On Tuesday 07 September 2004 02:00, Niels Gorisse wrote:> Hi all,
>
> Perhaps a stupid question, but I just need pieces of audio from a file. I
> know I have to use vorbisfile, and the example compiles, but I don't
know
> how to read the buffer. In fact, it's not even documented (or I'm
looking
> at the wrong place). I assumed it was a interleaved buffer containing
> unsigned shorts, but that didn't work.
It's documented (though perhaps not entirely clearly): the ov_read()
documentation states "If the audio is multichannel, the channels are
interleaved in the output buffer". The actual format of the data is
dependent
on the arguments passed to the ov_read() function: typically, you want 16 bit
_signed_ samples (that's what hardware usually wants). You may want it big
endian or little endian, depending on what you're doing with it. The ov_read
documentation explains what each of the parameters is for.
You're probably having problems because you're asking for signed
samples, then
treating them as unsigned, OR you've got the endianness wrong.
>
> I also tried the normal decode example, that one sounded great (attaching a
> real file and audio hardware to it), but I didn't succeed in remove the
> three (yes, three!!) while loops around the actual retrieval of audio
> samples, without breaking the code. Aghr - while loops, terrible. What a
> weird way of writing decoding - doesn't everybody just want a plain
> function with retrieveBuffer(float**inhere) just like ov_read() is?
>
> Thanks in advance for any help (either a non-looped version of the decoding
> example, or a piece of code how to read the ov_read() buffer would do),
The example decoder uses the low-level libvorbis interface; the loops there
are required (though one could, of course, write the loops in a different
way, if one really wanted). The higher-level libvorbisfile interface exists
precisely _because_ this low-level interface (while it is efficient) is not
very developer-friendly.
Mike