[vorbis-dev] encoding question

msmith at labyrinth.net.au msmith at labyrinth.net.au
Mon Dec 16 05:45:40 PST 2002



Thanatos02 at gmx.de said:

> Hi there,
> I've a little question abound programming an ogg-vorbis encoder.
> The encode_example.c works ok for files with 44100/2/16 - but not for other
> formats.

Right - it's a minimal example and deliberately doesn't deal with any other
formats.

> I don"t really understand what this piece of code is really doing:
>  /* uninterleave samples */
>       for(i=0;i<bytes/4;i++){
> 	buffer[0][i]=((readbuffer[i*4+1]<<8)|
> 		      (0x00ff&(int)readbuffer[i*4]))/32768.f;
> 	buffer[1][i]=((readbuffer[i*4+3]<<8)|
> 		      (0x00ff&(int)readbuffer[i*4+2]))/32768.f;
>       }
> how should this part look for files with other specifications then
> 44100/2/16?

In a wav file, the channels are interleaved. Since it's 16 bits, that's two
bytes per sample. So, denoting a byte belonging to the left channel with a 0,
and one from the right with a 1, the bytes look like:
001100110011, etc. 4 bytes for each left+right sample. 

This code un-interleaves them, because libvorbis wants seperate buffers for
left and right, and then converts them to floats (with a range of -1 to 1),
since again that's required by the library.

So, this is fine for stereo/16 bit/little endian (any sample rate, not just
44100), but doesn't work for others.

There are quite a few cases to handle, the exact details are boring and
difficult to describe without giving source, so...

> I'd a look at the oggenc source - but i didn"t find something familar and
> the vorbisenc-doku didn"t really help. 

The vorbis documentation documents the encoding library, not common audio
manipulation tasks like these.

Oggenc implements this in wav_read (in audio.c). You'll notice that there are
quite a few different cases, each handled individually - any number of
channels, 8 or 16 bit, big or little endian. That function should be
reasonably clear.

Mike

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'vorbis-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the Vorbis-dev mailing list