12 <concept xml:lang="en" id="GUID-1C499E7D-8099-5BE4-AE46-6143388E6ACB"><title>Audio Input Streaming Tutorial</title><prolog><metadata><keywords/></metadata></prolog><conbody><p>This tutorial describes how to use Audio Input Streaming. </p> <section><title>Purpose</title> <p>The purpose of this tutorial is to show you how to open, read and then close an audio input stream. </p> <p><b>Required Background</b> </p> <p>The <xref href="GUID-715E0EA4-8B3D-5DDF-B773-922E367B114F.dita">Audio Input Streaming Overview</xref> provides an introduction to Audio Input Streaming. </p> <p><b>Introduction</b> </p> <p>The audio input stream interface class, <xref href="GUID-92BDB3AF-D9DB-35E2-AC6F-6435D3D1A4D8.dita"><apiname>CMdaAudioInputStream</apiname></xref>, enables MMF client applications to: </p> <ul><li id="GUID-577E976A-11CC-5054-ABDE-522A30B5FDCF"><p>stream audio data from the low level audio controller (which has collected it from a hardware device, such as a microphone) to specified buffers (record audio). </p> </li> <li id="GUID-71E21858-E184-5B07-AE02-EFBE8F823B6E"><p>specify the priority of the audio stream relative to other clients trying to use the same audio hardware </p> </li> <li id="GUID-BA394ADC-BC3F-5896-BAD0-EB24759DBD36"><p>set the sample rate and the number of channels to use for recording. </p> </li> <li id="GUID-1CEAC638-A49F-5A21-91FC-90B6B56522EA"><p>change the gain and channel balance of the input stream. </p> </li> </ul> <p>The low level audio controller stores the audio data in buffers. <xref href="GUID-92BDB3AF-D9DB-35E2-AC6F-6435D3D1A4D8.dita"><apiname>CMdaAudioInputStream</apiname></xref> reads these buffers incrementally and does not have to wait until capture is complete. </p> </section> <section><title>Using Audio Input Streaming </title> <p>Typically, using an audio input stream involves the following steps as shown in the sequence diagram below: </p> <fig id="GUID-FC960A5D-EDE5-5245-A736-6A6C00A0AC33"><image href="GUID-65885916-0242-5DDB-9D88-EB214096C4DF_d0e529071_href.png" placement="inline"/></fig> <p>The following tasks will be covered in this tutorial: </p> <ul><li id="GUID-1E1A247E-3740-5CAB-AEB7-171F455EE429"><p><xref href="GUID-1C499E7D-8099-5BE4-AE46-6143388E6ACB.dita#GUID-1C499E7D-8099-5BE4-AE46-6143388E6ACB/GUID-196AFBAE-8264-5DE2-994D-F2F06CF5CF3A"> Constructing an audio input stream</xref> </p> </li> <li id="GUID-2744A8AE-A82C-5DAC-8C12-87D9B5ADCA6F"><p><xref href="GUID-1C499E7D-8099-5BE4-AE46-6143388E6ACB.dita#GUID-1C499E7D-8099-5BE4-AE46-6143388E6ACB/GUID-51B28404-61E7-54E8-9F4E-730315308EA2">Opening an audio input stream</xref> </p> </li> <li id="GUID-98480431-5F02-57D0-9564-7F0FFF2782C8"><p><xref href="GUID-1C499E7D-8099-5BE4-AE46-6143388E6ACB.dita#GUID-1C499E7D-8099-5BE4-AE46-6143388E6ACB/GUID-4EAC65E0-E108-5BAA-B338-5B19B82D5057"> Getting and setting the stream properties</xref> </p> </li> <li id="GUID-C03B920D-396F-5A44-9A76-77709CE45D2B"><p><xref href="GUID-1C499E7D-8099-5BE4-AE46-6143388E6ACB.dita#GUID-1C499E7D-8099-5BE4-AE46-6143388E6ACB/GUID-BD91C4E9-9BBA-5442-A72E-01B42160DBDA"> Reading an audio input stream</xref> </p> </li> <li id="GUID-91F3BEEE-52D7-504C-B74D-5C2FB8D59004"><p><xref href="GUID-1C499E7D-8099-5BE4-AE46-6143388E6ACB.dita#GUID-1C499E7D-8099-5BE4-AE46-6143388E6ACB/GUID-5811A2A0-5793-5FBB-B01A-AD94590955A8">Stopping an audio input stream</xref> </p> </li> </ul> <p id="GUID-196AFBAE-8264-5DE2-994D-F2F06CF5CF3A"><b>Basic Procedure to Construct an Audio Input Stream</b> </p> <p>The high level step to construct an audio input stream is shown here: </p> <ul><li id="GUID-DDD98263-FD3A-5057-8E35-72D237807343"><p>The client application creates an audio input stream object using the static function <xref href="GUID-92BDB3AF-D9DB-35E2-AC6F-6435D3D1A4D8.dita#GUID-92BDB3AF-D9DB-35E2-AC6F-6435D3D1A4D8/GUID-D534A585-D2B7-3906-AD82-E14A5FC1D501"><apiname>CMdaAudioInputStream::NewL()</apiname></xref>. The input stream class provides two versions of the constructor: one with the default priority and preferences, and another with specified priority and preferences. The client application must also implement the observer class <xref href="GUID-6A1EAD31-95CA-3CAC-8897-791E9D522DF0.dita"><apiname>MMdaAudioInputStreamCallback</apiname></xref> to notify it about audio input streaming progress. </p> <p>The following code constructs an audio input stream: </p> <codeblock id="GUID-0749EB33-33FA-5B58-856B-99F96AB9E3A2" xml:space="preserve">CMdaAudioInputStream* aInputStream; |
12 <concept xml:lang="en" id="GUID-1C499E7D-8099-5BE4-AE46-6143388E6ACB"><title>Audio Input Streaming Tutorial</title><prolog><metadata><keywords/></metadata></prolog><conbody><p>This tutorial describes how to use Audio Input Streaming. </p> <section><title>Purpose</title> <p>The purpose of this tutorial is to show you how to open, read and then close an audio input stream. </p> <p><b>Required Background</b> </p> <p>The <xref href="GUID-715E0EA4-8B3D-5DDF-B773-922E367B114F.dita">Audio Input Streaming Overview</xref> provides an introduction to Audio Input Streaming. </p> <p><b>Introduction</b> </p> <p>The audio input stream interface class, <xref href="GUID-92BDB3AF-D9DB-35E2-AC6F-6435D3D1A4D8.dita"><apiname>CMdaAudioInputStream</apiname></xref>, enables MMF client applications to: </p> <ul><li id="GUID-577E976A-11CC-5054-ABDE-522A30B5FDCF"><p>stream audio data from the low level audio controller (which has collected it from a hardware device, such as a microphone) to specified buffers (record audio). </p> </li> <li id="GUID-71E21858-E184-5B07-AE02-EFBE8F823B6E"><p>specify the priority of the audio stream relative to other clients trying to use the same audio hardware </p> </li> <li id="GUID-BA394ADC-BC3F-5896-BAD0-EB24759DBD36"><p>set the sample rate and the number of channels to use for recording. </p> </li> <li id="GUID-1CEAC638-A49F-5A21-91FC-90B6B56522EA"><p>change the gain and channel balance of the input stream. </p> </li> </ul> <p>The low level audio controller stores the audio data in buffers. <xref href="GUID-92BDB3AF-D9DB-35E2-AC6F-6435D3D1A4D8.dita"><apiname>CMdaAudioInputStream</apiname></xref> reads these buffers incrementally and does not have to wait until capture is complete. </p> </section> <section><title>Using Audio Input Streaming </title> <p>Typically, using an audio input stream involves the following steps as shown in the sequence diagram below: </p> <fig id="GUID-FC960A5D-EDE5-5245-A736-6A6C00A0AC33"><image href="GUID-65885916-0242-5DDB-9D88-EB214096C4DF_d0e516450_href.png" placement="inline"/></fig> <p>The following tasks will be covered in this tutorial: </p> <ul><li id="GUID-1E1A247E-3740-5CAB-AEB7-171F455EE429"><p><xref href="GUID-1C499E7D-8099-5BE4-AE46-6143388E6ACB.dita#GUID-1C499E7D-8099-5BE4-AE46-6143388E6ACB/GUID-196AFBAE-8264-5DE2-994D-F2F06CF5CF3A"> Constructing an audio input stream</xref> </p> </li> <li id="GUID-2744A8AE-A82C-5DAC-8C12-87D9B5ADCA6F"><p><xref href="GUID-1C499E7D-8099-5BE4-AE46-6143388E6ACB.dita#GUID-1C499E7D-8099-5BE4-AE46-6143388E6ACB/GUID-51B28404-61E7-54E8-9F4E-730315308EA2">Opening an audio input stream</xref> </p> </li> <li id="GUID-98480431-5F02-57D0-9564-7F0FFF2782C8"><p><xref href="GUID-1C499E7D-8099-5BE4-AE46-6143388E6ACB.dita#GUID-1C499E7D-8099-5BE4-AE46-6143388E6ACB/GUID-4EAC65E0-E108-5BAA-B338-5B19B82D5057"> Getting and setting the stream properties</xref> </p> </li> <li id="GUID-C03B920D-396F-5A44-9A76-77709CE45D2B"><p><xref href="GUID-1C499E7D-8099-5BE4-AE46-6143388E6ACB.dita#GUID-1C499E7D-8099-5BE4-AE46-6143388E6ACB/GUID-BD91C4E9-9BBA-5442-A72E-01B42160DBDA"> Reading an audio input stream</xref> </p> </li> <li id="GUID-91F3BEEE-52D7-504C-B74D-5C2FB8D59004"><p><xref href="GUID-1C499E7D-8099-5BE4-AE46-6143388E6ACB.dita#GUID-1C499E7D-8099-5BE4-AE46-6143388E6ACB/GUID-5811A2A0-5793-5FBB-B01A-AD94590955A8">Stopping an audio input stream</xref> </p> </li> </ul> <p id="GUID-196AFBAE-8264-5DE2-994D-F2F06CF5CF3A"><b>Basic Procedure to Construct an Audio Input Stream</b> </p> <p>The high level step to construct an audio input stream is shown here: </p> <ul><li id="GUID-DDD98263-FD3A-5057-8E35-72D237807343"><p>The client application creates an audio input stream object using the static function <xref href="GUID-92BDB3AF-D9DB-35E2-AC6F-6435D3D1A4D8.dita#GUID-92BDB3AF-D9DB-35E2-AC6F-6435D3D1A4D8/GUID-D534A585-D2B7-3906-AD82-E14A5FC1D501"><apiname>CMdaAudioInputStream::NewL()</apiname></xref>. The input stream class provides two versions of the constructor: one with the default priority and preferences, and another with specified priority and preferences. The client application must also implement the observer class <xref href="GUID-6A1EAD31-95CA-3CAC-8897-791E9D522DF0.dita"><apiname>MMdaAudioInputStreamCallback</apiname></xref> to notify it about audio input streaming progress. </p> <p>The following code constructs an audio input stream: </p> <codeblock id="GUID-0749EB33-33FA-5B58-856B-99F96AB9E3A2" xml:space="preserve">CMdaAudioInputStream* aInputStream; |
13 aInputStream = CMdaAudioInputStream::NewL(aCallback, EMdaPriorityNormal, EMdaPriorityPreferenceTimeAndQuality);</codeblock> <p>where, <codeph>aCallback</codeph> is an <xref href="GUID-6A1EAD31-95CA-3CAC-8897-791E9D522DF0.dita"><apiname>MMdaAudioInputStreamCallback</apiname></xref> object. </p> </li> </ul> <p id="GUID-51B28404-61E7-54E8-9F4E-730315308EA2"><b>Basic Procedure to Open an Audio Input Stream</b> </p> <p>The high level steps to open an audio input stream are shown here: </p> <ol id="GUID-67E0F7C7-E2E3-5882-A21F-254CB2EEBDA3"><li id="GUID-B3AE7481-9750-5352-B10B-D51D1A220F97"><p>To open an input stream, use the <xref href="GUID-20D0D10F-3401-3F72-8AF6-DC35F6025DC2.dita"><apiname>Open()</apiname></xref> member function, which provides a pointer to the <xref href="GUID-06892E22-2EAC-305A-9D3A-F24E7F903427.dita"><apiname>TMdaPackage</apiname></xref> object with the required audio settings. You can also open the stream without the audio settings. For example: </p> <codeblock id="GUID-96065C5F-54F6-59D7-B6F1-BDE71EF46303" xml:space="preserve">aInputStream->Open(NULL);</codeblock> </li> <li id="GUID-8D443EF2-2FD1-5DBD-BEB3-21C5B7855978"><p>Once the stream is open, a <xref href="GUID-6A1EAD31-95CA-3CAC-8897-791E9D522DF0.dita#GUID-6A1EAD31-95CA-3CAC-8897-791E9D522DF0/GUID-1F9A4EAF-EE58-3FA4-8707-D8C5EDFC0664"><apiname>MMdaAudioInputStreamCallback::MaiscOpenComplete()</apiname></xref> is issued to indicate that the stream is ready for use. </p> <codeblock id="GUID-20F93B48-6662-59F1-A61B-374565A2FCB2" xml:space="preserve">void CIOStreamAudio::MaiscOpenComplete(TInt aError) |
13 aInputStream = CMdaAudioInputStream::NewL(aCallback, EMdaPriorityNormal, EMdaPriorityPreferenceTimeAndQuality);</codeblock> <p>where, <codeph>aCallback</codeph> is an <xref href="GUID-6A1EAD31-95CA-3CAC-8897-791E9D522DF0.dita"><apiname>MMdaAudioInputStreamCallback</apiname></xref> object. </p> </li> </ul> <p id="GUID-51B28404-61E7-54E8-9F4E-730315308EA2"><b>Basic Procedure to Open an Audio Input Stream</b> </p> <p>The high level steps to open an audio input stream are shown here: </p> <ol id="GUID-67E0F7C7-E2E3-5882-A21F-254CB2EEBDA3"><li id="GUID-B3AE7481-9750-5352-B10B-D51D1A220F97"><p>To open an input stream, use the <xref href="GUID-20D0D10F-3401-3F72-8AF6-DC35F6025DC2.dita"><apiname>Open()</apiname></xref> member function, which provides a pointer to the <xref href="GUID-06892E22-2EAC-305A-9D3A-F24E7F903427.dita"><apiname>TMdaPackage</apiname></xref> object with the required audio settings. You can also open the stream without the audio settings. For example: </p> <codeblock id="GUID-96065C5F-54F6-59D7-B6F1-BDE71EF46303" xml:space="preserve">aInputStream->Open(NULL);</codeblock> </li> <li id="GUID-8D443EF2-2FD1-5DBD-BEB3-21C5B7855978"><p>Once the stream is open, a <xref href="GUID-6A1EAD31-95CA-3CAC-8897-791E9D522DF0.dita#GUID-6A1EAD31-95CA-3CAC-8897-791E9D522DF0/GUID-1F9A4EAF-EE58-3FA4-8707-D8C5EDFC0664"><apiname>MMdaAudioInputStreamCallback::MaiscOpenComplete()</apiname></xref> is issued to indicate that the stream is ready for use. </p> <codeblock id="GUID-20F93B48-6662-59F1-A61B-374565A2FCB2" xml:space="preserve">void CIOStreamAudio::MaiscOpenComplete(TInt aError) |