168 |
168 |
169 canvas = new RenderArea; |
169 canvas = new RenderArea; |
170 layout->addWidget(canvas); |
170 layout->addWidget(canvas); |
171 |
171 |
172 deviceBox = new QComboBox(this); |
172 deviceBox = new QComboBox(this); |
173 QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::deviceList(QAudio::AudioInput); |
173 QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioInput); |
174 for(int i = 0; i < devices.size(); ++i) { |
174 for(int i = 0; i < devices.size(); ++i) { |
175 deviceBox->addItem(devices.at(i).deviceName(), qVariantFromValue(devices.at(i))); |
175 deviceBox->addItem(devices.at(i).deviceName(), qVariantFromValue(devices.at(i))); |
176 } |
176 } |
177 connect(deviceBox,SIGNAL(activated(int)),SLOT(deviceChanged(int))); |
177 connect(deviceBox,SIGNAL(activated(int)),SLOT(deviceChanged(int))); |
178 layout->addWidget(deviceBox); |
178 layout->addWidget(deviceBox); |
193 |
193 |
194 buffer = new char[BUFFER_SIZE]; |
194 buffer = new char[BUFFER_SIZE]; |
195 |
195 |
196 pullMode = true; |
196 pullMode = true; |
197 |
197 |
198 // AudioInfo class only supports mono S16LE samples! |
|
199 format.setFrequency(8000); |
198 format.setFrequency(8000); |
200 format.setChannels(1); |
199 format.setChannels(1); |
201 format.setSampleSize(16); |
200 format.setSampleSize(16); |
202 format.setSampleType(QAudioFormat::SignedInt); |
201 format.setSampleType(QAudioFormat::SignedInt); |
203 format.setByteOrder(QAudioFormat::LittleEndian); |
202 format.setByteOrder(QAudioFormat::LittleEndian); |
204 format.setCodec("audio/pcm"); |
203 format.setCodec("audio/pcm"); |
|
204 |
|
205 QAudioDeviceInfo info(QAudioDeviceInfo::defaultInputDevice()); |
|
206 if (!info.isFormatSupported(format)) { |
|
207 qWarning()<<"default format not supported try to use nearest"; |
|
208 format = info.nearestFormat(format); |
|
209 } |
|
210 |
|
211 if(format.sampleSize() != 16) { |
|
212 qWarning()<<"audio device doesn't support 16 bit samples, example cannot run"; |
|
213 return; |
|
214 } |
205 |
215 |
206 audioInput = new QAudioInput(format,this); |
216 audioInput = new QAudioInput(format,this); |
207 connect(audioInput,SIGNAL(notify()),SLOT(status())); |
217 connect(audioInput,SIGNAL(notify()),SLOT(status())); |
208 connect(audioInput,SIGNAL(stateChanged(QAudio::State)),SLOT(state(QAudio::State))); |
218 connect(audioInput,SIGNAL(stateChanged(QAudio::State)),SLOT(state(QAudio::State))); |
209 audioinfo = new AudioInfo(this,audioInput); |
219 audioinfo = new AudioInfo(this,audioInput); |
214 |
224 |
215 InputTest::~InputTest() {} |
225 InputTest::~InputTest() {} |
216 |
226 |
217 void InputTest::status() |
227 void InputTest::status() |
218 { |
228 { |
219 qWarning()<<"bytesReady = "<<audioInput->bytesReady()<<" bytes, clock = "<<audioInput->clock()/1000<<"ms, totalTime = "<<audioInput->totalTime()/1000<<"ms"; |
229 qWarning()<<"bytesReady = "<<audioInput->bytesReady()<<" bytes, elapsedUSecs = "<<audioInput->elapsedUSecs()<<", processedUSecs = "<<audioInput->processedUSecs(); |
220 } |
230 } |
221 |
231 |
222 void InputTest::readMore() |
232 void InputTest::readMore() |
223 { |
233 { |
224 if(!audioInput) |
234 if(!audioInput) |
237 // Change bewteen pull and push modes |
247 // Change bewteen pull and push modes |
238 audioInput->stop(); |
248 audioInput->stop(); |
239 |
249 |
240 if (pullMode) { |
250 if (pullMode) { |
241 button->setText(tr("Click for Pull Mode")); |
251 button->setText(tr("Click for Pull Mode")); |
242 input = audioInput->start(0); |
252 input = audioInput->start(); |
243 connect(input,SIGNAL(readyRead()),SLOT(readMore())); |
253 connect(input,SIGNAL(readyRead()),SLOT(readMore())); |
244 pullMode = false; |
254 pullMode = false; |
245 } else { |
255 } else { |
246 button->setText(tr("Click for Push Mode")); |
256 button->setText(tr("Click for Push Mode")); |
247 pullMode = true; |
257 pullMode = true; |
250 } |
260 } |
251 |
261 |
252 void InputTest::toggleSuspend() |
262 void InputTest::toggleSuspend() |
253 { |
263 { |
254 // toggle suspend/resume |
264 // toggle suspend/resume |
255 if(audioInput->state() == QAudio::SuspendState) { |
265 if(audioInput->state() == QAudio::SuspendedState) { |
256 qWarning()<<"status: Suspended, resume()"; |
266 qWarning()<<"status: Suspended, resume()"; |
257 audioInput->resume(); |
267 audioInput->resume(); |
258 button2->setText("Click To Suspend"); |
268 button2->setText("Click To Suspend"); |
259 } else if (audioInput->state() == QAudio::ActiveState) { |
269 } else if (audioInput->state() == QAudio::ActiveState) { |
260 qWarning()<<"status: Active, suspend()"; |
270 qWarning()<<"status: Active, suspend()"; |
261 audioInput->suspend(); |
271 audioInput->suspend(); |
262 button2->setText("Click To Resume"); |
272 button2->setText("Click To Resume"); |
263 } else if (audioInput->state() == QAudio::StopState) { |
273 } else if (audioInput->state() == QAudio::StoppedState) { |
264 qWarning()<<"status: Stopped, resume()"; |
274 qWarning()<<"status: Stopped, resume()"; |
265 audioInput->resume(); |
275 audioInput->resume(); |
266 button2->setText("Click To Suspend"); |
276 button2->setText("Click To Suspend"); |
267 } else if (audioInput->state() == QAudio::IdleState) { |
277 } else if (audioInput->state() == QAudio::IdleState) { |
268 qWarning()<<"status: IdleState"; |
278 qWarning()<<"status: IdleState"; |