1

I have an Android application that simulates a Drum Kit where the user is able to "record" their performances. Currently this recording consists of store in a .json file which audio sample was played and the time that it took between the previous and the current note, something like this:

[
    {
        drumkit: 'snare',
        time: '0'
    },
    {
        drumkit: 'kick',
        time: '5'
    },
    {
        drumkit: 'splash',
        time: '3'
    }
    {
        drumkit: 'snare',
        time: '0'
    },
    {
        drumkit: 'kick',
        time: '2'
    },
    {
        drumkit: 'crash',
        time: '0'
    }

]

That said, now I'm looking for a way to generate an audio file (mp3 for example) from that record, since I already have the audio files in the app and also the logical sequence of the recording.

I tried to follow the approach shown in this question (https://stackoverflow.com/a/656302). The merging of audios worked, but in this way the next audio can only be placed after the previous one ends, making it impossible for two (or more) audios to be played at the same time. It is also not possible to define the time that separates the audios.

The ffmpeg lib seems to be good for dealing with this type of problem, there is even a version for Android. But I don't know how to do this using it.

Would anyone have a suggestion on how to solve the problem? (Using or not ffmpeg)

1 Answers1

1

FFmpeg

... is probably the best solution. I suggest reading more about it here.The command line tool ffmpeg (accessible in most FFmpeg android packages) accepts the parameter -itsoffset. -itsoffset essentially delays the input stream.

As I can see, the array contains objects with the instrument and the time to the next note. A 'for' loop with a time increment would work.

This pseudo-code assumes ffmpeg is a command line program/library/.so file.

# Preferably an object or function to map 'Object.Instrument' to a path
# { drumkit: "snare", time: 3 }  =>  ./snare.wav
Variable Command = 'ffmpeg'
Variable Sum = 0 # in seconds
Foreach Object in Array
    # Be careful with whitespace in the command
    Command = Command + ' -itsoffset ' + Sum + ' -i ' + Object.Instrument + '.wav'
    Show (Command)

    Sum = Sum + Object.Time

End Foreach
Command = Command + ' /output/path/file.wav'
# ffmpeg -itsoffset 0 -i snare.wav -itsoffset 3 -i kick.wav /output/path/file.wav
  • I tried to run the resulting command using some audio files. `ffmpeg -itsoffset 0 -i drum1_snare.ogg -itsoffset 300 -i drum1_close_hh.ogg -itsoffset 600 -i drum1_tom_2.ogg output.wav` However, the resulting sound did not come out as expected... ffmpeg only concatenated the first audio in the output. – Antonio Oliveira Mar 25 '20 at 14:46
  • I should specify that the `-itsoffset ` is in seconds. There is a 5 minute break between each input. – Bazza Cipher Mar 25 '20 at 22:25
  • Even changing the times to 3 and 5 seconds did not work. Here is the command I used: ffmpeg -itsoffset 0 -i drum1_snare.ogg -itsoffset 3 -i drum1_close_hh.ogg -itsoffset 6 -i drum1_tom_2.ogg output.wav And this is a print of the result I got: https://i.imgur.com/1BMtRWS.png – Antonio Oliveira Mar 25 '20 at 22:34