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 ** |
210 audioOutput->start(gen); |
210 audioOutput->start(gen); |
211 } |
211 } |
212 |
212 |
213 void AudioTest::status() |
213 void AudioTest::status() |
214 { |
214 { |
215 qWarning()<<"byteFree = "<<audioOutput->bytesFree()<<" bytes, elapsedUSecs = "<<audioOutput->elapsedUSecs()<<", processedUSecs = "<<audioOutput->processedUSecs(); |
215 qWarning() << "byteFree = " << audioOutput->bytesFree() << " bytes, elapsedUSecs = " << audioOutput->elapsedUSecs() << ", processedUSecs = " << audioOutput->processedUSecs(); |
216 } |
216 } |
217 |
217 |
218 void AudioTest::writeMore() |
218 void AudioTest::writeMore() |
219 { |
219 { |
220 if(!audioOutput) |
220 if (!audioOutput) |
221 return; |
221 return; |
222 |
222 |
223 if(audioOutput->state() == QAudio::StoppedState) |
223 if (audioOutput->state() == QAudio::StoppedState) |
224 return; |
224 return; |
225 |
225 |
226 int l; |
226 int l; |
227 int out; |
227 int out; |
228 |
228 |
229 int chunks = audioOutput->bytesFree()/audioOutput->periodSize(); |
229 int chunks = audioOutput->bytesFree()/audioOutput->periodSize(); |
230 while(chunks) { |
230 while(chunks) { |
231 l = gen->read(buffer,audioOutput->periodSize()); |
231 l = gen->read(buffer,audioOutput->periodSize()); |
232 if(l > 0) |
232 if (l > 0) |
233 out = output->write(buffer,l); |
233 out = output->write(buffer,l); |
234 if(l != audioOutput->periodSize()) |
234 if (l != audioOutput->periodSize()) |
235 break; |
235 break; |
236 chunks--; |
236 chunks--; |
237 } |
237 } |
238 } |
238 } |
239 |
239 |
257 } |
257 } |
258 |
258 |
259 void AudioTest::togglePlay() |
259 void AudioTest::togglePlay() |
260 { |
260 { |
261 // toggle suspend/resume |
261 // toggle suspend/resume |
262 if(audioOutput->state() == QAudio::SuspendedState) { |
262 if (audioOutput->state() == QAudio::SuspendedState) { |
263 qWarning()<<"status: Suspended, resume()"; |
263 qWarning() << "status: Suspended, resume()"; |
264 audioOutput->resume(); |
264 audioOutput->resume(); |
265 button2->setText("Click To Suspend"); |
265 button2->setText("Click To Suspend"); |
266 } else if (audioOutput->state() == QAudio::ActiveState) { |
266 } else if (audioOutput->state() == QAudio::ActiveState) { |
267 qWarning()<<"status: Active, suspend()"; |
267 qWarning() << "status: Active, suspend()"; |
268 audioOutput->suspend(); |
268 audioOutput->suspend(); |
269 button2->setText("Click To Resume"); |
269 button2->setText("Click To Resume"); |
270 } else if (audioOutput->state() == QAudio::StoppedState) { |
270 } else if (audioOutput->state() == QAudio::StoppedState) { |
271 qWarning()<<"status: Stopped, resume()"; |
271 qWarning() << "status: Stopped, resume()"; |
272 audioOutput->resume(); |
272 audioOutput->resume(); |
273 button2->setText("Click To Suspend"); |
273 button2->setText("Click To Suspend"); |
274 } else if (audioOutput->state() == QAudio::IdleState) { |
274 } else if (audioOutput->state() == QAudio::IdleState) { |
275 qWarning()<<"status: IdleState"; |
275 qWarning() << "status: IdleState"; |
276 } |
276 } |
277 } |
277 } |
278 |
278 |
279 void AudioTest::state(QAudio::State state) |
279 void AudioTest::state(QAudio::State state) |
280 { |
280 { |
281 qWarning()<<" state="<<state; |
281 qWarning() << " state=" << state; |
282 } |
282 } |