Re: A few questions about libvorbis from a newbie
Ian Nartowicz <[email protected]> Thu, 3 Dec 2015 00:16:29 +0000
| Newsgroups | gmane.comp.multimedia.ogg.vorbis.devel |
|---|---|
| Message-ID | <20151203001629.5dc80e65@crunchbang> |
On Tue, 1 Dec 2015 21:53:22 -0600 Blake Martin <[email protected]> wrote: >First off, I don't even know if this is the right place to ask these kind >of questions, but I haven't been able to find answers anywhere else, so > >1. I have found that "pcmTotal * vorbisInfo->channels * 2" gives the >uncompressed size of every ogg vorbis file I have used. What is a more >robust way of getting the full uncompressed file size? Of course there is no such thing as the uncompressed size of a Vorbis file. As mentioned below, the bits per sample of a Vorbis stream is meaningless. The data can be decoded into 16 bit fixed integer samples or into 32 bit float samples. Your calculation assumes 16 bits per sample, which may be true in your case. It also assumes that the header contains a correct sample count, which may or may not be true. > >2. How do I read a certain amount of ms of data? For example, I have been >using sizeUncompressed / seconds / 4 (using the above method to get >sizeUncompressed) to try and get 250ms worth of data, but I'm not sure it >is doing what I think it does. > Given that you should know the bits per sample of your decoded data, the sample rate, and the number of channels, you can get a pretty accurate calculation of the length of a given amount of decoded data. Note that you specify the requested amount of data from ov_read() and ov_read_float() in different ways. ov_read() returns up to a given number of bytes, while ov_read_float() returns up to a given number of samples. "Up to" is an important caveat, because if you request more data than a single packet decodes to then you won't get a full buffer. If you're just trying to get a sensible buffer size for decoding, then the approximations should be good enough. >3. How do I determine the sample size of a file? For example, how do I know >if I should reading 16 bit or 8 bit samples? Lossy codecs don't generally have a solid concept of the bit depth. They encode the audio using as few bits as possible, often variable numbers of bits. If you need to know the sample size of the original audio before it was encoded by Vorbis, then your best bet is to store it in metadata. > >Thanks for your time. Just to complicate matters, Ogg Vorbis streams may be chained, consisting of multiple audio streams serially arranged within a single "file". You might not think that is likely, but it is standard for streaming audio such as an internet radio station. Chained streams may have different parameters, even different numbers of channels or different sample rates. Rare in an internet stream, almost unheard of in a discrete file. --ian