[Vorbis-dev] How To Encode Realtime

Ralph Giles giles at xiph.org
Mon Sep 17 23:15:30 PDT 2007


On Tue, Sep 18, 2007 at 11:55:32AM +0800, yut_1985 at foxmail.com wrote:

>   Forgive my poor English, I'm trying to implement a net phone using vorbis codec, which need realtime encode and decode the stream.

Vorbis isn't appropriate for interactive chat. The latency is too high. 
You might look at speex instead if you are doing voice.

> 	The problem is, I use vorbis_analysis_buffer() and vorbis_analysis_wrote() push the PCM data in, then use vorbis_analysis_blockout(&vd, &vb) to output a block, it can't output all the data. It seems that some data which length is constant, must be in the vorbis_dsp_state, can not be output. When Decode, there's similar problem. These lead time lapse.

The encoder requires a working buffer of several blocks to choose 
optimum coding, and will create compressed blocks of two different
sizes based on the encoding mode and nature of the audio.

In general, you must repeatedly call call each output stage repeatedly 
until it asks for more data. When all stages are asking for more data,
call vorbis_analysis_wrote to submit more. This way it can buffer the 
data it needs, and you are certain to write out what is available as 
soon as possible.

See examples/encoder_example.c in the source package for more detail.

Hope that helps,
 -r


More information about the Vorbis-dev mailing list