Blake Martin
2015-Dec-02 03:53 UTC
[Vorbis-dev] A few questions about libvorbis from a newbie
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? 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. 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? Thanks for your time. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.xiph.org/pipermail/vorbis-dev/attachments/20151201/d53f37f2/attachment.htm
Gunter Königsmann
2015-Dec-02 07:08 UTC
[Vorbis-dev] A few questions about libvorbis from a newbie
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 On 02.12.2015 04:53, Blake Martin 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?This sounds quite reliable. At least if the .ogg file is equipped with the correct headers: If you capture the live stream from a radio station that radio station won't know in advance how many samples you will capture and pcmTotal (which is one of the first things you'll get) won't be filled with the correct value. Since ogg is vbr I assume the only way of working around bad headers would be to decode the whole file and count the number of samples - lest there is a way of querying every packet how many samples it contains without actually decoding it.> > 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.Seems quite reasonable to me. You also can look up the seeking mechanism of ogg vorbis that will allow you to move fast by a few seconds. But this mechanism fails with many live streams - and it might not get you to exactly the right point within the file you want to be at.> > 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?Ogg operates on floating-point numbers and is designed to do the best job on the data format it gets - or is instructed to produce. Unfortunately this means it doesn't care where the data came from and how the data source looked like. Perhaps you could do some heuristics trying to find out the remains of the typical noise generated by a 8-bit-sampling-process that are left after ogg-encoding the data. But this approach needs loads of maths and won't be 100% reliable. Kind regards, Gunter. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQJ8BAEBCgBmBQJWXpkHXxSAAAAAAC4AKGlzc3Vlci1mcHJAbm90YXRpb25zLm9w ZW5wZ3AuZmlmdGhob3JzZW1hbi5uZXQ1M0YwNDdDRTY2QjkxQjBGNzI0QzU0NUQ1 Qzg2QzBFNDIxMUQ1QjhFAAoJEFyGwOQhHVuOYTAP/17c3iD1R4lK3U7SLFyQDMSE 7TPwRlHp+Aijj9yUgDLF5rqg4fYzemPfzjixV9kyEcfQPVKyJLd011KJX75UpOFo xnsCgmGMBhzYoX2PhJm+e4FlLnjzjOwYr7TuVQHswcng08YGO4ZKCIZay9rDlS4U 1YY8k5Ieove9RrWuTRXe6zBe15lWkQyRPbyXIzeoy7ODKqJxOr6B/C2+gkhw3+BF b3KJFhT9adEblYvkqafYo6T5UQwmMkD7GvEAHs9zwk0MsftSnsif1rD2Yx3P3nTr TamCOOyj/lItwZ0ZUvTn3eBhOrd0xzFejlhOs03njHTNgy2M1bH3cDbKG2wP5IVU lxPIB4sImyNewcql2LLprrsfPtqRL0yn5i7Jo/B6b0qs3H9BUHQ7mw68KoM3/cTR HZc7k6NI60CierFfVSa0YKXkONq2DB9JyQE71E+G2wPMwi+7IBBC7rPsp7h+jD7M OszgwluVczWpc0O1UsAOHFfEM4WtqjqhYAAaMFlA5N5hDITw5JioqL1pI1FU3lSh nq/eEVkSl8D4+datIexfV0jpNvsRv66rOQgkAOCCo3TfiEK8jhToJ7tliesLxpFK CQKMZ8GW7QnOWH3L7tjXde4j2GSWx8T9dhtfGYBbkiimS3hscwbOxXsEhMFmmUiV 93iaRxPP/eFna4zcmbpP =YU9/ -----END PGP SIGNATURE-----
Ian Nartowicz
2015-Dec-03 00:16 UTC
[Vorbis-dev] A few questions about libvorbis from a newbie
On Tue, 1 Dec 2015 21:53:22 -0600 Blake Martin <blakemartin.official at gmail.com> 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