Use case
I have 68 piano samples, each approx. 174 kB, Ogg data, Vorbis sound, stereo, s16, 44100 Hz, 352 kbit / s, 4 seconds.
I need to play different combinations of them at the same time (musical term: harmonic chords / intervals), for example. 1st + 7th , 14th + 22nd , etc.
Also: the current โplayโ needs an option to stop it after t milliseconds.
What i tried
The obvious solution is to use SoundPool . After setting maxStreams = 20 , I .load() all the samples to it. Each playback request creates a stream (valid: Scala future ), which waits for the specified t millis , and then stops all sounds.
It seems to work ... usually.
Problem
This SoundPool , while playing 2 (or more) sounds at the same time, sometimes does not start them exactly at the same time, of course, you can hear a slight difference in their start time. However, most of the time this is normal.
There is also a problem with stopping ... sometimes the pair "lasts" longer, but then again, usually it ends at the time I want it.
Finally, which is really strange: each .play() , which is the first after:
- off (or even dimmed only!) the display or
- application launch ...
... will not play sound !
Question
Does Android support a more reliable (in terms of synchronization consistency) implementation of the audio channel pool?
Maybe itโs better to work if I created 68 threads, one for each sound? ... I donโt think so.
source share