[vorbis] Precache an entire OGG?

Michael Smith msmith at xiph.org
Wed Feb 18 22:45:29 PST 2004



>   pData->Length = ov_pcm_total(&sOVFile, -1);

Total length of all links in file, in samples.

>   if((pData->Buffer = (char*)malloc(pData->Length)) == NULL)

Incorrect. You want to allocate length * channels * bytes_per_sample here, not 
just length. However, since you're looking at _all_ the links in the file, 
the number of channels could change. 

>   if(pOVInfo->channels == 1)
>     pData->Channels = 0x1101;
>   else
>     pData->Channels = 0x1103;

I doubt that's what you mean - number of channels can be more than 2.

>
>   numStreams = ov_streams(&sOVFile);
>   StreamID = 0;
>   Location = 0;
>   while(StreamID < numStreams)
>     {
>     Size = ov_pcm_total(&sOVFile, StreamID);

This time you find out the length (in samples) of a particular link in the 
file. That's good. But the buffer (allocated before) is wrong.

>     while(Size > 0);
>       {
>       Read = ov_read(&sOVFile, (pData->Buffer + Location), Size, 0, 2, 1,
> &StreamID); Size -= Read;
>       Location += Read;

Size is in samples (as is Location), Read is in bytes. These are not the same.

You also need to look at what StreamID is after each call, so that you can 
allocate a new buffer (sized appropriately for the number of channels in this 
link) and start using it.

Mike

<p>--- >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-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 mailing list