//声卡采样格式
QAudioFormat format;
// set up the format you want, eg.
format.setSampleRate(8000);
format.setChannelCount(1);
format.setSampleSize(16);
format.setCodec("audio/pcm");
format.setByteOrder(QAudioFormat::LittleEndian);
//format.setByteOrder(QAudioFormat::BigEndian);
format.setSampleType(QAudioFormat::UnSignedInt);
//format.setSampleType(QAudioFormat::SignedInt);
QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice();
if (!info.isFormatSupported(format)) {
qWarning()<<"default format not supported try to use nearest";
format = info.nearestFormat(format);
}
audio_in = new QAudioInput(format, this);
myBuffer_in = audio_in->start();
connect(myBuffer_in, SIGNAL(readyRead()), SLOT(readMore()));
// Records audio for 3000ms
qDebug() <<"record begin!" << endl;
}
void Audio_Read::readMore()
{
char bytes[800] = {0};
int i = 0;
float input_frame1[320];
QByteArray frame;
QAudioFormat format; // set up the format you want, eg. format.setSampleRate(8000); format.setChannelCount(1); format.setSampleSize(16); format.setCodec("audio/pcm"); format.setByteOrder(QAudioFormat::LittleEndian); //format.setByteOrder(QAudioFormat::BigEndian); format.setSampleType(QAudioFormat::UnSignedInt); //format.setSampleType(QAudioFormat::SignedInt); QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice(); if (!info.isFormatSupported(format)) { qWarning()<<"default format not supported try to use nearest"; format = info.nearestFormat(format); }
//将解压后数据转换为声卡识别格式 //大端 short num = 0; for (i = 0;i < 160;i++) { num = output_frame1; buf[2 * i] = num; buf[2 * i + 1] = num >> 8; //qDebug() << "float out" << num << output_frame1; }