资源简介
Qt录音机 基于QAudioInput 和 QAudioOutput 实现了
录音, 麦克风音量监听, 麦克风音量调节,
还有一个去噪算法, 不太理想, 注掉了
代码片段和文件信息
#include “AudioRecorder.h“
#include
#include
#include
#include
#include
#define BufferSize 14096
struct HEADER
{
char RIFFNAME[4];
unsigned long nRIFFLength;
char WAVNAME[4];
char FMTNAME[4];
unsigned long nFMTLength;
unsigned short nAudioFormat;
unsigned short nChannleNumber;
unsigned long nSampleRate;
unsigned long nBytesPerSecond;
unsigned short nBytesPerSample;
unsigned short nBitsPerSample;
char DATANAME[4];
unsigned long nDataLength;
};
AudioRecorder::AudioRecorder(QWidget *parent)
: QWidget(parent)
mBuffer(BufferSize 0)
{
ui.setupUi(this);
miMaxValue = 0;
miVolume = ui.horizontalSlider->value();
mpOutputFile = NULL;
mpAudioInputFile = NULL;
mpAudioOutputFile = NULL;
mpAudioInputSound = NULL;
mpAudioOutputSound = NULL;
mpInputDevSound = NULL;
mpInputDevSound = NULL;
ui.btn_stop->setDisabled(true);
ui.btn_play->setDisabled(true);
ui.btn_save->setDisabled(true);
mpOutputFile = new QFile();
mpOutputFile->setFileName(tr(“record.raw“));
//mFormatFile.setFrequency(8000);
//mFormatFile.setChannels(1);
mFormatFile.setSampleSize(16);
mFormatFile.setSampleType(QAudioFormat::SignedInt);
mFormatFile.setByteOrder(QAudioFormat::LittleEndian);
mFormatFile.setCodec(“audio/pcm“);
QAudioDeviceInfo info(QAudioDeviceInfo::defaultInputDevice());
if (!info.isFormatSupported(mFormatFile)) {
qWarning(“input default mFormatFile not supported try to use nearest“);
mFormatFile = info.nearestFormat(mFormatFile);
}
QAudioDeviceInfo info1(QAudioDeviceInfo::defaultOutputDevice());
if (!info1.isFormatSupported(mFormatFile)) {
qWarning() << “output default mFormatFile not supported - trying to use nearest“;
// mFormatFile = info.nearestFormat(mFormatSound);
qWarning() << “output no support input mFormatFile.“;
return;
}
if(mFormatFile.sampleSize() != 16) {
qWarning(“audio device doesn‘t support 16 bit support %d bit samples example cannot run“ mFormatFile.sampleSize());
mpAudioInputFile = 0;
return;
}
mpAudioInputFile = NULL;
mpAudioOutputFile = NULL;
connect(ui.btn_start SIGNAL(clicked()) thisSLOT(OnRecordStart()));
connect(ui.btn_stop SIGNAL(clicked()) thisSLOT(OnRecordStop()));
connect(ui.btn_play SIGNAL(clicked()) thisSLOT(OnRecordPlay()));
connect(ui.btn_save SIGNAL(clicked()) thisSLOT(OnRecordSave()));
InitMonitor();
}
AudioRecorder::~AudioRecorder()
{
}
void AudioRecorder::OnRecordStart()
{
mpOutputFile->open(QIODevice::WriteOnly | QIODevice::Truncate);
mpAudioInputFile = new QAudioInput(mFormatFile this);
mpAudioInputFile->start(mpOutputFile);
ui.btn_start->setDisabled(true);
ui.btn_stop->setDisabled(false);
ui.btn_play->setDisabled(true);
ui.btn_save->setDisabled(true);
}
void AudioRecorder::OnRecordPlay()
{
mpOutputFile->open(QIODevice::ReadOnly | QIODevice::Truncate);
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2014-05-29 17:06 AudioRecorder\
文件 9637 2014-05-29 16:55 AudioRecorder\AudioRecorder.cpp
文件 1183 2014-05-29 16:51 AudioRecorder\AudioRecorder.h
文件 2734 2013-06-03 21:56 AudioRecorder\AudioRecorder.ico
文件 73 2014-05-29 15:48 AudioRecorder\AudioRecorder.qrc
文件 52 2014-05-29 15:48 AudioRecorder\AudioRecorder.rc
文件 3164 2014-05-29 17:02 AudioRecorder\AudioRecorder.ui
文件 9997 2014-05-29 16:00 AudioRecorder\AudioRecorder.vcxproj
文件 2365 2014-05-29 16:00 AudioRecorder\AudioRecorder.vcxproj.filters
文件 609 2014-05-29 15:48 AudioRecorder\AudioRecorder.vcxproj.user
文件 185 2014-05-29 15:48 AudioRecorder\main.cpp
文件 42880 2014-05-29 16:56 AudioRecorder\record.raw
评论
共有 条评论