2
votes

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

1 Answers

2
votes

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.