简体   繁体   English

Vorbis查找文件的解压缩大小

[英]Vorbis finding decompressed size of file

I'm working with JNI and Android NDK bindings to wrap around the Tremor version of Vorbis.我正在使用 JNI 和 Android NDK 绑定来包裹 Tremor 版本的 Vorbis。 So far i've succeeded in streaming sound from file to speakers.到目前为止,我已经成功地将声音从文件传输到扬声器。

However, i'd also like to be able to 'cache' small sounds in byte arrays, so there's no redundant decompression when i use these sounds often.但是,我还希望能够在字节数组中“缓存”小声音,所以当我经常使用这些声音时没有多余的解压缩。

My problem is that i don't know how large the array needs to be to hold all the PCM data in the vorbis file.我的问题是我不知道数组需要多大才能保存 vorbis 文件中的所有 PCM 数据。

I have tried these following methods, none of which work 100% of the time.我尝试了以下这些方法,但没有一种方法能 100% 有效。

pcmDuration = ov_pcm_total(vorbisFile, -1);
pcmDuration *= 2;              // 16bit channels
pcmDuration *= vorbisInfo->channels;   // number of channels.

The above works perfectly for some files, and nails exactly the size required.以上内容非常适用于某些文件,并且准确地确定了所需的大小。 However, for others it doesn't.然而,对其他人来说则不然。 It dramatically underestimates (usually by about 1-2kb) the size required, obviously leading to out of bounds exceptions.它大大低估了所需的大小(通常大约 1-2kb),显然会导致超出范围的异常。

The below was a recommended solution, but has the exact same problem.以下是推荐的解决方案,但存在完全相同的问题。 It yields the same results as above.它产生与上述相同的结果。

for(int i = 0; i < ov_streams(vorbisFile); i++)
    size += ov_pcm_total(vorbisFile, i);

What method should i use to find out the actual byte size required to hold an Ogg Vorbis file?我应该使用什么方法来找出保存 Ogg Vorbis 文件所需的实际字节大小?

EDIT;编辑;

I know i could just do ov_reads over the entire length of the file, and take the sum of those reads as the decompressed size.我知道我可以在文件的整个长度上执行 ov_reads,并将这些读取的总和作为解压缩后的大小。 However i'd prefer not to double-decompress, since i'm working in Android and it's got limited CPU power in the first place, and that's a pretty ugly solution.但是我不希望双重解压缩,因为我在 Android 中工作,而且它首先具有有限的 CPU 能力,这是一个非常丑陋的解决方案。 This isn't a response to any answer, i just know i could do it but would prefer not to.这不是对任何答案的回应,我只知道我可以做到但不希望这样做。

I know this is four years late, but I never found a real answer to this question.我知道这已经晚了四年,但我从来没有找到这个问题的真正答案。 The solution I went with long ago was to use linked lists of fixed-size byte arrays, each representing one chunk of decompressed data.我很久以前采用的解决方案是使用固定大小字节数组的链表,每个字节数组代表一块解压缩数据。 Each ov_read would store the data into a new chunk, and chunks would link together one-to-the-next until the entire file was decoded.每个 ov_read 会将数据存储到一个新的块中,并且块将一个接一个地链接在一起,直到整个文件被解码。 Subsequent playback would just grab data from each chunk sequentially and replay it.随后的回放只会从每个块中按顺序获取数据并重播。

This obviously fell apart when decompressing large files, and leads to a lot of memory management for decompressed chunks (unloading a single file means de-linking all chunks completely so that they can be garbage collected).这在解压缩大文件时显然会崩溃,并导致对解压缩的块进行大量内存管理(卸载单个文件意味着完全解除所有块的链接,以便它们可以被垃圾收集)。

I just had this same exact issue streaming ogg using the Vorbisfile API with XAudio2.我刚刚在使用带有 XAudio2 的 Vorbisfile API 流式传输 ogg 时遇到了同样的问题。

The fix that worked for me was to call ov_raw_seek (after both ov_open_callbacks and ov_info calls, but before ov_pcm_total and ov_read ) to seek back to the start of the file.对我有用的修复方法是调用ov_raw_seek (在ov_open_callbacksov_info调用之后,但在ov_pcm_totalov_read之前)来寻找文件的开头。 Apparently, this "fixes" the internal state around the pcm positions/offset vars.显然,这“修复”了 pcm 位置/偏移变量周围的内部状态。

After that, all ogg files I test with play correctly.之后,我测试的所有 ogg 文件都可以正常播放。

This gave me the clue: https://github.com/xiph/vorbis/issues/60这给了我线索: https ://github.com/xiph/vorbis/issues/60

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM