[vorbis-dev] Problem with ov_read_float()

volsung at asu.edu volsung at asu.edu
Wed Jan 16 20:14:20 PST 2002



On Wed, 16 Jan 2002, David Mitchell wrote:

> I'm having some sort of problem using ov_read_float(). Everything looks
> good to me, but I'm trashing memory somehow, so clearly I'm screwing
> something up. What confuses me is why it takes a ***float for the
> buffer.

There are some problems with the semantics of ov_read_float().  It works as
defined, but we plan to change a few things before RC4 to make it more useful.  
(ReplayGain on ogg123 will not be committed until the changes occur.)

> float **buffer
> bytes_read = ov_read_float(&vf, &buffer, 0)
> memcpy (b, *buffer, 0);

Uh, why are you memcopy()ing 0 bytes?  That looks wrong already.

<p>Some of your confusion might come from a misunderstanding of what points at
after you call ov_read_float().  buffer is actually an array of floating point
arrays, one for each channel of audio.  If you are decoding stereo, buffer[0]
will be the array of left channel samples, and buffer[1] will be the right
channel.  As you might expect, buffer[0][0] will be the first sample in the
left channel, and buffer[1][0] will be the first sample in the right channel.

Because these are arrays of arrays, you can't just memcpy() the whole thing
anyway since it doesn't necessarily exist in contiguous memory.  Also, note
that bytes_read is a misnomer.  This function actually returns the number of
samples read (in either channel, not both channels added together).

Also make sure that you don't free() buffer anywhere since you don't own it.

[Disclaimer: If this seems odd at all to you, realize that we agree.  The
fixed version will have semantics closer to ov_read().]


---
Stan Seibert

<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-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