2018-02-12 16:58:34 +08:00
|
|
|
|
#include "mainwindow.h"
|
2018-02-10 00:32:32 +08:00
|
|
|
|
#include "ui_mainwindow.h"
|
|
|
|
|
#include <qqtaudiomanager.h>
|
|
|
|
|
#include <qqtcore.h>
|
2018-02-10 23:49:06 +08:00
|
|
|
|
#include <qsound.h>
|
|
|
|
|
#include <qsoundeffect.h>
|
2018-02-13 20:21:20 +08:00
|
|
|
|
#include <qqtsoundeffect.h>
|
|
|
|
|
#include <qqtframe.h>
|
2018-02-10 00:32:32 +08:00
|
|
|
|
|
|
|
|
|
MainWindow::MainWindow ( QWidget* parent ) :
|
|
|
|
|
QMainWindow ( parent ),
|
|
|
|
|
ui ( new Ui::MainWindow )
|
|
|
|
|
{
|
|
|
|
|
ui->setupUi ( this );
|
|
|
|
|
|
2018-02-10 23:49:06 +08:00
|
|
|
|
connect ( &manager, SIGNAL ( readyRead() ), this, SLOT ( readyRead() ) );
|
2018-02-10 00:32:32 +08:00
|
|
|
|
|
2018-02-13 20:21:20 +08:00
|
|
|
|
connect ( &wavRecManager, SIGNAL ( readyRead() ), this, SLOT ( wavRecReadyRead() ) );
|
|
|
|
|
connect ( &wavFileManager, SIGNAL ( readyRead() ), this, SLOT ( wavFileReadyRead() ) );
|
|
|
|
|
|
2018-02-10 00:32:32 +08:00
|
|
|
|
QList<QAudioDeviceInfo> ladInfo;
|
|
|
|
|
ladInfo = QAudioDeviceInfo::availableDevices ( QAudio::AudioInput );
|
|
|
|
|
QListIterator<QAudioDeviceInfo> itor ( ladInfo );
|
|
|
|
|
pline() << "本机音频输入设备列表";
|
2018-02-11 20:18:05 +08:00
|
|
|
|
|
2018-02-10 00:32:32 +08:00
|
|
|
|
while ( itor.hasNext() )
|
|
|
|
|
pline() << itor.next().deviceName();
|
2018-02-11 20:18:05 +08:00
|
|
|
|
|
2018-02-10 00:32:32 +08:00
|
|
|
|
pline() << "默认输入设备" << QAudioDeviceInfo::defaultInputDevice().deviceName();
|
|
|
|
|
pline() << "输入设备详细信息";
|
|
|
|
|
itor.toFront();
|
2018-02-11 20:18:05 +08:00
|
|
|
|
|
2018-02-10 00:32:32 +08:00
|
|
|
|
while ( itor.hasNext() )
|
|
|
|
|
{
|
|
|
|
|
QAudioDeviceInfo adInfo = itor.next();
|
|
|
|
|
pline() << adInfo.deviceName();
|
|
|
|
|
pline() << adInfo.supportedByteOrders();
|
|
|
|
|
pline() << adInfo.supportedChannelCounts();
|
|
|
|
|
pline() << adInfo.supportedCodecs();
|
|
|
|
|
pline() << adInfo.supportedSampleRates();
|
|
|
|
|
pline() << adInfo.supportedSampleSizes();
|
|
|
|
|
pline() << adInfo.supportedSampleTypes();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QList<QAudioDeviceInfo> ladOutputInfo;
|
|
|
|
|
ladOutputInfo = QAudioDeviceInfo::availableDevices ( QAudio::AudioOutput );
|
|
|
|
|
QListIterator<QAudioDeviceInfo> itor2 ( ladOutputInfo );
|
|
|
|
|
pline() << "本机音频输出设备列表";
|
2018-02-11 20:18:05 +08:00
|
|
|
|
|
2018-02-10 00:32:32 +08:00
|
|
|
|
while ( itor2.hasNext() )
|
|
|
|
|
pline() << itor2.next().deviceName();
|
2018-02-11 20:18:05 +08:00
|
|
|
|
|
2018-02-10 00:32:32 +08:00
|
|
|
|
pline() << "默认输出设备" << QAudioDeviceInfo::defaultOutputDevice().deviceName();
|
|
|
|
|
pline() << "输出设备详细信息";
|
|
|
|
|
itor2.toFront();
|
2018-02-11 20:18:05 +08:00
|
|
|
|
|
2018-02-10 00:32:32 +08:00
|
|
|
|
while ( itor2.hasNext() )
|
|
|
|
|
{
|
|
|
|
|
QAudioDeviceInfo adInfo = itor2.next();
|
|
|
|
|
pline() << adInfo.deviceName();
|
|
|
|
|
pline() << adInfo.supportedByteOrders();
|
|
|
|
|
pline() << adInfo.supportedChannelCounts();
|
|
|
|
|
pline() << adInfo.supportedCodecs();
|
|
|
|
|
pline() << adInfo.supportedSampleRates();
|
|
|
|
|
pline() << adInfo.supportedSampleSizes();
|
|
|
|
|
pline() << adInfo.supportedSampleTypes();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pline() << "..........................";
|
|
|
|
|
|
|
|
|
|
connect ( ui->inputListWidget->selectionModel(), SIGNAL ( currentRowChanged ( QModelIndex, QModelIndex ) ),
|
|
|
|
|
this, SLOT ( currentInputRowChanged ( QModelIndex, QModelIndex ) ) );
|
|
|
|
|
connect ( ui->outputListWidget->selectionModel(), SIGNAL ( currentRowChanged ( QModelIndex, QModelIndex ) ),
|
|
|
|
|
this, SLOT ( currentOutputRowChanged ( QModelIndex, QModelIndex ) ) );
|
2018-02-10 13:18:08 +08:00
|
|
|
|
|
|
|
|
|
// on_pushButton_2_clicked();
|
|
|
|
|
// ui->inputListWidget->setCurrentRow ( 0 );
|
|
|
|
|
// ui->outputListWidget->setCurrentRow ( 0 );
|
|
|
|
|
// ui->inputListWidget->setFocus();
|
|
|
|
|
|
|
|
|
|
ui->inHS->setRange ( 0, 100 );
|
|
|
|
|
ui->inHS->setValue ( 100 );
|
|
|
|
|
|
|
|
|
|
ui->outHS->setRange ( 0, 100 );
|
|
|
|
|
ui->outHS->setValue ( 100 );
|
2018-02-11 20:18:05 +08:00
|
|
|
|
|
|
|
|
|
//pline() << QSoundEffect::supportedMimeTypes();
|
|
|
|
|
|
|
|
|
|
QSoundEffect e;
|
|
|
|
|
e.setLoopCount ( 1 );
|
|
|
|
|
e.setVolume ( 0.9f );
|
|
|
|
|
e.setMuted ( false );
|
|
|
|
|
|
|
|
|
|
//不响
|
|
|
|
|
QUrl u;
|
|
|
|
|
u.setUrl ( "http://xmdx.sc.chinaz.com/Files/DownLoad/sound1/201802/9733.wav" );
|
|
|
|
|
e.setSource ( u );
|
|
|
|
|
//e.play();
|
|
|
|
|
|
|
|
|
|
//响
|
2018-02-13 20:21:20 +08:00
|
|
|
|
e.setSource ( QUrl::fromLocalFile ( res ( "9733.wav" ) ) );
|
2018-02-11 20:18:05 +08:00
|
|
|
|
//e.play();
|
|
|
|
|
|
|
|
|
|
//响
|
2018-02-13 20:21:20 +08:00
|
|
|
|
//QSound::play ( res ( "9733.wav" ) );
|
2018-02-11 20:18:05 +08:00
|
|
|
|
|
2018-02-12 16:58:34 +08:00
|
|
|
|
//响
|
2018-02-12 20:47:57 +08:00
|
|
|
|
QQtWavSoundEffect e1;
|
2018-02-13 20:21:20 +08:00
|
|
|
|
//e1.play ( res ( "9733.wav" ) );
|
2018-02-12 07:20:52 +08:00
|
|
|
|
|
2018-02-12 16:58:34 +08:00
|
|
|
|
//响
|
2018-02-12 07:20:52 +08:00
|
|
|
|
//QApplication::beep();
|
2018-02-11 20:18:05 +08:00
|
|
|
|
|
2018-02-12 16:58:34 +08:00
|
|
|
|
//建议初始化
|
2018-02-12 20:47:57 +08:00
|
|
|
|
QQtWavSoundEffect::Instance ( this );
|
2018-02-12 16:58:34 +08:00
|
|
|
|
|
|
|
|
|
//可以多次循环调用。
|
2018-02-13 20:21:20 +08:00
|
|
|
|
QQtWavSound ( res ( "9733.wav" ) );
|
2018-02-12 16:58:34 +08:00
|
|
|
|
|
|
|
|
|
//QQtSleep ( 3000 );
|
2018-02-11 20:18:05 +08:00
|
|
|
|
|
2018-02-10 00:32:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
|
{
|
|
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QAudioDeviceInfo MainWindow::findInputAudioDeviceInfoByName ( QString devName )
|
|
|
|
|
{
|
|
|
|
|
QList<QAudioDeviceInfo> ladInfo;
|
|
|
|
|
ladInfo = QQtAudioManager::availableInputDevices();
|
|
|
|
|
QListIterator<QAudioDeviceInfo> itor ( ladInfo );
|
2018-02-11 20:18:05 +08:00
|
|
|
|
|
2018-02-10 00:32:32 +08:00
|
|
|
|
while ( itor.hasNext() )
|
|
|
|
|
{
|
|
|
|
|
QAudioDeviceInfo adInfo = itor.next();
|
2018-02-11 20:18:05 +08:00
|
|
|
|
|
2018-02-10 00:32:32 +08:00
|
|
|
|
if ( devName == adInfo.deviceName() )
|
|
|
|
|
return adInfo;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QAudioDeviceInfo MainWindow::findOutputAudioDeviceInfoByName ( QString devName )
|
|
|
|
|
{
|
|
|
|
|
QList<QAudioDeviceInfo> ladInfo;
|
|
|
|
|
ladInfo = QQtAudioManager::availableOutputDevices();
|
|
|
|
|
QListIterator<QAudioDeviceInfo> itor ( ladInfo );
|
2018-02-11 20:18:05 +08:00
|
|
|
|
|
2018-02-10 00:32:32 +08:00
|
|
|
|
while ( itor.hasNext() )
|
|
|
|
|
{
|
|
|
|
|
QAudioDeviceInfo adInfo = itor.next();
|
2018-02-11 20:18:05 +08:00
|
|
|
|
|
2018-02-10 00:32:32 +08:00
|
|
|
|
if ( devName == adInfo.deviceName() )
|
|
|
|
|
return adInfo;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_pushButton_2_clicked()
|
|
|
|
|
{
|
|
|
|
|
ui->inputListWidget->clear();
|
|
|
|
|
|
|
|
|
|
QList<QAudioDeviceInfo> ladInfo;
|
|
|
|
|
ladInfo = QQtAudioManager::availableInputDevices();
|
|
|
|
|
QListIterator<QAudioDeviceInfo> itor ( ladInfo );
|
|
|
|
|
pline() << "本机音频输入设备列表";
|
2018-02-11 20:18:05 +08:00
|
|
|
|
|
2018-02-10 00:32:32 +08:00
|
|
|
|
while ( itor.hasNext() )
|
|
|
|
|
{
|
|
|
|
|
QAudioDeviceInfo adInfo = itor.next();
|
|
|
|
|
pline() << adInfo.deviceName();
|
|
|
|
|
ui->inputListWidget->addItem ( adInfo.deviceName() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ui->outputListWidget->clear();
|
|
|
|
|
|
|
|
|
|
QList<QAudioDeviceInfo> ladOutputInfo;
|
|
|
|
|
ladOutputInfo = QQtAudioManager::availableOutputDevices();
|
|
|
|
|
QListIterator<QAudioDeviceInfo> itor2 ( ladOutputInfo );
|
|
|
|
|
pline() << "本机音频输出设备列表";
|
2018-02-11 20:18:05 +08:00
|
|
|
|
|
2018-02-10 00:32:32 +08:00
|
|
|
|
while ( itor2.hasNext() )
|
|
|
|
|
{
|
|
|
|
|
QAudioDeviceInfo adInfo = itor2.next();
|
|
|
|
|
pline() << adInfo.deviceName();
|
|
|
|
|
ui->outputListWidget->addItem ( adInfo.deviceName() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::currentInputRowChanged ( QModelIndex cur, QModelIndex )
|
|
|
|
|
{
|
|
|
|
|
/*在清空设备列表时,clear函数,会调用多次这个函数。在这里用cur valid加以过滤,否则,程序会崩溃退出。*/
|
|
|
|
|
if ( !cur.isValid() )
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ui->inBit->clear();
|
|
|
|
|
ui->inChn->clear();
|
|
|
|
|
ui->intRate->clear();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QString name = cur.data().toString();
|
|
|
|
|
QAudioDeviceInfo dev = findInputAudioDeviceInfoByName ( name );
|
|
|
|
|
|
|
|
|
|
if ( dev.isNull() )
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QList<int> size = dev.supportedSampleSizes();
|
|
|
|
|
QListIterator<int> itor ( size );
|
2018-02-11 20:18:05 +08:00
|
|
|
|
|
2018-02-10 00:32:32 +08:00
|
|
|
|
while ( itor.hasNext() )
|
|
|
|
|
{
|
|
|
|
|
QString s0 = QString::number ( itor.next() );
|
|
|
|
|
ui->inBit->addItem ( s0 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
itor = dev.supportedChannelCounts();
|
2018-02-11 20:18:05 +08:00
|
|
|
|
|
2018-02-10 00:32:32 +08:00
|
|
|
|
while ( itor.hasNext() )
|
|
|
|
|
{
|
|
|
|
|
QString s0 = QString::number ( itor.next() );
|
|
|
|
|
ui->inChn->addItem ( s0 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
itor = dev.supportedSampleRates();
|
2018-02-11 20:18:05 +08:00
|
|
|
|
|
2018-02-10 00:32:32 +08:00
|
|
|
|
while ( itor.hasNext() )
|
|
|
|
|
{
|
|
|
|
|
QString s0 = QString::number ( itor.next() );
|
|
|
|
|
ui->intRate->addItem ( s0 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::currentOutputRowChanged ( QModelIndex cur, QModelIndex )
|
|
|
|
|
{
|
|
|
|
|
if ( !cur.isValid() )
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ui->outBit->clear();
|
|
|
|
|
ui->outChn->clear();
|
|
|
|
|
ui->outRate->clear();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QString name = cur.data().toString();
|
|
|
|
|
QAudioDeviceInfo dev = findOutputAudioDeviceInfoByName ( name );
|
|
|
|
|
|
|
|
|
|
if ( dev.isNull() )
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QList<int> size = dev.supportedSampleSizes();
|
|
|
|
|
QListIterator<int> itor ( size );
|
2018-02-11 20:18:05 +08:00
|
|
|
|
|
2018-02-10 00:32:32 +08:00
|
|
|
|
while ( itor.hasNext() )
|
|
|
|
|
{
|
|
|
|
|
QString s0 = QString::number ( itor.next() );
|
|
|
|
|
ui->outBit->addItem ( s0 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
itor = dev.supportedChannelCounts();
|
2018-02-11 20:18:05 +08:00
|
|
|
|
|
2018-02-10 00:32:32 +08:00
|
|
|
|
while ( itor.hasNext() )
|
|
|
|
|
{
|
|
|
|
|
QString s0 = QString::number ( itor.next() );
|
|
|
|
|
ui->outChn->addItem ( s0 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
itor = dev.supportedSampleRates();
|
2018-02-11 20:18:05 +08:00
|
|
|
|
|
2018-02-10 00:32:32 +08:00
|
|
|
|
while ( itor.hasNext() )
|
|
|
|
|
{
|
|
|
|
|
QString s0 = QString::number ( itor.next() );
|
|
|
|
|
ui->outRate->addItem ( s0 );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-10 13:18:08 +08:00
|
|
|
|
/*
|
|
|
|
|
* 处理声音三要点
|
|
|
|
|
* 声音的格式 ,也就是声音三要素,输入一个、输出一个,manager对其分开管理,但是建议用户合并为一个置等。通道数、采样位宽、采样率
|
|
|
|
|
* 声音设备 ,输入一个、输出一个,manager管理start\stop等接口,manager内部的inputManager和outputManager负责其他接口。
|
|
|
|
|
* 声音设备的读写出入口 ,manager管理,包括可读信号和写入函数。
|
|
|
|
|
*/
|
2018-02-10 00:32:32 +08:00
|
|
|
|
void MainWindow::on_pushButton_clicked()
|
|
|
|
|
{
|
2018-02-10 10:59:35 +08:00
|
|
|
|
/*这里是自定义输入、输出设备*/
|
2018-02-10 16:12:47 +08:00
|
|
|
|
QString name = QQtAudioManager::defaultInputDevice().deviceName();
|
2018-02-11 20:18:05 +08:00
|
|
|
|
|
2018-02-10 16:12:47 +08:00
|
|
|
|
if ( ui->inputListWidget->currentIndex().isValid() )
|
|
|
|
|
name = ui->inputListWidget->currentIndex().data().toString();
|
2018-02-11 20:18:05 +08:00
|
|
|
|
|
2018-02-10 00:32:32 +08:00
|
|
|
|
QAudioDeviceInfo dev = findInputAudioDeviceInfoByName ( name );
|
|
|
|
|
|
2018-02-10 16:12:47 +08:00
|
|
|
|
name = QQtAudioManager::defaultOutputDevice().deviceName();
|
2018-02-11 20:18:05 +08:00
|
|
|
|
|
2018-02-10 16:12:47 +08:00
|
|
|
|
if ( ui->outputListWidget->currentIndex().isValid() )
|
|
|
|
|
name = ui->outputListWidget->currentIndex().data().toString();
|
2018-02-11 20:18:05 +08:00
|
|
|
|
|
2018-02-10 00:32:32 +08:00
|
|
|
|
QAudioDeviceInfo devOut = findOutputAudioDeviceInfoByName ( name );
|
|
|
|
|
|
2018-02-10 10:59:35 +08:00
|
|
|
|
/*使用默认输入、输出设备*/
|
|
|
|
|
//如果开启这段代码,页面上的输入、输出设备选择,就仅仅是个显示了,不具备操作能力。
|
|
|
|
|
/*
|
|
|
|
|
dev = QQtAudioManager::defaultInputDevice();
|
|
|
|
|
devOut = QQtAudioManager::defaultOutputDevice();
|
|
|
|
|
*/
|
2018-02-10 00:32:32 +08:00
|
|
|
|
|
2018-02-10 10:59:35 +08:00
|
|
|
|
//把设备设进manager去
|
2018-02-10 00:32:32 +08:00
|
|
|
|
manager.inputDeviceInfo() = dev;
|
|
|
|
|
manager.outputDeviceInfo() = devOut;
|
|
|
|
|
|
2018-02-10 10:59:35 +08:00
|
|
|
|
//这里保证输入、输出使用格式相等 或者 不同
|
|
|
|
|
//如果格式不同,在mac电脑上本地输入输出设备是可以使用的,但是对于连接的语音蓝牙话筒,却是不可以使用的,原因未知。
|
|
|
|
|
//格式相同的时候,实在是太好用啦。
|
|
|
|
|
//这个建议默认就相同,但是,在QQtAudioManager当中,并没有直接将其相等处理,如果用户在readyRead槽函数里,可以更改采样率进行某些特殊处理。一般不需要差异处理的,相等就行了。
|
2018-02-10 16:12:47 +08:00
|
|
|
|
// int inBit = ui->inBit->currentIndex().data().toInt();
|
|
|
|
|
// int inChn = ui->inChn->currentIndex().data().toInt();
|
|
|
|
|
// int inRate = ui->intRate->currentIndex().data().toInt();
|
|
|
|
|
// QAudioFormat inFmt;
|
|
|
|
|
// inFmt.setChannelCount ( inChn );
|
|
|
|
|
// inFmt.setSampleSize ( inBit );
|
|
|
|
|
// inFmt.setSampleRate ( inRate );
|
|
|
|
|
// inFmt.setCodec ( "audio/pcm" );
|
|
|
|
|
// manager.inputAudioFormat() = inFmt;
|
|
|
|
|
|
|
|
|
|
QAudioFormat outFmt = manager.outputDeviceInfo().preferredFormat();
|
|
|
|
|
|
|
|
|
|
int outBit = outFmt.sampleSize(), outChn = outFmt.channelCount(), outRate = outFmt.sampleRate();
|
2018-02-11 20:18:05 +08:00
|
|
|
|
|
2018-02-10 16:12:47 +08:00
|
|
|
|
if ( ui->outBit->currentIndex().isValid() )
|
|
|
|
|
outBit = ui->outBit->currentIndex().data().toInt();
|
2018-02-11 20:18:05 +08:00
|
|
|
|
|
2018-02-10 16:12:47 +08:00
|
|
|
|
if ( ui->outChn->currentIndex().isValid() )
|
|
|
|
|
outChn = ui->outChn->currentIndex().data().toInt();
|
2018-02-11 20:18:05 +08:00
|
|
|
|
|
2018-02-10 16:12:47 +08:00
|
|
|
|
if ( ui->outRate->currentIndex().isValid() )
|
|
|
|
|
outRate = ui->outRate->currentIndex().data().toInt();
|
|
|
|
|
|
|
|
|
|
outFmt.setChannelCount ( outChn );
|
|
|
|
|
outFmt.setSampleSize ( outBit );
|
|
|
|
|
outFmt.setSampleRate ( outRate );
|
|
|
|
|
outFmt.setCodec ( "audio/pcm" );
|
|
|
|
|
|
|
|
|
|
manager.inputAudioFormat() = outFmt;
|
|
|
|
|
manager.outputAudioFormat() = outFmt;
|
2018-02-10 10:59:35 +08:00
|
|
|
|
|
|
|
|
|
pline() << "in prefer" << dev.preferredFormat().channelCount() << dev.preferredFormat().sampleRate() <<
|
|
|
|
|
dev.preferredFormat().sampleSize();
|
|
|
|
|
|
2018-02-10 16:12:47 +08:00
|
|
|
|
pline() << "out prefer" << devOut.preferredFormat().channelCount() << devOut.preferredFormat().sampleRate() <<
|
|
|
|
|
devOut.preferredFormat().sampleSize();
|
|
|
|
|
|
2018-02-10 17:40:26 +08:00
|
|
|
|
pline() << "in" << manager.inputAudioFormat().channelCount() << manager.inputAudioFormat().sampleRate() <<
|
|
|
|
|
manager.inputAudioFormat().sampleSize();
|
|
|
|
|
|
2018-02-10 10:59:35 +08:00
|
|
|
|
pline() << "out" << manager.outputAudioFormat().channelCount() << manager.outputAudioFormat().sampleRate() <<
|
|
|
|
|
manager.outputAudioFormat().sampleSize();
|
|
|
|
|
|
2018-02-10 00:32:32 +08:00
|
|
|
|
manager.startInput();
|
|
|
|
|
manager.startOutput();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::readyRead()
|
|
|
|
|
{
|
2018-02-10 13:18:08 +08:00
|
|
|
|
//这里是用户实现,任何用户希望做的事情,都在这里做完。
|
|
|
|
|
//可以 录音、保存文件
|
|
|
|
|
//可以 直接播放
|
|
|
|
|
//可以 混音 +保存 +播放...
|
|
|
|
|
//可以 消音
|
|
|
|
|
//可以 将pcm转换为其他格式音频
|
|
|
|
|
//可以 降噪
|
|
|
|
|
//可以 ...
|
2018-02-11 20:18:05 +08:00
|
|
|
|
//ptime();//11-12ms 是个10ms timer
|
2018-02-12 07:20:52 +08:00
|
|
|
|
QByteArray bytes = manager.readAll();
|
|
|
|
|
manager.write ( bytes );
|
2018-02-10 00:32:32 +08:00
|
|
|
|
}
|
2018-02-10 10:59:35 +08:00
|
|
|
|
|
2018-02-13 20:21:20 +08:00
|
|
|
|
void MainWindow::wavRecReadyRead()
|
|
|
|
|
{
|
|
|
|
|
QByteArray bytes = wavRecManager.readAll();
|
|
|
|
|
//pline() << "recording:" << bytes.size();
|
|
|
|
|
wavFileManager.write ( bytes );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::wavFileReadyRead()
|
|
|
|
|
{
|
|
|
|
|
QByteArray bytes = wavFileManager.readAll();
|
|
|
|
|
//pline() << "playing:" << bytes.size();
|
|
|
|
|
wavRecManager.write ( bytes );
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-10 10:59:35 +08:00
|
|
|
|
void MainWindow::on_pushButton_3_clicked()
|
|
|
|
|
{
|
|
|
|
|
manager.stopInput();
|
2018-02-10 17:40:26 +08:00
|
|
|
|
manager.stopOutput();
|
2018-02-10 10:59:35 +08:00
|
|
|
|
}
|
2018-02-10 13:18:08 +08:00
|
|
|
|
|
|
|
|
|
/*bug:Qt 设置音量会报错退出*/
|
|
|
|
|
void MainWindow::on_inHS_valueChanged ( int value )
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if ( !manager.inputDevice() )
|
|
|
|
|
return;
|
|
|
|
|
|
2018-02-12 11:11:09 +08:00
|
|
|
|
qreal linearVolume;
|
|
|
|
|
// qreal linearVolume = QAudio::convertVolume ( value / qreal ( 100.0 ),
|
|
|
|
|
// QAudio::LogarithmicVolumeScale,
|
|
|
|
|
// QAudio::LinearVolumeScale );
|
2018-02-10 13:18:08 +08:00
|
|
|
|
|
2018-02-12 11:11:09 +08:00
|
|
|
|
// pline() << "输入音量" << value << linearVolume << qRound ( linearVolume * 100 ) ;
|
2018-02-10 13:18:08 +08:00
|
|
|
|
manager.inputManager()->setVolume ( qRound ( linearVolume * 100 ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*bug:Qt 设置音量会报错退出*/
|
|
|
|
|
void MainWindow::on_outHS_valueChanged ( int value )
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if ( !manager.outputDevice() )
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
qreal vol = qreal ( value ) / 100;
|
|
|
|
|
pline() << "输出音量" << vol ;
|
|
|
|
|
manager.outputManager()->setVolume ( vol );
|
|
|
|
|
}
|
2018-02-10 16:12:47 +08:00
|
|
|
|
|
|
|
|
|
void MainWindow::on_pushButton_4_clicked()
|
|
|
|
|
{
|
|
|
|
|
manager.inputAudioFormat() = QQtAudioManager::defaultOutputDevice().preferredFormat();
|
|
|
|
|
manager.outputAudioFormat() = QQtAudioManager::defaultOutputDevice().preferredFormat();
|
|
|
|
|
|
2018-02-10 17:40:26 +08:00
|
|
|
|
pline() << "in prefer" << QQtAudioManager::defaultInputDevice().preferredFormat().channelCount() <<
|
|
|
|
|
QQtAudioManager::defaultInputDevice().preferredFormat().sampleRate() <<
|
|
|
|
|
QQtAudioManager::defaultInputDevice().preferredFormat().sampleSize();
|
|
|
|
|
|
|
|
|
|
pline() << "out prefer" << QQtAudioManager::defaultOutputDevice().preferredFormat().channelCount() <<
|
|
|
|
|
QQtAudioManager::defaultOutputDevice().preferredFormat().sampleRate() <<
|
|
|
|
|
QQtAudioManager::defaultOutputDevice().preferredFormat().sampleSize();
|
|
|
|
|
|
|
|
|
|
pline() << "in" << manager.inputAudioFormat().channelCount() << manager.inputAudioFormat().sampleRate() <<
|
|
|
|
|
manager.inputAudioFormat().sampleSize();
|
|
|
|
|
|
|
|
|
|
pline() << "out" << manager.outputAudioFormat().channelCount() << manager.outputAudioFormat().sampleRate() <<
|
|
|
|
|
manager.outputAudioFormat().sampleSize();
|
|
|
|
|
|
2018-02-10 16:12:47 +08:00
|
|
|
|
manager.startDefaultInput();
|
|
|
|
|
manager.startDefaultOutput();
|
|
|
|
|
}
|
2018-02-12 16:58:34 +08:00
|
|
|
|
|
|
|
|
|
void MainWindow::on_pushButton_5_clicked()
|
|
|
|
|
{
|
|
|
|
|
QString name = QQtAudioManager::defaultOutputDevice().deviceName();
|
|
|
|
|
|
|
|
|
|
if ( ui->outputListWidget->currentIndex().isValid() )
|
|
|
|
|
name = ui->outputListWidget->currentIndex().data().toString();
|
|
|
|
|
|
|
|
|
|
QAudioDeviceInfo devOut = findOutputAudioDeviceInfoByName ( name );
|
|
|
|
|
|
2018-02-12 20:47:57 +08:00
|
|
|
|
QQtWavSoundEffect::Instance()->useCustomOutputDevice ( devOut );
|
2018-02-13 11:50:16 +08:00
|
|
|
|
QQtWavSound()->setLoops ( 3 );
|
2018-02-13 20:21:20 +08:00
|
|
|
|
QQtWavSound ( res ( "9733.wav" ) );
|
2018-02-12 16:58:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_pushButton_6_clicked()
|
|
|
|
|
{
|
|
|
|
|
QString name = QQtAudioManager::defaultOutputDevice().deviceName();
|
|
|
|
|
|
|
|
|
|
if ( ui->outputListWidget->currentIndex().isValid() )
|
|
|
|
|
name = ui->outputListWidget->currentIndex().data().toString();
|
|
|
|
|
|
|
|
|
|
QAudioDeviceInfo devOut = findOutputAudioDeviceInfoByName ( name );
|
|
|
|
|
|
2018-02-12 20:47:57 +08:00
|
|
|
|
QQtWavSoundEffect::Instance()->useCustomOutputDevice ( devOut );
|
2018-02-13 20:21:20 +08:00
|
|
|
|
QQtWavSound ( res ( "9763.wav" ) );
|
|
|
|
|
//QSound::play ( res("9763.wav"));
|
2018-02-12 16:58:34 +08:00
|
|
|
|
}
|
2018-02-13 11:50:16 +08:00
|
|
|
|
|
|
|
|
|
void MainWindow::on_pushButton_7_clicked()
|
|
|
|
|
{
|
|
|
|
|
QString name = QQtAudioManager::defaultOutputDevice().deviceName();
|
|
|
|
|
|
|
|
|
|
if ( ui->outputListWidget->currentIndex().isValid() )
|
|
|
|
|
name = ui->outputListWidget->currentIndex().data().toString();
|
|
|
|
|
|
|
|
|
|
QAudioDeviceInfo devOut = findOutputAudioDeviceInfoByName ( name );
|
|
|
|
|
|
|
|
|
|
QQtWavSoundEffect::Instance()->useCustomOutputDevice ( devOut );
|
|
|
|
|
QQtWavSound()->setLoops ( 1 );
|
2018-02-13 20:21:20 +08:00
|
|
|
|
QQtWavSound ( res ( "9612.wav" ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define TMPFILE "./temp.wav"
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_pushButton_8_clicked()
|
|
|
|
|
{
|
|
|
|
|
//不需要停止录音?需要
|
2018-02-13 21:04:13 +08:00
|
|
|
|
//android 不支持./temp.wav....
|
2018-02-13 20:21:20 +08:00
|
|
|
|
|
|
|
|
|
//record
|
|
|
|
|
QAudioDeviceInfo input = QQtAudioManager::defaultInputDevice();
|
|
|
|
|
wavRecManager.inputDeviceInfo() = input;
|
|
|
|
|
wavRecManager.inputAudioFormat() = input.preferredFormat();
|
|
|
|
|
|
|
|
|
|
//save wav file
|
|
|
|
|
wavFileManager.outputAudioFormat() = wavRecManager.inputAudioFormat();
|
|
|
|
|
wavFileManager.setOutputSourceFile ( TMPFILE );
|
|
|
|
|
|
|
|
|
|
pline() << "record:" << wavRecManager.inputDeviceInfo().deviceName() << wavRecManager.inputAudioFormat();
|
|
|
|
|
pline() << "save:" << wavFileManager.outputSourceFile() << wavFileManager.outputAudioFormat();
|
|
|
|
|
|
|
|
|
|
//内部存在自动关停。对wav写自动关停,会导致文件被重写。这个函数是录音重新开始,所以可以自动关停。
|
|
|
|
|
wavFileManager.startOutput();
|
|
|
|
|
wavRecManager.startInput();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_pushButton_9_clicked()
|
|
|
|
|
{
|
|
|
|
|
//不需要停止放音?需要
|
|
|
|
|
|
|
|
|
|
//read wav file
|
|
|
|
|
wavFileManager.setInputSourceFile ( TMPFILE );
|
|
|
|
|
|
|
|
|
|
//play record
|
|
|
|
|
wavRecManager.outputAudioFormat() = wavFileManager.inputAudioFormat();
|
|
|
|
|
wavRecManager.outputDeviceInfo() = QQtAudioManager::defaultOutputDevice();
|
|
|
|
|
|
|
|
|
|
pline() << "file:" << wavFileManager.inputSourceFile() << wavFileManager.inputAudioFormat();
|
|
|
|
|
pline() << "play:" << wavRecManager.outputDeviceInfo().deviceName() << wavRecManager.outputAudioFormat();
|
|
|
|
|
|
|
|
|
|
//内部存在自动关停。
|
|
|
|
|
wavRecManager.startOutput();
|
|
|
|
|
wavFileManager.startInput();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_pushButton_10_clicked()
|
|
|
|
|
{
|
|
|
|
|
wavRecManager.stopInput();
|
|
|
|
|
wavFileManager.stopOutput();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_pushButton_11_clicked()
|
|
|
|
|
{
|
|
|
|
|
wavFileManager.stopInput();
|
|
|
|
|
wavRecManager.stopOutput();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_pushButton_12_clicked()
|
|
|
|
|
{
|
|
|
|
|
//android support 16bit but 24bit
|
2018-04-17 19:32:16 +08:00
|
|
|
|
QQtWavSoundEffect* e0 = QQtWavSound();
|
|
|
|
|
e0->setTimerInterval ( 100 );
|
2018-02-13 20:34:56 +08:00
|
|
|
|
QQtWavSound ( res ( "9767.wav" ) );
|
2018-02-13 11:50:16 +08:00
|
|
|
|
}
|