examples/multimedia/audioinput/audioinput.h
branchRCL_3
changeset 7 3f74d0d4af4c
parent 4 3b1da2848fc7
--- a/examples/multimedia/audioinput/audioinput.h	Mon Mar 15 12:43:09 2010 +0200
+++ b/examples/multimedia/audioinput/audioinput.h	Thu Apr 08 14:19:33 2010 +0300
@@ -45,6 +45,7 @@
 #include <QMainWindow>
 #include <QPushButton>
 #include <QComboBox>
+#include <QByteArray>
 
 #include <qaudioinput.h>
 
@@ -52,21 +53,21 @@
 {
     Q_OBJECT
 public:
-    AudioInfo(QObject *parent, QAudioInput *device);
+    AudioInfo(const QAudioFormat &format, QObject *parent);
     ~AudioInfo();
 
     void start();
     void stop();
 
-    int LinearMax();
+    qreal level() const { return m_level; }
 
     qint64 readData(char *data, qint64 maxlen);
     qint64 writeData(const char *data, qint64 len);
 
-    QAudioInput *input;
-
 private:
-    int m_maxValue;
+    const QAudioFormat m_format;
+    quint16 m_maxAmplitude;
+    qreal m_level; // 0.0 <= m_level <= 1.0
 
 signals:
     void update();
@@ -80,14 +81,14 @@
 public:
     RenderArea(QWidget *parent = 0);
 
-    void setLevel(int value);
+    void setLevel(qreal value);
 
 protected:
     void paintEvent(QPaintEvent *event);
 
 private:
-    int level;
-    QPixmap pixmap;
+    qreal m_level;
+    QPixmap m_pixmap;
 };
 
 class InputTest : public QMainWindow
@@ -97,29 +98,38 @@
     InputTest();
     ~InputTest();
 
+private:
+    void initializeWindow();
+    void initializeAudio();
+    void createAudioInput();
+
 private slots:
     void refreshDisplay();
-    void status();
+    void notified();
     void readMore();
     void toggleMode();
     void toggleSuspend();
-    void state(QAudio::State s);
-    void deviceChanged(int idx);
+    void stateChanged(QAudio::State state);
+    void deviceChanged(int index);
 
 private:
-    AudioInfo *audioinfo;
-    QAudioDeviceInfo device;
-    QAudioFormat format;
-    QAudioInput *audioInput;
-    QIODevice *input;
-    RenderArea *canvas;
+    // Owned by layout
+    RenderArea *m_canvas;
+    QPushButton *m_modeButton;
+    QPushButton *m_suspendResumeButton;
+    QComboBox *m_deviceBox;
 
-    bool pullMode;
+    QAudioDeviceInfo m_device;
+    AudioInfo *m_audioInfo;
+    QAudioFormat m_format;
+    QAudioInput *m_audioInput;
+    QIODevice *m_input;
+    bool m_pullMode;
+    QByteArray m_buffer;
 
-    QPushButton *button;
-    QPushButton *button2;
-    QComboBox *deviceBox;
-
-    char *buffer;
+    static const QString PushModeLabel;
+    static const QString PullModeLabel;
+    static const QString SuspendLabel;
+    static const QString ResumeLabel;
 };