Author Topic: Playing from a constant income of bytes smoothly?  (Read 1980 times)

Offline Gliby

  • bit
  • Posts: 4
    • View Profile
Playing from a constant income of bytes smoothly?
« on: September 16, 2013, 09:37:19 AM »
Hi I would like to know how to smoothly play a stream of constantly incoming bytes, I've tried a few things but I always end up with some jittery sound. I have yet to come across a way to play bytes as they come in realtime.
« Last Edit: September 16, 2013, 11:23:57 AM by Gliby »

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3496
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Playing from a constant income of bytes smoothly?
« Reply #1 on: September 16, 2013, 04:44:34 PM »
This is probably due to inconsistencies in the data rate (including processing rate by the application and supporting libraries, not just the network data rate).  To fix the problem, you will need to do some buffering (how large depends on how 'jittery' the data rate is -- if steady, then it can be relatively small).  Easiest way is to use three buffers.  Write your data into the first buffer, and once it is full queue it up to play while switching to write to the next buffer, and so on.  Once you reach the third buffer, loop back to the first one.  The larger the buffers, the more latency you will experience, but also will be able to handle more inconsistency in the data rate.
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted