[Vorbis] Using decoding vorebis from a Vorbis / Theora Video

Ralph Giles giles at xiph.org
Mon Feb 19 15:40:05 PST 2007

On Mon, Feb 19, 2007 at 11:05:59PM +0000, Charles Mason wrote:

> Thanks for the info Ralph. I have managed to implement what I think is
> the correct Vorbis decoding routine. I am now getting the pointer back
> from pcm out.


> I was wondering if someone could clarify what format and size the PCM
> data is in. It appears to be a pointer to a 2 dimensional float array.
> I assume one dimension is the channel number and the is the time
> offset of the sample.

Yes, it's non-interleaved float data, in the range [-1,1], at least 
according to the comments in decoder_example.c.

The first index is the channel number, and the second index is the 
sample number. vorbis_synthesis_pcmout() returns the number of samples 
available per channel in the returned data.

I don't know how multidimensional arrays work in C#, but in C the 
returned (float **)pcm is an array of vi.channels elements, each of 
which is a pointer to a float array of samples. If the array indexing is 
the same you should be able to convert to interleaved signed short 
without explicit pointer arithmetic like so:

/* NB: untested pseudocode */
int samples = vorbis_synthesis_pcmout(vd,pcm);
int16_t buffer[vi.channels*samples]
for (int sample = 0; sample < samples; sample++) {
  for (int channel = 0; channel < channels; channel++) {
    buffer[sample*channels + channel] = pcm[channel][sample]*32767.0;

Note that you also have to call vorbis_synthesis_read() when you're done 
to tell it how much data you've consumed out of the pcm buffer.

> How long is the data. I get the sample number returned from the pcmout
> function. Is that per channel. So if its stereo and I get 576 returned
> I need to read in 576 * 2 floats.

That's right.

Hope that helps,

More information about the Vorbis mailing list