43 #include <QWidget> |
43 #include <QWidget> |
44 #include <QObject> |
44 #include <QObject> |
45 #include <QMainWindow> |
45 #include <QMainWindow> |
46 #include <QPushButton> |
46 #include <QPushButton> |
47 #include <QComboBox> |
47 #include <QComboBox> |
|
48 #include <QByteArray> |
48 |
49 |
49 #include <qaudioinput.h> |
50 #include <qaudioinput.h> |
50 |
51 |
51 class AudioInfo : public QIODevice |
52 class AudioInfo : public QIODevice |
52 { |
53 { |
53 Q_OBJECT |
54 Q_OBJECT |
54 public: |
55 public: |
55 AudioInfo(QObject *parent, QAudioInput *device); |
56 AudioInfo(const QAudioFormat &format, QObject *parent); |
56 ~AudioInfo(); |
57 ~AudioInfo(); |
57 |
58 |
58 void start(); |
59 void start(); |
59 void stop(); |
60 void stop(); |
60 |
61 |
61 int LinearMax(); |
62 qreal level() const { return m_level; } |
62 |
63 |
63 qint64 readData(char *data, qint64 maxlen); |
64 qint64 readData(char *data, qint64 maxlen); |
64 qint64 writeData(const char *data, qint64 len); |
65 qint64 writeData(const char *data, qint64 len); |
65 |
66 |
66 QAudioInput *input; |
|
67 |
|
68 private: |
67 private: |
69 int m_maxValue; |
68 const QAudioFormat m_format; |
|
69 quint16 m_maxAmplitude; |
|
70 qreal m_level; // 0.0 <= m_level <= 1.0 |
70 |
71 |
71 signals: |
72 signals: |
72 void update(); |
73 void update(); |
73 }; |
74 }; |
74 |
75 |
78 Q_OBJECT |
79 Q_OBJECT |
79 |
80 |
80 public: |
81 public: |
81 RenderArea(QWidget *parent = 0); |
82 RenderArea(QWidget *parent = 0); |
82 |
83 |
83 void setLevel(int value); |
84 void setLevel(qreal value); |
84 |
85 |
85 protected: |
86 protected: |
86 void paintEvent(QPaintEvent *event); |
87 void paintEvent(QPaintEvent *event); |
87 |
88 |
88 private: |
89 private: |
89 int level; |
90 qreal m_level; |
90 QPixmap pixmap; |
91 QPixmap m_pixmap; |
91 }; |
92 }; |
92 |
93 |
93 class InputTest : public QMainWindow |
94 class InputTest : public QMainWindow |
94 { |
95 { |
95 Q_OBJECT |
96 Q_OBJECT |
96 public: |
97 public: |
97 InputTest(); |
98 InputTest(); |
98 ~InputTest(); |
99 ~InputTest(); |
99 |
100 |
|
101 private: |
|
102 void initializeWindow(); |
|
103 void initializeAudio(); |
|
104 void createAudioInput(); |
|
105 |
100 private slots: |
106 private slots: |
101 void refreshDisplay(); |
107 void refreshDisplay(); |
102 void status(); |
108 void notified(); |
103 void readMore(); |
109 void readMore(); |
104 void toggleMode(); |
110 void toggleMode(); |
105 void toggleSuspend(); |
111 void toggleSuspend(); |
106 void state(QAudio::State s); |
112 void stateChanged(QAudio::State state); |
107 void deviceChanged(int idx); |
113 void deviceChanged(int index); |
108 |
114 |
109 private: |
115 private: |
110 AudioInfo *audioinfo; |
116 // Owned by layout |
111 QAudioDeviceInfo device; |
117 RenderArea *m_canvas; |
112 QAudioFormat format; |
118 QPushButton *m_modeButton; |
113 QAudioInput *audioInput; |
119 QPushButton *m_suspendResumeButton; |
114 QIODevice *input; |
120 QComboBox *m_deviceBox; |
115 RenderArea *canvas; |
|
116 |
121 |
117 bool pullMode; |
122 QAudioDeviceInfo m_device; |
|
123 AudioInfo *m_audioInfo; |
|
124 QAudioFormat m_format; |
|
125 QAudioInput *m_audioInput; |
|
126 QIODevice *m_input; |
|
127 bool m_pullMode; |
|
128 QByteArray m_buffer; |
118 |
129 |
119 QPushButton *button; |
130 static const QString PushModeLabel; |
120 QPushButton *button2; |
131 static const QString PullModeLabel; |
121 QComboBox *deviceBox; |
132 static const QString SuspendLabel; |
122 |
133 static const QString ResumeLabel; |
123 char *buffer; |
|
124 }; |
134 }; |
125 |
135 |