Mixing audio in itself is not too hard.. you basically add each byte of each
sound (that plays at the same exact point in time). You do face the issue of
dynamic range.. if you are mixing 16-bit sounds, you don't want to use a
16-bit value to store the mixed sounds.. you'll overflow it. or clip the
sound. Usually you'll use a 32-bit integer to add all the sounds, then
you'll lower it to 24-bit or 16-bit with some fancy algorithm that won't
clip all the mixed sounds.. sort of like lowering their combined volumes so
they don't clip. However, you can't keep lowering volumes with more sounds..
it changes the overall mixed volume.. there is some FFT or something like
that which properly does this. It's been a long time since I did this stuff,
back when SoundBlaster 8-bit sound card was out and mikmod and module
players were quite popular. Long before the sound cards mixed audio
themselves. ;)

I am sure you can find stuff on it. I too wanted to work on a low-latency
music app, but until google puts more resources into making the NDK and
android platform on par with iPhone, I don't think it's worth the effort.
There is just WAY too many problems with the issue of low latency audio
right now. Really what you need is to use the NDK, pass the sound buffers of
different sounds (or better yet, NDK can directly access the buffers of
loaded sounds or SD stored sounds), do the mixing there, and then be able to
play to a the sound output in some low latency manner. Unless things have
changed, I've been led to believe we're a long ways off before we'll have
anything like that.

Sadly, it seems google/android team is completely quiet on any details at
all with regards to this stuff. I've not been able to find one bit of info
whether or not they are hearing us game/audio developers and are working on
a better platform for us or not. Given their stagnant market work and lack
of any info at all on anything being worked on.. I wouldn't count on
anything anytime soon. Let's hope I am very wrong on this, but I fear that
the articles that indicate android will surpass iphone by 2012 are grossly
misleading if android as a platform can't compete on games and audio with
iPhone. :( They still need to fix the multi-touch issue which plagues gamers
on several devices but apparently it's in the hardware, not the platform.

If I am wrong.. if there is some place google posts what is coming and
when.. please correct me. I really love the idea of Android, and still
follow along, but I've basically stopped any development primarily because
there isn't much money in it, and with no idea if far better game/audio
support is coming, I don't want to waste time hoping. There are other
avenues of interest in non game/music related things for Android tho, but my
heart lies in making a kick ass music app... and possibly a side scroller
game at some point. Would be wonderful if Google had something like XNA for
us. :)


On Mon, Apr 12, 2010 at 12:42 PM, k_day <[email protected]> wrote:

> Despite everything I have read about the difficulty of making low
> latency audio apps in Android, I am giving it a shot.  To start, I
> loaded each note in an octave into a SoundPool, and then looped
> through each note that was to be played on that beat and called
> play().  This didn't even come close to being accurate enough for me,
> and got especially bad if a lot of notes were being played at once.
>
> From what I read, the only way to do something like this is to mix the
> audio yourself, though I am not entirely sure how to go about this.
> My initial thought is that for each beat, I could precompute the sound
> the sound that is to be played (i.e., combine the wav's), and then
> pass that stream to an AudioTrack when it is time to be played.
>
> Are there any good examples out there for how to mix audio like this,
> or libraries I could use to do this for me?  How have coders of other
> music apps dealt with this?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>
> To unsubscribe, reply using "remove me" as the subject.
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to