I try to record sound from my pc audio device. I can hear the recorded sound only when I set samplesize to 8 but when I set the samplesize to 16 , the recorded sound is only a whistle. why? here is the code
void audioprocess::startRecording()
{
outputFile.setFileName("C:/Users/Rem/Documents/Qtproject/remaudio.wav");
outputFile.open( QIODevice::WriteOnly );
QAudioFormat format;
// set up the format you want, eg.
format.setCodec("audio/pcm");
format.setSampleRate(8000);
format.setChannelCount(1);
format.setSampleSize(8);
format.setByteOrder(QAudioFormat::LittleEndian);
format.setSampleType(QAudioFormat::UnSignedInt);
audioInput = new QAudioInput(format);
QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice();
if (!info.isFormatSupported(format)) {
qWarning()<<"default format not supported try to use nearest";
format = info.nearestFormat(format);
}
QTimer::singleShot(120000, this, SLOT(stopRecording()));
audioInput->start(&outputFile);
// Records audio for 120000ms
}
The whistle is probably because every second sample is zero. That means you get a periodic signal at exactly half the sample frequency.
Now what does your code actually do? You haven't shown us the definition of outputFile, but the code snippet is almost literally taken from Qt documentation. And it defines outputFile as a QFile. The file there is called test.raw, and for good reason. Raw files lack a header. Thus it's impossible to determine their sample size.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With