gpt4 book ai didi

c++ - 在 QAudioOutput 中改变音量后的噪音

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:16:36 27 4
gpt4 key购买 nike

我正在尝试使用 QAudioOutput 和“原始格式”的 wav 来播放声音。计时器超时后(每 50 毫秒)我执行以下操作:

QByteArray TempSBuffer;
short int *hi;

// Check if wav has reached their end and reset its position to the beginning if yes
if((m_timerStepNum+1)*m_audioOutput->periodSize()>=m_soundBuffer.size()) {
m_timerStepNum=0;
}
// 2. Write the buffer data for the next timecycle into a temporary QByteArray TempSBuffer
TempSBuffer=m_soundBuffer.mid(m_timerStepNum*m_audioOutput->periodSize(), m_audioOutput->periodSize());
hi=(short int *)TempSBuffer.data();

for(int i=0;i < m_audioOutput->periodSize() / 2;i++) { hi[i]*= m_audioOutput->volume(); }

// 4. Play the resulting buffer
m_ioDevice->write(TempSBuffer, m_audioOutput->periodSize());
m_timerStepNum++;

一切正常,但当我尝试在 QAudioOutput 中更改音量,例如 0.2(我的主音量为 100%)时,我听到了可怕的噪音。我应该承认,这只发生在我的一个 wav 文件中,其格式为:

bitsPerSample: 8
channels: 1
frequency: 16000

正如我所说,其他文件播放正常。好波的格式示例:

bitsPerSample: 16
channels: 1
frequency: 22050

bitsPerSample: 16
channels: 2
frequency: 22050

bitsPerSample: 16
channels: 2
frequency: 22050

最佳答案

嗯,根据The ABCs of PCM (Uncompressed) digital audioFinal Notes -

For some reason, WAV files don't support signed 8-bit format, so when reading and writing WAV files, be aware that 8-bits means unsigned, but in virtually all other cases it's safe to assume integers are signed.

我通过将原始 wav 转换为 16 位格式解决了一段时间的问题。

关于c++ - 在 QAudioOutput 中改变音量后的噪音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32821706/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com