September 23rd, 2012, 12:31 PM
My name is Jerry Kaidor. I recently got a shiny new LG Optimus Slider, and am eager to write a few things for it. I am handicapped by the facts that
1. I know nothing about Android
2. I do not know Java.
HOWEVER, I do have over 20 years of experience in embedded C development, and have recently written maybe 50,000 lines of object-oriented Perl. I am also a longtime Linux user ( since kernel version 0.94.... AND, the eclipse IDE is very helpful .
So - moving on to today's question. I am writing an app that needs to make some sounds. These sounds need to be sequenced. That is, I would like the device to play sound #1 until it is done, then play #2 till it is done, then play #3. Etc.
I am trying to use the SoundPool class to do this, but it insists on trying to play my sounds all at once. Or dropping the sound it's playing for the new sound.
Anybody have a clue for me? Thanks in advance,
- Jerry Kaidor
September 24th, 2012, 01:48 PM
OK, I have a partial answer - the SoundPool class just is not appropriate for what I want to do. The appropriate class is something called "AudioTrack", which is the most primitive android sound API. AudioTrack doesn't do much for you, but it doesn't get in your way, either. You basically just send it some samples, and it writes them to the hardware. You can set up a listener for when there's room for more samples.
So I'm envisioning a layer that implements a circular buffer. "Upper level" code writes into it, "Lower level" code reads from it. When I used to do this sort of thing in C and assembler, I'd always size the buffer to a power of 2, and wrap the indices with logical "and"s. A special case would be a 64K buffer indexed with a 16-bit variable- don't even have to do the "and"s. And an even more special case was the traditional X86 architecture, with segment registers, which allowed me to use 16-bit *pointers* and not even do any index->pointer arithmetic - the cheapest circular buffer of all!
I don't think java is conducive to such tricks. Too high level.
But the processors are a lot faster nowadays too. But I will want to be careful about memory - not that much in the typical cell phone.