Noise after changing volume in QAudioOutput

血红的双手。 提交于 2019-12-13 15:46:48

问题


I am trying to play sound by using QAudioOutput and wav in "raw format". After timer's timeout (every 50ms) I do following:

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++;

Everything plays ok but when I try to change volume say for example 0.2 in QAudioOutput (and my master volume is 100%) I've got the horrible noise. I should admit that this happens only for my one wav file which has format:

bitsPerSample: 8
channels: 1
frequency: 16000

Other files play ok, as I said. Format examples of good-played waves:

bitsPerSample: 16
channels: 1
frequency: 22050

bitsPerSample: 16
channels: 2
frequency: 22050

bitsPerSample: 16
channels: 2
frequency: 22050

回答1:


Well, according to The ABCs of PCM (Uncompressed) digital audio in Final 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.

I solved for a while my problem by converting my raw wav to 16-bit format.



来源:https://stackoverflow.com/questions/32821706/noise-after-changing-volume-in-qaudiooutput

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!