185
189
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qaudiooutput.html#notify">notify</a></b> ()</td></tr>
186
190
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qaudiooutput.html#stateChanged">stateChanged</a></b> ( QAudio::State <i>state</i> )</td></tr>
193
<li class="fn">1 signal inherited from <a href="http://qt.nokia.com/doc/4.6/qobject.html#signals">QObject</a></li>
195
<h3>Additional Inherited Members</h3>
197
<li class="fn">1 property inherited from <a href="http://qt.nokia.com/doc/4.6/qobject.html#properties">QObject</a></li>
198
<li class="fn">1 public slot inherited from <a href="http://qt.nokia.com/doc/4.6/qobject.html#public-slots">QObject</a></li>
199
<li class="fn">1 public variable inherited from <a href="http://qt.nokia.com/doc/4.6/qobject.html#public-variables">QObject</a></li>
200
<li class="fn">4 static public members inherited from <a href="http://qt.nokia.com/doc/4.6/qobject.html#static-public-members">QObject</a></li>
201
<li class="fn">7 protected functions inherited from <a href="http://qt.nokia.com/doc/4.6/qobject.html#protected-functions">QObject</a></li>
202
<li class="fn">2 protected variables inherited from <a href="http://qt.nokia.com/doc/4.6/qobject.html#protected-variables">QObject</a></li>
188
204
<a name="details"></a>
190
206
<div class="descr"/>
192
208
<p>The QAudioOutput class provides an interface for sending audio data to an audio output device.</p>
193
209
<p>You can construct an audio output with the system's <a href="qaudiodeviceinfo.html#defaultOutputDevice">default audio output device</a>. It is also possible to create QAudioOutput with a specific <a href="qaudiodeviceinfo.html">QAudioDeviceInfo</a>. When you create the audio output, you should also send in the <a href="qaudioformat.html">QAudioFormat</a> to be used for the playback (see the <a href="qaudioformat.html">QAudioFormat</a> class description for details).</p>
194
210
<p>To play a file:</p>
195
<p>Starting to play an audio stream is simply a matter of calling <a href="qaudiooutput.html#start">start</a>() with a QIODevice. QAudioOutput will then fetch the data it needs from the io device. So playing back an audio file is as simple as:</p>
211
<p>Starting to play an audio stream is simply a matter of calling <a href="qaudiooutput.html#start">start</a>() with a <a href="http://qt.nokia.com/doc/4.6/qiodevice.html">QIODevice</a>. QAudioOutput will then fetch the data it needs from the io device. So playing back an audio file is as simple as:</p>
196
212
<pre class="highlightedCode brush: cpp"> QFile inputFile; <span class="comment">// class member.</span>
197
213
QAudioOutput* audio; <span class="comment">// class member.</span></pre>
198
214
<pre class="highlightedCode brush: cpp"> inputFile.setFileName("/tmp/test.raw");
229
245
<p>At any given time, the QAudioOutput will be in one of four states: active, suspended, stopped, or idle. These states are described by the <a href="qaudio.html#State-enum">QAudio::State</a> enum. State changes are reported through the <a href="qaudiooutput.html#stateChanged">stateChanged</a>() signal. You can use this signal to, for instance, update the GUI of the application; the mundane example here being changing the state of a <tt>play/pause</tt> button. You request a state change directly with <a href="qaudiooutput.html#suspend">suspend</a>(), <a href="qaudiooutput.html#stop">stop</a>(), <a href="qaudiooutput.html#reset">reset</a>(), <a href="qaudiooutput.html#resume">resume</a>(), and <a href="qaudiooutput.html#start">start</a>().</p>
230
<p>While the stream is playing, you can set a notify interval in milliseconds with <a href="qaudiooutput.html#setNotifyInterval">setNotifyInterval</a>(). This interval specifies the time between two emissions of the <a href="qaudiooutput.html#notify">notify</a>() signal. This is relative to the position in the stream, i.e., if the QAudioOutput is in the SuspendedState or the IdleState, the <a href="qaudiooutput.html#notify">notify</a>() signal is not emitted. A typical use-case would be to update a slider that allows seeking in the stream. If you want the time since playback started regardless of which states the audio output has been in, <a href="qaudiooutput.html#elapsedUSecs">elapsedUSecs</a>() is the function for you.</p>
246
<p>While the stream is playing, you can set a notify interval in milliseconds with <a href="qaudiooutput.html#setNotifyInterval">setNotifyInterval</a>(). This interval specifies the time between two emissions of the <a href="qaudiooutput.html#notify">notify</a>() signal. This is relative to the position in the stream, i.e., if the QAudioOutput is in the SuspendedState or the IdleState, the <a href="qaudiooutput.html#notify">notify</a>() signal is not emitted. A typical use-case would be to update a <a href="http://qt.nokia.com/doc/4.6/qslider.html">slider</a> that allows seeking in the stream. If you want the time since playback started regardless of which states the audio output has been in, <a href="qaudiooutput.html#elapsedUSecs">elapsedUSecs</a>() is the function for you.</p>
231
247
<p>If an error occurs, you can fetch the <a href="qaudio.html#Error-enum">error type</a> with the <a href="qaudiooutput.html#error">error</a>() function. Please see the <a href="qaudio.html#Error-enum">QAudio::Error</a> enum for a description of the possible errors that are reported. When an error is encountered, the state changes to <a href="qaudio.html#State-enum">QAudio::StoppedState</a>. You can check for errors by connecting to the <a href="qaudiooutput.html#stateChanged">stateChanged</a>() signal:</p>
232
248
<pre class="highlightedCode brush: cpp"> void stateChanged(QAudio::State newState)
245
261
<div class="func"/>
246
262
<h2>Member Function Documentation</h2>
247
<h3 class="fn"><a name="QAudioOutput"></a>QAudioOutput::QAudioOutput ( const <a href="qaudioformat.html">QAudioFormat</a> & <i>format</i> = QAudioFormat(), QObject * <i>parent</i> = 0 )</h3>
263
<h3 class="fn"><a name="QAudioOutput"></a>QAudioOutput::QAudioOutput ( const <a href="qaudioformat.html">QAudioFormat</a> & <i>format</i> = QAudioFormat(), <a href="http://qt.nokia.com/doc/4.6/qobject.html">QObject</a> * <i>parent</i> = 0 )</h3>
248
264
<p>Construct a new audio output and attach it to <i>parent</i>. The default audio output device is used with the output <i>format</i> parameters.</p>
249
<h3 class="fn"><a name="QAudioOutput-2"></a>QAudioOutput::QAudioOutput ( const <a href="qaudiodeviceinfo.html">QAudioDeviceInfo</a> & <i>audioDevice</i>, const <a href="qaudioformat.html">QAudioFormat</a> & <i>format</i> = QAudioFormat(), QObject * <i>parent</i> = 0 )</h3>
265
<h3 class="fn"><a name="QAudioOutput-2"></a>QAudioOutput::QAudioOutput ( const <a href="qaudiodeviceinfo.html">QAudioDeviceInfo</a> & <i>audioDevice</i>, const <a href="qaudioformat.html">QAudioFormat</a> & <i>format</i> = QAudioFormat(), <a href="http://qt.nokia.com/doc/4.6/qobject.html">QObject</a> * <i>parent</i> = 0 )</h3>
250
266
<p>Construct a new audio output and attach it to <i>parent</i>. The device referenced by <i>audioDevice</i> is used with the output <i>format</i> parameters.</p>
251
267
<h3 class="fn"><a name="dtor.QAudioOutput"></a>QAudioOutput::~QAudioOutput ()</h3>
252
268
<p>Destroys this audio output.</p>
256
272
<p>See also <a href="qaudiooutput.html#setBufferSize">setBufferSize</a>().</p>
257
273
<h3 class="fn"><a name="bytesFree"></a>int QAudioOutput::bytesFree () const</h3>
258
274
<p>Returns the free space available in bytes in the audio buffer.</p>
259
<p>NOTE: returned value is only valid while in <a href="qaudio.html#State-enum">QAudio::ActiveState</a> or <a href="qaudio.html#State-enum">QAudio::IdleState</a> state, otherwise returns zero.</p>
260
<h3 class="fn"><a name="elapsedUSecs"></a>qint64 QAudioOutput::elapsedUSecs () const</h3>
275
<p>NOTE: returned value is only valid while in <a href="http://qt.nokia.com/doc/4.6/qaudio.html#State-enum">QAudio::ActiveState</a> or <a href="http://qt.nokia.com/doc/4.6/qaudio.html#State-enum">QAudio::IdleState</a> state, otherwise returns zero.</p>
276
<h3 class="fn"><a name="elapsedUSecs"></a><a href="http://qt.nokia.com/doc/4.6/qtglobal.html#qint64-typedef">qint64</a> QAudioOutput::elapsedUSecs () const</h3>
261
277
<p>Returns the microseconds since <a href="qaudiooutput.html#start">start</a>() was called, including time in Idle and Suspend states.</p>
262
278
<h3 class="fn"><a name="error"></a><a href="qaudio.html#Error-enum">QAudio::Error</a> QAudioOutput::error () const</h3>
263
279
<p>Returns the error state.</p>
271
287
<h3 class="fn"><a name="periodSize"></a>int QAudioOutput::periodSize () const</h3>
272
288
<p>Returns the period size in bytes.</p>
273
289
<p>Note: This is the recommended write size in bytes.</p>
274
<h3 class="fn"><a name="processedUSecs"></a>qint64 QAudioOutput::processedUSecs () const</h3>
290
<h3 class="fn"><a name="processedUSecs"></a><a href="http://qt.nokia.com/doc/4.6/qtglobal.html#qint64-typedef">qint64</a> QAudioOutput::processedUSecs () const</h3>
275
291
<p>Returns the amount of audio data processed since <a href="qaudiooutput.html#start">start</a>() was called in microseconds.</p>
276
292
<h3 class="fn"><a name="reset"></a>void QAudioOutput::reset ()</h3>
277
293
<p>Drops all audio data in the buffers, resets buffers to zero.</p>
278
294
<h3 class="fn"><a name="resume"></a>void QAudioOutput::resume ()</h3>
279
295
<p>Resumes processing audio data after a <a href="qaudiooutput.html#suspend">suspend</a>().</p>
280
<p>Sets <a href="qaudiooutput.html#error">error</a>() to <a href="qaudio.html#Error-enum">QAudio::NoError</a>. Sets <a href="qaudiooutput.html#state">state</a>() to <a href="qaudio.html#State-enum">QAudio::ActiveState</a> if you previously called start(QIODevice*). Sets <a href="qaudiooutput.html#state">state</a>() to <a href="qaudio.html#State-enum">QAudio::IdleState</a> if you previously called <a href="qaudiooutput.html#start">start</a>(). emits <a href="qaudiooutput.html#stateChanged">stateChanged</a>() signal.</p>
296
<p>Sets <a href="qaudiooutput.html#error">error</a>() to <a href="http://qt.nokia.com/doc/4.6/qaudio.html#Error-enum">QAudio::NoError</a>. Sets <a href="qaudiooutput.html#state">state</a>() to <a href="http://qt.nokia.com/doc/4.6/qaudio.html#State-enum">QAudio::ActiveState</a> if you previously called start(<a href="http://qt.nokia.com/doc/4.6/qiodevice.html">QIODevice</a>*). Sets <a href="qaudiooutput.html#state">state</a>() to <a href="http://qt.nokia.com/doc/4.6/qaudio.html#State-enum">QAudio::IdleState</a> if you previously called <a href="qaudiooutput.html#start">start</a>(). emits <a href="qaudiooutput.html#stateChanged">stateChanged</a>() signal.</p>
281
297
<h3 class="fn"><a name="setBufferSize"></a>void QAudioOutput::setBufferSize ( int <i>value</i> )</h3>
282
298
<p>Sets the audio buffer size to <i>value</i> in bytes.</p>
283
299
<p>Note: This function can be called anytime before <a href="qaudiooutput.html#start">start</a>(), calls to this are ignored after <a href="qaudiooutput.html#start">start</a>(). It should not be assumed that the buffer size set is the actual buffer size used, calling <a href="qaudiooutput.html#bufferSize">bufferSize</a>() anytime after <a href="qaudiooutput.html#start">start</a>() will return the actual buffer size being used.</p>
285
301
<h3 class="fn"><a name="setNotifyInterval"></a>void QAudioOutput::setNotifyInterval ( int <i>ms</i> )</h3>
286
302
<p>Sets the interval for <a href="qaudiooutput.html#notify">notify</a>() signal to be emitted. This is based on the <i>ms</i> of audio data processed not on actual real-time. The minimum resolution of the timer is platform specific and values should be checked with <a href="qaudiooutput.html#notifyInterval">notifyInterval</a>() to confirm actual value being used.</p>
287
303
<p>See also <a href="qaudiooutput.html#notifyInterval">notifyInterval</a>().</p>
288
<h3 class="fn"><a name="start"></a>void QAudioOutput::start ( QIODevice * <i>device</i> )</h3>
289
<p>Uses the <i>device</i> as the QIODevice to transfer data. Passing a QIODevice allows the data to be transfered without any extra code. All that is required is to open the QIODevice.</p>
290
<p>If able to successfully output audio data to the systems audio device the <a href="qaudiooutput.html#state">state</a>() is set to <a href="qaudio.html#State-enum">QAudio::ActiveState</a>, <a href="qaudiooutput.html#error">error</a>() is set to <a href="qaudio.html#Error-enum">QAudio::NoError</a> and the <a href="qaudiooutput.html#stateChanged">stateChanged</a>() signal is emitted.</p>
291
<p>If a problem occurs during this process the <a href="qaudiooutput.html#error">error</a>() is set to <a href="qaudio.html#Error-enum">QAudio::OpenError</a>, <a href="qaudiooutput.html#state">state</a>() is set to <a href="qaudio.html#State-enum">QAudio::StoppedState</a> and <a href="qaudiooutput.html#stateChanged">stateChanged</a>() signal is emitted.</p>
292
<p>See also QIODevice.</p>
293
<h3 class="fn"><a name="start-2"></a>QIODevice * QAudioOutput::start ()</h3>
294
<p>Returns a pointer to the QIODevice being used to handle the data transfer. This QIODevice can be used to write() audio data directly.</p>
295
<p>If able to access the systems audio device the <a href="qaudiooutput.html#state">state</a>() is set to <a href="qaudio.html#State-enum">QAudio::IdleState</a>, <a href="qaudiooutput.html#error">error</a>() is set to <a href="qaudio.html#Error-enum">QAudio::NoError</a> and the <a href="qaudiooutput.html#stateChanged">stateChanged</a>() signal is emitted.</p>
296
<p>If a problem occurs during this process the <a href="qaudiooutput.html#error">error</a>() is set to <a href="qaudio.html#Error-enum">QAudio::OpenError</a>, <a href="qaudiooutput.html#state">state</a>() is set to <a href="qaudio.html#State-enum">QAudio::StoppedState</a> and <a href="qaudiooutput.html#stateChanged">stateChanged</a>() signal is emitted.</p>
297
<p>See also QIODevice.</p>
304
<h3 class="fn"><a name="start"></a>void QAudioOutput::start ( <a href="http://qt.nokia.com/doc/4.6/qiodevice.html">QIODevice</a> * <i>device</i> )</h3>
305
<p>Uses the <i>device</i> as the <a href="http://qt.nokia.com/doc/4.6/qiodevice.html">QIODevice</a> to transfer data. Passing a <a href="http://qt.nokia.com/doc/4.6/qiodevice.html">QIODevice</a> allows the data to be transfered without any extra code. All that is required is to open the <a href="http://qt.nokia.com/doc/4.6/qiodevice.html">QIODevice</a>.</p>
306
<p>If able to successfully output audio data to the systems audio device the <a href="qaudiooutput.html#state">state</a>() is set to <a href="http://qt.nokia.com/doc/4.6/qaudio.html#State-enum">QAudio::ActiveState</a>, <a href="qaudiooutput.html#error">error</a>() is set to <a href="http://qt.nokia.com/doc/4.6/qaudio.html#Error-enum">QAudio::NoError</a> and the <a href="qaudiooutput.html#stateChanged">stateChanged</a>() signal is emitted.</p>
307
<p>If a problem occurs during this process the <a href="qaudiooutput.html#error">error</a>() is set to <a href="http://qt.nokia.com/doc/4.6/qaudio.html#Error-enum">QAudio::OpenError</a>, <a href="qaudiooutput.html#state">state</a>() is set to <a href="qaudio.html#State-enum">QAudio::StoppedState</a> and <a href="qaudiooutput.html#stateChanged">stateChanged</a>() signal is emitted.</p>
308
<p>See also <a href="http://qt.nokia.com/doc/4.6/qiodevice.html">QIODevice</a>.</p>
309
<h3 class="fn"><a name="start-2"></a><a href="http://qt.nokia.com/doc/4.6/qiodevice.html">QIODevice</a> * QAudioOutput::start ()</h3>
310
<p>Returns a pointer to the <a href="http://qt.nokia.com/doc/4.6/qiodevice.html">QIODevice</a> being used to handle the data transfer. This <a href="http://qt.nokia.com/doc/4.6/qiodevice.html">QIODevice</a> can be used to write() audio data directly.</p>
311
<p>If able to access the systems audio device the <a href="qaudiooutput.html#state">state</a>() is set to <a href="http://qt.nokia.com/doc/4.6/qaudio.html#State-enum">QAudio::IdleState</a>, <a href="qaudiooutput.html#error">error</a>() is set to <a href="http://qt.nokia.com/doc/4.6/qaudio.html#Error-enum">QAudio::NoError</a> and the <a href="qaudiooutput.html#stateChanged">stateChanged</a>() signal is emitted.</p>
312
<p>If a problem occurs during this process the <a href="qaudiooutput.html#error">error</a>() is set to <a href="http://qt.nokia.com/doc/4.6/qaudio.html#Error-enum">QAudio::OpenError</a>, <a href="qaudiooutput.html#state">state</a>() is set to <a href="qaudio.html#State-enum">QAudio::StoppedState</a> and <a href="qaudiooutput.html#stateChanged">stateChanged</a>() signal is emitted.</p>
313
<p>See also <a href="http://qt.nokia.com/doc/4.6/qiodevice.html">QIODevice</a>.</p>
298
314
<h3 class="fn"><a name="state"></a><a href="qaudio.html#State-enum">QAudio::State</a> QAudioOutput::state () const</h3>
299
315
<p>Returns the state of audio processing.</p>
300
316
<h3 class="fn"><a name="stateChanged"></a>void QAudioOutput::stateChanged ( <a href="qaudio.html#State-enum">QAudio::State</a> <i>state</i> )<tt> [signal]</tt></h3>
301
317
<p>This signal is emitted when the device <i>state</i> has changed. This is the current state of the audio output.</p>
302
318
<h3 class="fn"><a name="stop"></a>void QAudioOutput::stop ()</h3>
303
319
<p>Stops the audio output, detaching from the system resource.</p>
304
<p>Sets <a href="qaudiooutput.html#error">error</a>() to <a href="qaudio.html#Error-enum">QAudio::NoError</a>, <a href="qaudiooutput.html#state">state</a>() to <a href="qaudio.html#State-enum">QAudio::StoppedState</a> and emit <a href="qaudiooutput.html#stateChanged">stateChanged</a>() signal.</p>
320
<p>Sets <a href="qaudiooutput.html#error">error</a>() to <a href="http://qt.nokia.com/doc/4.6/qaudio.html#Error-enum">QAudio::NoError</a>, <a href="qaudiooutput.html#state">state</a>() to <a href="qaudio.html#State-enum">QAudio::StoppedState</a> and emit <a href="qaudiooutput.html#stateChanged">stateChanged</a>() signal.</p>
305
321
<h3 class="fn"><a name="suspend"></a>void QAudioOutput::suspend ()</h3>
306
322
<p>Stops processing audio data, preserving buffered audio data.</p>
307
<p>Sets <a href="qaudiooutput.html#error">error</a>() to <a href="qaudio.html#Error-enum">QAudio::NoError</a>, <a href="qaudiooutput.html#state">state</a>() to <a href="qaudio.html#State-enum">QAudio::SuspendedState</a> and emit <a href="qaudiooutput.html#stateChanged">stateChanged</a>() signal.</p>
323
<p>Sets <a href="qaudiooutput.html#error">error</a>() to <a href="http://qt.nokia.com/doc/4.6/qaudio.html#Error-enum">QAudio::NoError</a>, <a href="qaudiooutput.html#state">state</a>() to <a href="qaudio.html#State-enum">QAudio::SuspendedState</a> and emit <a href="qaudiooutput.html#stateChanged">stateChanged</a>() signal.</p>
310
326
<div class="feedback t_button">