07-16-2011 08:15 AM - edited 07-16-2011 08:39 AM
I was thinking of somehow abusing SoundPool to simulate real time streaming.
But looking at the API, it seems it can only load them from file (is it indeed the case?). Perhaps it's possible to allocate a few clips in SoundPool, the incoming RtpPackets' payload are somehow loaded in these clips, and a queue plays them in sequence once they're loaded. When a clip is playing, the next clip can be loaded. Something like that
Perhaps a long shot and it's probably difficult to completely avoid ticks and pops in the audio when one is stopped and the next one is started, but I'll give it a try.
EDIT: I just realized I'm mixing up Android and RIM in my post as I'm now simultaneously developing on Android and BB. SoundPool doesn't exist in BB Sorry about that.
Is there something similar to SoundPool in BB though?
07-18-2011 10:37 AM - edited 07-18-2011 10:38 AM
Makes sense. It would have been a bug if it wouldn't size the buffer according to sampling rate.
Good news that OS7 will have a fix!
fgVoip claim they've solved the problem though. Did anyone try their solution? Did they really manage to reduce latency to usable levels?
Try out BlackVoib (http://www.blackvoib.com). We have very low latency in voice playback on all (except CDMA) the BB device and we will be supporting GSM codec very soon.
07-18-2011 10:41 AM
I saw on the Linphone site that amr is the only way to do real time audio on BB. Not sure I believe that, but who knows... So far I haven't been able to get working AMR-NB support on our Asterisk server, but I'll be very interested to hear about your results with AMR
That's only true for CDMA devices. GSM devices can be programed to support G711ulaw/alaw, gsm, amr,adpcm codecs.
07-18-2011 10:46 AM
07-18-2011 04:29 PM
07-19-2011 12:58 PM
Hmm, that is intriguing indeed ...
I didn't have much luck yet though. I tried making the SourceStream RANDOM_ACCESSIBLE and do setMediaTime on the player when its state = STARTED and I receive a playerUpdate, but even when I only make the stream RANDOM_ACCESSIBLE (so without doing setMediaTime) it starts throwing exceptions ("media unloaded while initializing").
07-19-2011 02:55 PM
The best way to do it is to make a good estimate the size of the remaining data in the player's internal buffer and add your audio data accordingly. If the remaining data in the player's buffer can only last 350ms, you should be adding more audio data. If you have no audio data at the time, add some silence audio data. The trick is to keep the player not to run out of data.
07-19-2011 04:45 PM
07-20-2011 04:53 PM
I've had some lock reducing latency and got it well under 1 second now.
I measure the time between reads and try to estimate how much must still be in the buffer and write data until it hits a target, adding silence if necessary.
I'm having a problem now that after about 30 seconds I see that there is for some reason a long time between reads (more than a second) at which point buffering will start and my delay is huge again. It seems I'm doing something wrong in my estimations though as it seems the latency is slowly getting shorter until buffering kicks in.
It's definitely the right track though, but tricky to get right.