Use case
I've got 68 piano samples, each approx. 174 kB, Ogg data, Vorbis audio, stereo, s16, 44100 Hz, 352 kb/s, 4 seconds.
I need to simultaneously play different combinations of them (musical term: harmonic chords/intervals), e.g. 1st + 7th
, 14th + 22nd
etc.
Also: current "playback" needs an option to stop it after t
milliseconds.
What I've tried
An obvious solution seems to be to use a SoundPool
. After setting maxStreams = 20
, I .load()
all the samples to it. With every play request a thread (really: Scala's future
) is created that awaits given t millis
and then stops all sounds.
It seems to work... usually.
The problem
This
SoundPool
, when playing 2 (or more) sounds simultaneously, sometimes won't start them exactly at the same time, slight difference in their start times certainly can be heard. Most of the time, however, it's OK.There's also a problem with stopping... sometimes a pair "lasts" longer, but again, usually it ends at the time I want it to.
Finally, what's really weird: every
.play()
that is a first one after either:- turned off (or even dimmed only!) display or
- application launch...
...won't produce a sound!
Question
Does Android provide us with a more reliable (in terms of timing consistency) sound pool implementation to use?
Would it perhaps work better if I created 68 threads, one for each sound?... I don't think so.