You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用OGG/Vorbis解码无声音输出,求问题排查方案

播放OGG/Vorbis音视频文件时音频近乎无声的问题

我尝试播放OGG/Vorbis音视频文件,目前无法读取文件中的有效音频,输出的音频近乎无声。补充说明:OGG数据包读取逻辑正常,同一文件的视频数据使用相同代码读取,播放完全正常。

我的音频读取算法流程如下:

1. 初始化所需结构体

vorbis_info info;
vorbis_comment comment;
vorbis_dsp_state dsp;
vorbis_block block;

vorbis_info_init(&info);
vorbis_comment_init(&comment);

2. 读取头部

  • 调用vorbis_synthesis_headerin(&info, &comment, packet);直到返回OV_ENOTVORBIS
  • 执行vorbis_synthesis_init(&dsp, &info);
  • 执行vorbis_block_init(&dsp, &block);
  • 将第一个非头部数据包传入下方的putPacket函数

3. 解析数据包,直到audioReady == READY

putPacket(ogg_packet *packet) {
    int ret;
    ret = vorbis_synthesis(&block, packet);
    if( ret == 0 ) {
        ret = vorbis_synthesis_blockin(&dsp, &block);
        audioReady = (ret == 0) ? READY : NOT_READY;
    } else {
        audioReady = NOT_READY;
    }
}

4. 读取音频数据

float** rawData = nullptr;
readSamples = vorbis_synthesis_pcmout(&dsp, &rawData);
if( readSamples == 0 ) {
    audioReady = NOT_READY;
    return;
}

int16_t* newData = new int16_t[readSamples * getChannels()];
int16_t* dst = newData;
for(unsigned int i=0; i<readSamples; ++i) {
    for(unsigned char ch=0; ch<getChannels(); ++ch) {
        *(dst++) = math::clamp<int16_t>(rawData[ch][i]*32767 + 0.5f, -32767, 32767);
    }
}
audioData.push_back({readSamples * getChannels() , newData});
vorbis_synthesis_read(&dsp, static_cast<int>(readSamples));

audioReady = NOT_READY;

我怀疑算法存在问题,但无法定位。参考同类程序源码(如theoraplay库),其流程与我类似却能正常工作。

请问我的程序输出近乎无声的原因是什么?

内容的提问来源于stack exchange,提问作者Felix.leg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 20:16:11