I am sampling a incoming audio stream at 8Ksps. I have a codec that takes ~1.6ms to encode a packet of data (80 samples) into an encoded packet (5 samples). At this rate I get 8000*1.662e-3 ~= 13 samples every encoding cycle. But I need 80 samples every cycle. How do I keep the stream continuous? My only guess is slow down the bitrate of the outgoing encode stream but I'm not sure how to calculate this in general such that buffers on the incoming side don't fill up and the receiving side's buffers don't get starved. And besides that doesn't slowing the bitrate take away the point of encoding in the first place?

This seems like a basic tenet of streaming but I can't find any info on methods. Thanks for any help!


The purpose of the encoding is to slow down the required bit rate of the encoded data stream. By the sound of it, your encoder is slowing it down by a factor of 16, so your output data stream should be either 500sps or 512sps (depending upon whether "K" meant 1000 or 1024). If you feed that into a matching decoder, it should convert that stream into an 8Ksps data stream which can then be output as audio.

To avoid having the receiver starve or get overrun if e.g. it's operating at 8,000.1sps while the sender is operating at 7,999sps, it may be desirable to have the playback CODEC include a buffer, measure the incoming speed, and adjust its speed slightly based upon the incoming speed and the amount of data in the buffer.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.