1
0
mirror of https://gitee.com/drabel/LibQQt.git synced 2025-01-04 10:18:44 +08:00
2018-04-19 18:46:08 +08:00

45 lines
1.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow ( QWidget* parent ) :
QMainWindow ( parent ),
ui ( new Ui::MainWindow )
{
ui->setupUi ( this );
//wavManager设置待播放的文件inputFormat起效
wavManager.setInputSourceFile ( res ( "9763.wav" ) );
//audManager设置输出设备也就是设置输出喇叭并且这里的并且很重要设置输出格式等于wav里的音频的格式。
audManager.outputDeviceInfo() = QQtAudioManager::defaultOutputDevice();
audManager.outputAudioFormat() = wavManager.inputAudioFormat();
//连接wavManager的音频帧接收槽这里其实是个接收器在接收器里播放。
connect ( &wavManager, SIGNAL ( readyRead() ), this, SLOT ( on_play_frame() ) );
;
//这个是专门为使用机械硬盘设置的减慢读取timer要不有滋滋的噪音。
wavManager.inputManager()->setTimerInterval ( 100 );
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
wavManager.stopInput();
audManager.stopOutput();
audManager.startDefaultOutput();
wavManager.startInput();
}
void MainWindow::on_play_frame()
{
//这里readAll就是读一帧wavManger内部对音频进行了切帧
QByteArray bytes = wavManager.readAll();
//播放
audManager.write ( bytes );
}