Symbian3/SDK/Source/GUID-ECBA6331-2187-52C9-A5DF-20CD1EEFE781.dita
changeset 8 ae94777fff8f
parent 7 51a74ef9ed63
child 13 48780e181b38
equal deleted inserted replaced
7:51a74ef9ed63 8:ae94777fff8f
     7     Nokia Corporation - initial contribution.
     7     Nokia Corporation - initial contribution.
     8 Contributors: 
     8 Contributors: 
     9 -->
     9 -->
    10 <!DOCTYPE concept
    10 <!DOCTYPE concept
    11   PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
    11   PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
    12 <concept xml:lang="en" id="GUID-ECBA6331-2187-52C9-A5DF-20CD1EEFE781"><title>Audio Output Streaming Tutorial</title><prolog><metadata><keywords/></metadata></prolog><conbody><p>This tutorial describes how to use Audio Output Streaming. </p> <section><title>Purpose</title> <p>The purpose of this tutorial is to show you how to open, play and then close an audio output stream. </p> <p><b>Required Background</b> </p> <p>The user needs to maintain the data packets in a queue before starting to send it to the server. There is no need for the entire sound clip to arrive to be able to pass on to the low level audio controller. They can be forwarded as they arrive. If the server tends to receive data more than it can read or process, then a separate queue is maintained in the client side whose elements are references to the buffers passed to it. Once the server is free to receive more data the client sends the data in the queue and receives a notification from the server by means of a callback. As a result of this, the client deletes the data fragments from the queue. </p> <p>Upon receiving the data packets the audio controller maintains them in the received buffers. A read function is instantiated to read the data into the destination descriptors. </p> <p><b>Introduction</b> </p> <p>The Audio streaming API is the interface providing the functionalities for playing, stopping, and recording the audio stream to and from the audio buffers. The audio output stream interface class, <xref href="GUID-B87C8F92-9737-3636-9800-BA267A1DCA6D.dita"><apiname>CMdaAudioOutputStream</apiname></xref>, enables client applications to: </p> <ul><li id="GUID-542B9854-AF72-5A00-B05C-AF7DE8C56916"><p>Stream raw audio data from specified buffers to audio devices. </p> </li> <li id="GUID-C4F56B32-661A-5160-AE11-C11BCCDA856E"><p>Specify the priority of the audio stream relative to other clients trying to use the same hardware. </p> </li> <li id="GUID-40790849-788F-56A1-8116-90AA755698DE"><p>Set the sample rate and the number of audio channels before playback. </p> </li> <li id="GUID-3664365E-FB62-5EB6-B396-B83655ECC49C"><p>Adjust the volume and channel balance during playback. </p> </li> </ul> </section> <section><title>Using Audio Output Streaming </title> <p>Typically, using an audio output stream involves the following steps as shown in the sequence diagram below: </p> <fig id="GUID-2D2AAE41-55E6-5BB6-B572-0A8C8015054C"><image href="GUID-534C1D1A-9450-5A1B-933F-5157039BF069_d0e315546_href.png" placement="inline"/></fig> <p>The following tasks will be covered in this tutorial: </p> <ul><li id="GUID-C498F32D-D466-5C10-893D-71B8168E6C1D"><p><xref href="GUID-ECBA6331-2187-52C9-A5DF-20CD1EEFE781.dita#GUID-ECBA6331-2187-52C9-A5DF-20CD1EEFE781/GUID-7435C237-DB6C-516E-BB4D-C31BF96470B0"> Constructing an audio output stream</xref>  </p> </li> <li id="GUID-F66078F3-9125-5277-BEAF-2740869354ED"><p><xref href="GUID-ECBA6331-2187-52C9-A5DF-20CD1EEFE781.dita#GUID-ECBA6331-2187-52C9-A5DF-20CD1EEFE781/GUID-A48822BE-E726-5892-A83D-CDD224C27EA0"> Opening an audio output stream</xref>  </p> </li> <li id="GUID-F3A82F27-5406-5937-BC5E-E83D9C7A6F6B"><p><xref href="GUID-ECBA6331-2187-52C9-A5DF-20CD1EEFE781.dita#GUID-ECBA6331-2187-52C9-A5DF-20CD1EEFE781/GUID-E21EE5D7-42ED-5D7C-AB8F-000D6BBE88A9">Getting and setting the stream properties</xref>  </p> </li> <li id="GUID-5F166776-8C9C-5C00-8A39-E77C9157DF59"><p><xref href="GUID-ECBA6331-2187-52C9-A5DF-20CD1EEFE781.dita#GUID-ECBA6331-2187-52C9-A5DF-20CD1EEFE781/GUID-CD886111-BE51-523D-A782-FA35A3889A0B"> Playing an audio output stream</xref>  </p> </li> <li id="GUID-7F60C260-A0B3-51C7-A1B1-4BE5A3F7E03A"><p><xref href="GUID-ECBA6331-2187-52C9-A5DF-20CD1EEFE781.dita#GUID-ECBA6331-2187-52C9-A5DF-20CD1EEFE781/GUID-B18F568C-E82B-5D46-A225-96816258E8AB">Stopping an audio output stream</xref>  </p> </li> </ul> <p id="GUID-7435C237-DB6C-516E-BB4D-C31BF96470B0"><b>Basic Procedure for Constructing an Audio Output Stream</b> </p> <p>The high level step to construct an audio output stream is shown here: </p> <ul><li id="GUID-8314E401-E900-587A-A7DD-2899214AB883"><p>The client application creates an audio output stream object using the static function <xref href="GUID-B87C8F92-9737-3636-9800-BA267A1DCA6D.dita#GUID-B87C8F92-9737-3636-9800-BA267A1DCA6D/GUID-B4D44672-C628-304A-B36E-8AF0ACAA8A80"><apiname>CMdaAudioOutputStream::NewL()</apiname></xref>. Optionally, it also sets the audio priorities to be able to access the audio hardware in relation to the other clients trying to access the same device. </p> <codeblock id="GUID-ACD5FF96-44F1-5DC8-8A89-CD3C193EAACE" xml:space="preserve">static IMPORT_C CMdaAudioOutputStream *NewL(MMdaAudioOutputStreamCallback &amp;aCallBack, 
    12 <concept xml:lang="en" id="GUID-ECBA6331-2187-52C9-A5DF-20CD1EEFE781"><title>Audio Output Streaming Tutorial</title><prolog><metadata><keywords/></metadata></prolog><conbody><p>This tutorial describes how to use Audio Output Streaming. </p> <section><title>Purpose</title> <p>The purpose of this tutorial is to show you how to open, play and then close an audio output stream. </p> <p><b>Required Background</b> </p> <p>The user needs to maintain the data packets in a queue before starting to send it to the server. There is no need for the entire sound clip to arrive to be able to pass on to the low level audio controller. They can be forwarded as they arrive. If the server tends to receive data more than it can read or process, then a separate queue is maintained in the client side whose elements are references to the buffers passed to it. Once the server is free to receive more data the client sends the data in the queue and receives a notification from the server by means of a callback. As a result of this, the client deletes the data fragments from the queue. </p> <p>Upon receiving the data packets the audio controller maintains them in the received buffers. A read function is instantiated to read the data into the destination descriptors. </p> <p><b>Introduction</b> </p> <p>The Audio streaming API is the interface providing the functionalities for playing, stopping, and recording the audio stream to and from the audio buffers. The audio output stream interface class, <xref href="GUID-B87C8F92-9737-3636-9800-BA267A1DCA6D.dita"><apiname>CMdaAudioOutputStream</apiname></xref>, enables client applications to: </p> <ul><li id="GUID-542B9854-AF72-5A00-B05C-AF7DE8C56916"><p>Stream raw audio data from specified buffers to audio devices. </p> </li> <li id="GUID-C4F56B32-661A-5160-AE11-C11BCCDA856E"><p>Specify the priority of the audio stream relative to other clients trying to use the same hardware. </p> </li> <li id="GUID-40790849-788F-56A1-8116-90AA755698DE"><p>Set the sample rate and the number of audio channels before playback. </p> </li> <li id="GUID-3664365E-FB62-5EB6-B396-B83655ECC49C"><p>Adjust the volume and channel balance during playback. </p> </li> </ul> </section> <section><title>Using Audio Output Streaming </title> <p>Typically, using an audio output stream involves the following steps as shown in the sequence diagram below: </p> <fig id="GUID-2D2AAE41-55E6-5BB6-B572-0A8C8015054C"><image href="GUID-534C1D1A-9450-5A1B-933F-5157039BF069_d0e309152_href.png" placement="inline"/></fig> <p>The following tasks will be covered in this tutorial: </p> <ul><li id="GUID-C498F32D-D466-5C10-893D-71B8168E6C1D"><p><xref href="GUID-ECBA6331-2187-52C9-A5DF-20CD1EEFE781.dita#GUID-ECBA6331-2187-52C9-A5DF-20CD1EEFE781/GUID-7435C237-DB6C-516E-BB4D-C31BF96470B0"> Constructing an audio output stream</xref>  </p> </li> <li id="GUID-F66078F3-9125-5277-BEAF-2740869354ED"><p><xref href="GUID-ECBA6331-2187-52C9-A5DF-20CD1EEFE781.dita#GUID-ECBA6331-2187-52C9-A5DF-20CD1EEFE781/GUID-A48822BE-E726-5892-A83D-CDD224C27EA0"> Opening an audio output stream</xref>  </p> </li> <li id="GUID-F3A82F27-5406-5937-BC5E-E83D9C7A6F6B"><p><xref href="GUID-ECBA6331-2187-52C9-A5DF-20CD1EEFE781.dita#GUID-ECBA6331-2187-52C9-A5DF-20CD1EEFE781/GUID-E21EE5D7-42ED-5D7C-AB8F-000D6BBE88A9">Getting and setting the stream properties</xref>  </p> </li> <li id="GUID-5F166776-8C9C-5C00-8A39-E77C9157DF59"><p><xref href="GUID-ECBA6331-2187-52C9-A5DF-20CD1EEFE781.dita#GUID-ECBA6331-2187-52C9-A5DF-20CD1EEFE781/GUID-CD886111-BE51-523D-A782-FA35A3889A0B"> Playing an audio output stream</xref>  </p> </li> <li id="GUID-7F60C260-A0B3-51C7-A1B1-4BE5A3F7E03A"><p><xref href="GUID-ECBA6331-2187-52C9-A5DF-20CD1EEFE781.dita#GUID-ECBA6331-2187-52C9-A5DF-20CD1EEFE781/GUID-B18F568C-E82B-5D46-A225-96816258E8AB">Stopping an audio output stream</xref>  </p> </li> </ul> <p id="GUID-7435C237-DB6C-516E-BB4D-C31BF96470B0"><b>Basic Procedure for Constructing an Audio Output Stream</b> </p> <p>The high level step to construct an audio output stream is shown here: </p> <ul><li id="GUID-8314E401-E900-587A-A7DD-2899214AB883"><p>The client application creates an audio output stream object using the static function <xref href="GUID-B87C8F92-9737-3636-9800-BA267A1DCA6D.dita#GUID-B87C8F92-9737-3636-9800-BA267A1DCA6D/GUID-B4D44672-C628-304A-B36E-8AF0ACAA8A80"><apiname>CMdaAudioOutputStream::NewL()</apiname></xref>. Optionally, it also sets the audio priorities to be able to access the audio hardware in relation to the other clients trying to access the same device. </p> <codeblock id="GUID-ACD5FF96-44F1-5DC8-8A89-CD3C193EAACE" xml:space="preserve">static IMPORT_C CMdaAudioOutputStream *NewL(MMdaAudioOutputStreamCallback &amp;aCallBack, 
    13 TInt aPriority, TMdaPriorityPreference aPref=EMdaPriorityPreferenceTimeAndQuality);</codeblock> </li> </ul> <p id="GUID-A48822BE-E726-5892-A83D-CDD224C27EA0"><b>Basic Procedure for Opening an Audio Output Stream </b> </p> <p>The high level steps to open an audio output stream are shown here: </p> <ol id="GUID-B7CF17BD-41ED-5B34-8801-7101170D43C9"><li id="GUID-074798AB-3B28-52FA-9082-0B34DBB6118C"><p>To open the output stream, use the <xref href="GUID-20D0D10F-3401-3F72-8AF6-DC35F6025DC2.dita"><apiname>Open()</apiname></xref> member function. For example: </p> <codeblock id="GUID-7EA3B237-91BB-5933-AAEE-1A59375BF004" xml:space="preserve">virtual void Open(TMdaPackage* aSettings);</codeblock> </li> <li id="GUID-2D96C7A5-A81C-5B6A-A977-5A897B357FEE"><p>Once the stream is open <xref href="GUID-A35C1D9B-DC43-39FB-9FF1-39CD01D981B8.dita#GUID-A35C1D9B-DC43-39FB-9FF1-39CD01D981B8/GUID-148F9A5D-883E-3E9E-A3F4-FBACFACC2CB4"><apiname>MMdaAudioOutputStreamCallback::MaoscOpenComplete()</apiname></xref> is invoked to indicate that the stream is ready to use. </p> <codeblock id="GUID-6F18FC40-E21D-58D9-8703-0BDA17E69F0A" xml:space="preserve">void CIOStreamAudio::MaoscOpenComplete(TInt aError)
    13 TInt aPriority, TMdaPriorityPreference aPref=EMdaPriorityPreferenceTimeAndQuality);</codeblock> </li> </ul> <p id="GUID-A48822BE-E726-5892-A83D-CDD224C27EA0"><b>Basic Procedure for Opening an Audio Output Stream </b> </p> <p>The high level steps to open an audio output stream are shown here: </p> <ol id="GUID-B7CF17BD-41ED-5B34-8801-7101170D43C9"><li id="GUID-074798AB-3B28-52FA-9082-0B34DBB6118C"><p>To open the output stream, use the <xref href="GUID-20D0D10F-3401-3F72-8AF6-DC35F6025DC2.dita"><apiname>Open()</apiname></xref> member function. For example: </p> <codeblock id="GUID-7EA3B237-91BB-5933-AAEE-1A59375BF004" xml:space="preserve">virtual void Open(TMdaPackage* aSettings);</codeblock> </li> <li id="GUID-2D96C7A5-A81C-5B6A-A977-5A897B357FEE"><p>Once the stream is open <xref href="GUID-A35C1D9B-DC43-39FB-9FF1-39CD01D981B8.dita#GUID-A35C1D9B-DC43-39FB-9FF1-39CD01D981B8/GUID-148F9A5D-883E-3E9E-A3F4-FBACFACC2CB4"><apiname>MMdaAudioOutputStreamCallback::MaoscOpenComplete()</apiname></xref> is invoked to indicate that the stream is ready to use. </p> <codeblock id="GUID-6F18FC40-E21D-58D9-8703-0BDA17E69F0A" xml:space="preserve">void CIOStreamAudio::MaoscOpenComplete(TInt aError)
    14     {
    14     {
    15     ASSERT(iState==EStateOpeningOutput);
    15     ASSERT(iState==EStateOpeningOutput);
    16     TInt error = aError;
    16     TInt error = aError;
    17     if (error==KErrNone)
    17     if (error==KErrNone)