Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef MAINWINDOW_H
- #define MAINWINDOW_H
- #include <QMainWindow>
- #include <QTimer>
- #include <QDebug>
- #include <QAudioOutput>
- #include <QByteArray>
- #include <QIODevice>
- class AudioManager : public QObject
- {
- Q_OBJECT
- public:
- explicit AudioManager(QObject *parent = 0);
- public slots:
- /// plays data (as PCM)
- void playAudio(QByteArray data);
- void start();
- void stop();
- private:
- QIODevice* m_audioOutputDevice;
- // audio format, initialized with PCM values
- QAudioFormat m_pcmFormat;
- QAudioOutput* m_audioOutput;
- };
- namespace Ui {
- class MainWindow;
- }
- class MainWindow : public QMainWindow
- {
- Q_OBJECT
- public:
- explicit MainWindow(QWidget *parent = 0);
- ~MainWindow();
- protected slots:
- void timer()
- {
- if (!m_playing)
- {
- m_audio.start();
- m_audio.playAudio(QByteArray(16*20, ' '));
- m_timer.start(22);
- m_playing = true;
- }
- else
- {
- m_audio.stop();
- m_timer.start(200);
- //m_timer.start(10);
- m_playing = false;
- }
- }
- private:
- Ui::MainWindow *ui;
- AudioManager m_audio;
- QTimer m_timer;
- bool m_playing;
- };
- #endif // MAINWINDOW_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement