使用 minimp3 将 MP3 实时转换为 PCM 在帧开始时产生噪声/间隙

问题描述 投票:0回答:1

我正在使用 minimp3 (https://github.com/lieff/minimp3) 来实现音频管道,我在其中使用 Web 套接字将 MP3 数据流式传输到虚幻引擎 5 客户端。收到后,我将数据添加到 TArray(充当缓冲区),然后尽可能多地解码为 PCM。解码后,我将新样本添加到音频源。然后我对数据流中的所有 MP3 帧重复此操作。

我已经确认 MP3 正在正确传输,但是,转换后的 PCM 在 MP3 帧块的开头有间隙/噪音,在播放过程中会扭曲音频。

附代码:

https://gist.github.com/DeveloperHarris/c3bd30d6cc689f22ec9e8fc839c80655

Audacity 中的顶级音频是测试 MP3,由 Unreal Engine 客户端接收的 100Hz 正弦波组成。 底部轨道是转换后的 PCM 流。

噪音/间隙似乎出现在新块的开头。我最初的理论是这是由于 MP3 的字节存储系统(假设每次间隔大约 3 帧长),但我认为 minimp3 应该解释这个问题?它是块之间 mp3d 的相同实例。

我需要做什么来解决块开头的解码问题?

c++ mp3 pcm unreal-engine5
1个回答
0
投票

事实证明,我需要更仔细地阅读图书馆文档:

The decoder will analyze the input buffer to properly sync with the MP3 stream, and will skip ID3 data, as well as any data which is not valid. Short buffers may cause false sync and can produce 'squealing' artefacts. The bigger the size of the input buffer, the more reliable the sync procedure. We recommend having as many as 10 consecutive MP3 frames (~16KB) in the input buffer at a time.

在我的解码函数的开头添加检查以检查它是否有 10 个连续帧足以解决问题。

© www.soinside.com 2019 - 2024. All rights reserved.