Advertisement
Guest User

mainwindow.h

a guest
Apr 3rd, 2013
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QMainWindow>
  5. #include <QTimer>
  6. #include <QDebug>
  7.  
  8. #include <QAudioOutput>
  9. #include <QByteArray>
  10. #include <QIODevice>
  11.  
  12. class AudioManager : public QObject
  13. {
  14.     Q_OBJECT
  15.     public:
  16.         explicit AudioManager(QObject *parent = 0);
  17.  
  18.     public slots:
  19.         /// plays data (as PCM)
  20.         void playAudio(QByteArray data);
  21.  
  22.         void start();
  23.         void stop();
  24.  
  25.     private:
  26.         QIODevice* m_audioOutputDevice;
  27.  
  28.         // audio format, initialized with PCM values
  29.         QAudioFormat m_pcmFormat;
  30.  
  31.         QAudioOutput* m_audioOutput;
  32. };
  33.  
  34. namespace Ui {
  35. class MainWindow;
  36. }
  37.  
  38. class MainWindow : public QMainWindow
  39. {
  40.         Q_OBJECT
  41.        
  42.     public:
  43.         explicit MainWindow(QWidget *parent = 0);
  44.         ~MainWindow();
  45.  
  46.     protected slots:
  47.         void timer()
  48.         {
  49.             if (!m_playing)
  50.             {
  51.                 m_audio.start();
  52.                 m_audio.playAudio(QByteArray(16*20, ' '));
  53.  
  54.                 m_timer.start(22);
  55.                 m_playing = true;
  56.             }
  57.             else
  58.             {
  59.                 m_audio.stop();
  60.                  m_timer.start(200);
  61.                 //m_timer.start(10);
  62.                 m_playing = false;
  63.             }
  64.         }
  65.     private:
  66.         Ui::MainWindow *ui;
  67.         AudioManager m_audio;
  68.         QTimer m_timer;
  69.         bool m_playing;
  70. };
  71.  
  72. #endif // MAINWINDOW_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement