1 /**************************************************************************** |
1 /**************************************************************************** |
2 ** |
2 ** |
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
4 ** All rights reserved. |
4 ** All rights reserved. |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
6 ** |
6 ** |
7 ** This file is part of the examples of the Qt Toolkit. |
7 ** This file is part of the examples of the Qt Toolkit. |
8 ** |
8 ** |
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 |
100 QAudioDeviceInfo device; |
101 private: |
101 QAudioFormat format; |
102 void initializeWindow(); |
102 QAudioInput* audioInput; |
103 void initializeAudio(); |
103 AudioInfo* audioinfo; |
104 void createAudioInput(); |
104 QIODevice* input; |
|
105 RenderArea* canvas; |
|
106 |
|
107 bool pullMode; |
|
108 |
|
109 QPushButton* button; |
|
110 QPushButton* button2; |
|
111 QComboBox* deviceBox; |
|
112 |
|
113 char* buffer; |
|
114 |
105 |
115 private slots: |
106 private slots: |
116 void refreshDisplay(); |
107 void refreshDisplay(); |
117 void status(); |
108 void notified(); |
118 void readMore(); |
109 void readMore(); |
119 void toggleMode(); |
110 void toggleMode(); |
120 void toggleSuspend(); |
111 void toggleSuspend(); |
121 void state(QAudio::State s); |
112 void stateChanged(QAudio::State state); |
122 void deviceChanged(int idx); |
113 void deviceChanged(int index); |
|
114 |
|
115 private: |
|
116 // Owned by layout |
|
117 RenderArea *m_canvas; |
|
118 QPushButton *m_modeButton; |
|
119 QPushButton *m_suspendResumeButton; |
|
120 QComboBox *m_deviceBox; |
|
121 |
|
122 AudioInfo *m_audioInfo; |
|
123 QAudioDeviceInfo m_device; |
|
124 QAudioFormat m_format; |
|
125 QAudioInput *m_audioInput; |
|
126 QIODevice *m_input; |
|
127 bool m_pullMode; |
|
128 QByteArray m_buffer; |
|
129 |
|
130 static const QString PushModeLabel; |
|
131 static const QString PullModeLabel; |
|
132 static const QString SuspendLabel; |
|
133 static const QString ResumeLabel; |
123 }; |
134 }; |
124 |
135 |