Greetings, 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. I call it like so: float **buffer bytes_read = ov_read_float(&vf, &buffer, 0) memcpy (b, *buffer, 0); This compiles fine, but after a few reads, libvorbis crashes internally at random spots. If I take out the memcpy, it runs fine. I'm 99% certain that I'm trashing memory somewhere, but it's not clear why. The ov_read_float docs give this as "Typical usage", but it doesn't even compile under gcc, so it's clearly wrong: float **pcm; bytes_read=ov_read_float(&vf,pcm,¤t_section); Can anyone tell me what I'm missing? I'm sure there is a good reason that pcm_channels is a triple pointer, but I don't see what it is. It seems to me that a double pointer would work fine. Thanks in advance, -David Mitchell --- >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@xiph.org' containing only the word 'unsubscribe' in the body. No subject is needed. Unsubscribe messages sent to the list will be ignored/filtered.
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@xiph.org' containing only the word 'unsubscribe' in the body. No subject is needed. Unsubscribe messages sent to the list will be ignored/filtered.
----- Original Message ----- From: "David Mitchell" <vorbis@themitchells.org> To: <vorbis-dev@xiph.org> Sent: Thursday, January 17, 2002 4:00 AM Subject: [vorbis-dev] Problem with ov_read_float() <p>> float **buffer> bytes_read = ov_read_float(&vf, &buffer, 0) > memcpy (b, *buffer, 0);What also bothers me is that the last parameter expects a pointer, and you're passing it a 0. -- GCP <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@xiph.org' containing only the word 'unsubscribe' in the body. No subject is needed. Unsubscribe messages sent to the list will be ignored/filtered.