93 format.setSampleSize(8); |
93 format.setSampleSize(8); |
94 format.setCodec("audio/pcm"); |
94 format.setCodec("audio/pcm"); |
95 format.setByteOrder(QAudioFormat::LittleEndian); |
95 format.setByteOrder(QAudioFormat::LittleEndian); |
96 format.setSampleType(QAudioFormat::UnSignedInt); |
96 format.setSampleType(QAudioFormat::UnSignedInt); |
97 |
97 |
98 if (QAudioDeviceInfo info(QAudioDeviceInfo::defaultInputDevice()); |
98 QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice(); |
99 if (!info.isFormatSupported(format)) { |
99 if (!info.isFormatSupported(format)) { |
100 qWarning()<<"default format not supported try to use nearest"; |
100 qWarning()<<"default format not supported try to use nearest"; |
101 format = info.nearestFormat(format); |
101 format = info.nearestFormat(format); |
102 } |
102 } |
103 |
103 |
188 /*! |
188 /*! |
189 Uses the \a device as the QIODevice to transfer data. |
189 Uses the \a device as the QIODevice to transfer data. |
190 Passing a QIODevice allows the data to be transfered without any extra code. |
190 Passing a QIODevice allows the data to be transfered without any extra code. |
191 All that is required is to open the QIODevice. |
191 All that is required is to open the QIODevice. |
192 |
192 |
|
193 If able to successfully get audio data from the systems audio device the |
|
194 state() is set to either QAudio::ActiveState or QAudio::IdleState, |
|
195 error() is set to QAudio::NoError and the stateChanged() signal is emitted. |
|
196 |
|
197 If a problem occurs during this process the error() is set to QAudio::OpenError, |
|
198 state() is set to QAudio::StoppedState and stateChanged() signal is emitted. |
|
199 |
193 \sa QIODevice |
200 \sa QIODevice |
194 */ |
201 */ |
195 |
202 |
196 void QAudioInput::start(QIODevice* device) |
203 void QAudioInput::start(QIODevice* device) |
197 { |
204 { |
198 /* |
|
199 -If currently not StoppedState, stop |
|
200 -If previous start was push mode, delete internal QIODevice. |
|
201 -open audio input. |
|
202 If ok, NoError and ActiveState, else OpenError and StoppedState. |
|
203 -emit stateChanged() |
|
204 */ |
|
205 d->start(device); |
205 d->start(device); |
206 } |
206 } |
207 |
207 |
208 /*! |
208 /*! |
209 Returns a pointer to the QIODevice being used to handle the data |
209 Returns a pointer to the QIODevice being used to handle the data |
210 transfer. This QIODevice can be used to read() audio data |
210 transfer. This QIODevice can be used to read() audio data |
211 directly. |
211 directly. |
212 |
212 |
|
213 If able to access the systems audio device the state() is set to |
|
214 QAudio::IdleState, error() is set to QAudio::NoError |
|
215 and the stateChanged() signal is emitted. |
|
216 |
|
217 If a problem occurs during this process the error() is set to QAudio::OpenError, |
|
218 state() is set to QAudio::StoppedState and stateChanged() signal is emitted. |
|
219 |
213 \sa QIODevice |
220 \sa QIODevice |
214 */ |
221 */ |
215 |
222 |
216 QIODevice* QAudioInput::start() |
223 QIODevice* QAudioInput::start() |
217 { |
224 { |
218 /* |
|
219 -If currently not StoppedState, stop |
|
220 -If no internal QIODevice, create one. |
|
221 -open audio input. |
|
222 -If ok, NoError and IdleState, else OpenError and StoppedState |
|
223 -emit stateChanged() |
|
224 -return internal QIODevice |
|
225 */ |
|
226 return d->start(0); |
225 return d->start(0); |
227 } |
226 } |
228 |
227 |
229 /*! |
228 /*! |
230 Returns the QAudioFormat being used. |
229 Returns the QAudioFormat being used. |
234 { |
233 { |
235 return d->format(); |
234 return d->format(); |
236 } |
235 } |
237 |
236 |
238 /*! |
237 /*! |
239 Stops the audio input. |
238 Stops the audio input, detaching from the system resource. |
|
239 |
|
240 Sets error() to QAudio::NoError, state() to QAudio::StoppedState and |
|
241 emit stateChanged() signal. |
240 */ |
242 */ |
241 |
243 |
242 void QAudioInput::stop() |
244 void QAudioInput::stop() |
243 { |
245 { |
244 /* |
|
245 -If StoppedState, return |
|
246 -set to StoppedState |
|
247 -detach from audio device |
|
248 -emit stateChanged() |
|
249 */ |
|
250 d->stop(); |
246 d->stop(); |
251 } |
247 } |
252 |
248 |
253 /*! |
249 /*! |
254 Drops all audio data in the buffers, resets buffers to zero. |
250 Drops all audio data in the buffers, resets buffers to zero. |
255 */ |
251 */ |
256 |
252 |
257 void QAudioInput::reset() |
253 void QAudioInput::reset() |
258 { |
254 { |
259 /* |
|
260 -drop all buffered audio, set buffers to zero. |
|
261 -call stop() |
|
262 */ |
|
263 d->reset(); |
255 d->reset(); |
264 } |
256 } |
265 |
257 |
266 /*! |
258 /*! |
267 Stops processing audio data, preserving buffered audio data. |
259 Stops processing audio data, preserving buffered audio data. |
|
260 |
|
261 Sets error() to QAudio::NoError, state() to QAudio::SuspendedState and |
|
262 emit stateChanged() signal. |
268 */ |
263 */ |
269 |
264 |
270 void QAudioInput::suspend() |
265 void QAudioInput::suspend() |
271 { |
266 { |
272 /* |
|
273 -If not ActiveState|IdleState, return |
|
274 -stop processing audio, saving all buffered audio data |
|
275 -set NoError and SuspendedState |
|
276 -emit stateChanged() |
|
277 */ |
|
278 d->suspend(); |
267 d->suspend(); |
279 } |
268 } |
280 |
269 |
281 /*! |
270 /*! |
282 Resumes processing audio data after a suspend(). |
271 Resumes processing audio data after a suspend(). |
|
272 |
|
273 Sets error() to QAudio::NoError. |
|
274 Sets state() to QAudio::ActiveState if you previously called start(QIODevice*). |
|
275 Sets state() to QAudio::IdleState if you previously called start(). |
|
276 emits stateChanged() signal. |
283 */ |
277 */ |
284 |
278 |
285 void QAudioInput::resume() |
279 void QAudioInput::resume() |
286 { |
280 { |
287 /* |
|
288 -If SuspendedState, return |
|
289 -resume audio |
|
290 -(PULL MODE): set ActiveState, NoError |
|
291 -(PUSH MODE): set IdleState, NoError |
|
292 -kick start audio if needed |
|
293 -emit stateChanged() |
|
294 */ |
|
295 d->resume(); |
281 d->resume(); |
296 } |
282 } |
297 |
283 |
298 /*! |
284 /*! |
299 Sets the audio buffer size to \a value milliseconds. |
285 Sets the audio buffer size to \a value milliseconds. |
350 } |
339 } |
351 |
340 |
352 /*! |
341 /*! |
353 Sets the interval for notify() signal to be emitted. |
342 Sets the interval for notify() signal to be emitted. |
354 This is based on the \a ms of audio data processed |
343 This is based on the \a ms of audio data processed |
355 not on actual real-time. The resolution of the timer is platform specific. |
344 not on actual real-time. |
|
345 The minimum resolution of the timer is platform specific and values |
|
346 should be checked with notifyInterval() to confirm actual value |
|
347 being used. |
356 */ |
348 */ |
357 |
349 |
358 void QAudioInput::setNotifyInterval(int ms) |
350 void QAudioInput::setNotifyInterval(int ms) |
359 { |
351 { |
360 d->setNotifyInterval(ms); |
352 d->setNotifyInterval(ms); |