Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow),
- m_audio(this),
- m_playing(false)
- {
- ui->setupUi(this);
- connect(&m_timer, SIGNAL(timeout()), this, SLOT(timer()));
- m_timer.start();
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- }
- #include <QAudioDeviceInfo>
- #include <QDebug>
- // =====================================================================================================================
- AudioManager::AudioManager(QObject *parent) :
- QObject(parent)
- , m_audioOutputDevice(NULL)
- , m_audioOutput(NULL)
- {
- // PCM{U/A}
- m_pcmFormat.setByteOrder(QAudioFormat::LittleEndian);
- m_pcmFormat.setChannelCount(1);
- m_pcmFormat.setCodec("audio/pcm");
- m_pcmFormat.setFrequency(8000);
- m_pcmFormat.setSampleSize(16);
- m_pcmFormat.setSampleType(QAudioFormat::SignedInt);
- }
- // =====================================================================================================================
- void AudioManager::start()
- {
- m_audioOutput = new QAudioOutput(m_pcmFormat, this);
- m_audioOutputDevice = m_audioOutput->start();
- qDebug() << "Started output";
- }
- void AudioManager::stop()
- {
- qDebug() << "Stopping output";
- m_audioOutput->stop();
- qDebug() << "Stopped output";
- m_audioOutputDevice = NULL;
- qDebug() << "Delete output";
- delete m_audioOutput;
- m_audioOutput = NULL;
- qDebug() << "Output reset";
- }
- // =====================================================================================================================
- void AudioManager::playAudio(QByteArray data)
- {
- if (!m_audioOutputDevice || !m_audioOutput)
- {
- qDebug() << "Cannot play, device: " << m_audioOutputDevice << " output: " << m_audioOutput;
- return;
- }
- m_audioOutputDevice->write(data);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement