Speex is also available for Ios and Android "code page two"

Source: Internet
Author: User
<span id="Label3"></p><p><p>The book was answered Once.<br>The previous article mentions how to encode audio PCM data using protocols so that it can be used for iOS and Android systems when Decoding.</p></p><p><p>Now is the decoding part, the decoding part is to obtain all the bytes of The. SPX file, and then according to the previous protocol, get the header information of The. spx, get the relevant parameters of the audio in the header information, then initialize the player, then decode each frame to play.</p></p><p><p>Regarding the agreement part, may have many kinds of protocol way, can follow the SPEEX_HEADER.H definition the way also can, I chose the most convenient one.</p></p><p><p>The following parameters specifically explain, because directly related to the success or failure of Decoding.</p></p><p><p>Bit rate: 160</p></p><p><p>Bit rate is 160, the source data of each frame is 160 bytes when the recording is Proved.</p></p><p><p>The frame size is assumed to be 20, proving that each frame 160 bytes of source data is encoded and converted into a 20-byte SPX File.</p></p><p><p>That<br></p></p><p><p>therefore, the decoding of the time, the first to obtain 20 bytes of SPX data, decode the source data 160 bytes, and then play.</p></p><pre class="prettyprint"><code class=" hljs avrasm">byte[] Endecode = new byte[<span class="hljs-number"><span class="hljs-number">65536</span></span>]<span class="hljs-comment"><span class="hljs-comment">;</span></span>For (int Packagecount =<span class="hljs-number"><span class="hljs-number">0</span></span> <span class="hljs-comment"><span class="hljs-comment">; mdatapro<= (int) Spxdatalength;packagecount++) {</span></span>Dis<span class="hljs-preprocessor"><span class="hljs-preprocessor">. readfully</span></span>(endecode,<span class="hljs-number"><span class="hljs-number">0</span></span>, Framesize)<span class="hljs-comment"><span class="hljs-comment">;</span></span>Log<span class="hljs-preprocessor"><span class="hljs-preprocessor">. D</span></span>(Speex<span class="hljs-preprocessor"><span class="hljs-preprocessor">. SPEEX</span></span>_log,<span class="hljs-string"><span class="hljs-string">"mdatapro="</span></span>+mdatapro)<span class="hljs-comment"><span class="hljs-comment">;</span></span>Mdatapro+=framesize<span class="hljs-comment"><span class="hljs-comment">;</span></span>int Decsize<span class="hljs-comment"><span class="hljs-comment">;</span></span>short[] decoded = new short[<span class="hljs-number"><span class="hljs-number"></span> the</span>]<span class="hljs-comment"><span class="hljs-comment">;</span></span>If ((decsize=speexdecoder<span class="hljs-preprocessor"><span class="hljs-preprocessor">. Decode</span></span>(endecode, decoded,<span class="hljs-number"><span class="hljs-number"></span> the</span>)) ><span class="hljs-number"><span class="hljs-number">0</span></span>) {Log<span class="hljs-preprocessor"><span class="hljs-preprocessor">. D</span></span>(Speex<span class="hljs-preprocessor"><span class="hljs-preprocessor">. SPEEX</span></span>_log,<span class="hljs-string"><span class="hljs-string">"decsize size="</span></span>+decsize)<span class="hljs-comment"><span class="hljs-comment">;</span></span>Log<span class="hljs-preprocessor"><span class="hljs-preprocessor">. D</span></span>(Speex<span class="hljs-preprocessor"><span class="hljs-preprocessor">. SPEEX</span></span>_log,<span class="hljs-string"><span class="hljs-string">"decoded size="</span></span>+decoded<span class="hljs-preprocessor"><span class="hljs-preprocessor">. Length</span></span>)<span class="hljs-comment"><span class="hljs-comment">;</span></span>Log<span class="hljs-preprocessor"><span class="hljs-preprocessor">. D</span></span>(Speex<span class="hljs-preprocessor"><span class="hljs-preprocessor">. SPEEX</span></span>_log,<span class="hljs-string"><span class="hljs-string">"decoded ="</span></span>+decoded)<span class="hljs-comment"><span class="hljs-comment">;</span></span>Track<span class="hljs-preprocessor"><span class="hljs-preprocessor">. Write</span></span>(decoded,<span class="hljs-number"><span class="hljs-number">0</span></span>, Decsize)<span class="hljs-comment"><span class="hljs-comment">;</span></span>Track<span class="hljs-preprocessor"><span class="hljs-preprocessor">. Play</span></span>()<span class="hljs-comment"><span class="hljs-comment">;</span></span>} }</code></pre><p><p>Each time the length of the framesize data read into the endecode, and then through the Speex decode method, get to the source data decoded, and then put decoded in the player to Play.</p></p><p><p>Demo Address:<br>csdn:http://download.csdn.net/detail/a_asinceo/8879125<br>Git:https://github.com/parktjt/speex</p></p><p><p>The last one on the demo:<br></p></p><p><p>At this point, the demo has been completed, we can be processed according to their own needs, special head information section, can be encrypted processing, or increase the length of the Indicator.<br>Hope can help everyone understand the use of good Speex.</p></p> <p style="font-size:12px;"><p style="font-size:12px;">Copyright Notice: This article for Bo Master original article, without Bo Master permission not Reproduced.</p></p> <p><p>Speex is also available for Ios and Android "code page two"</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.