Enver Umerov
Enver Umerov

Reputation: 49

Simple android audio sequencer implementation

I'd like to create a simple audio sequencer app for Android (like FL, GarageBand etc.). However, I'm stuck at manipulating the audio. In particular, how should I implement audio playback (that is, playing the recorded audio), are there any libraries to use or it is better to use just default Java methods? Recently I found Oboe but I'm not sure whether it is good for that purpose.

I'm using raw files as the audio sources (like piano notes) and access them using AudioTrack.

Upvotes: 0

Views: 227

Answers (3)

asubb
asubb

Reputation: 19

You also may take a look at this library I'm working on: https://github.com/WaveBeans/wavebeans

It'll allow you to mix different sample files, though the playback part you would need to do on your own as a custom output. It's on Kotlin, not sure if it'll work seamlessly with Java at the moment.

The code would look like this (for predefined mix):

val silence = input { ZeroSample }
val sample1 = wav("file://sample1.wav")
val sample2 = wav("file://sample1.wav")

val track1 = sample1..silence.trim(100, MILLISECONDS)..sample1
val track2 = sample2..silence.trim(10, MILLISECONDS)..sample2..silence.trim(10, MILLISECONDS)..sample2

val mix = track1 + track2

mix.out { 
/**
 * here is the output code to perform the playback
 * follow https://wavebeans.io/docs/api/outputs/output-as-a-function.html
 */
}

// and evaluate the output as by https://wavebeans.io/docs/exe/

Upvotes: 0

philburk
philburk

Reputation: 711

On Android, for native Audio apps, I recommend using Oboe. Open a single output stream and then do all your mixing of tracks down to the one single stream. Use the frame count as a timing reference, as the other Phil suggested.

You can use the DrumThumper app as a starting point because it mixes multiple WAV samples into a single output.

Upvotes: 1

Phil Freihofner
Phil Freihofner

Reputation: 7910

If the android environment for audio output is like Java, the best way to get accurate timing is going to be by counting PCM frames and using that to keep all the elements aligned. I haven't done a lot with Android, but I think the class to use for output is AudioTrack, as it allows you to stream PCM. I'd look at making sure all your sounds can be converted to PCM and use that data form for mixing and effects processing, then output via AudioTrack.

I haven't looked at Oboe. Perhaps it has everything that is needed already built. I'm old school--am only recently getting the hang of looking for libraries rather than reinventing the wheel.

Here's a previous question that talks a bit about outputting PCM.

Upvotes: 1

Related Questions