<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://www.newlc.com" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>NewLC - Converting from AMR to PCM16 does not work. - Comments</title>
 <link>http://www.newlc.com/topic-9211</link>
 <description>Comments for &quot;Converting from AMR to PCM16 does not work.&quot;</description>
 <language>en</language>
<item>
 <title>Re: Converting from AMR to PCM16 does not work.</title>
 <link>http://www.newlc.com/topic-9211#comment-22704</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;Hi&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;/sites/all/modules/smf_filter/smf_smileys/huh.gif&quot; alt=&quot;Huh&quot; border=&quot;0&quot; /&gt; You really don&amp;#039;t seem to have understood what an AMR file is and how it is encoded.&amp;nbsp; Or how to use MMF codecs and buffers.&amp;nbsp; There&amp;#039;s so many things wrong with this code. A little tutorial is in order:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Point 1:&lt;/b&gt;&lt;br /&gt;You&amp;#039;ve new&amp;#039;ed a TPtr8 into existence, and then not put it onto the cleanup stack even though you&amp;#039;ve called leaving functions subsequently.&amp;nbsp; Bad man!&amp;nbsp; The TPtr8 should be an automatic variable in any case.&amp;nbsp; I&amp;#039;m not sure why you&amp;#039;ve set the length and the maximum length as the same value either.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Point 2:&lt;/b&gt;&lt;br /&gt;An AMR file (a .amr file you can play on any AMR file player) contains a 6-byte binary header, this is always {0x23,0x21,0x41,0x4D,0x52,0x0A}.&amp;nbsp; If this is the type of file you&amp;#039;re trying to decode and convert above, you need to remove the first 6-bytes before you even hit the AMR data you&amp;#039;ll feed into the codec.&amp;nbsp; You haven&amp;#039;t done that above.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Point 3:&lt;/b&gt;&lt;br /&gt;An AMR file consists of a number of encoded frames of audio data.&amp;nbsp; Each frame represents 20ms of audio.&lt;br /&gt;&lt;br /&gt;Assuming this is a normal AMR file (and not AMR-WB) the sound will decode into 8KHz, 16-bit PCM.&amp;nbsp; 20ms of PCM of this type is 320bytes in size, do the math (8000Hz * 16-bits * 0.02sec = 2560bits = 320bytes).&amp;nbsp; So, your output MMF buffer in your decoder should be 320 bytes in size, enough to hold 1 frame of decoded AMR. That&amp;#039;s all you need.&lt;br /&gt;&lt;br /&gt;These 20ms frames of audio are compressed in the AMR file.&amp;nbsp; Depending on the encoding level used, frames will be the following sizes:&lt;br /&gt;&lt;br /&gt;CMR&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Mode&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Frame size (bytes)&lt;br /&gt;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AMR 4.75&amp;nbsp; &amp;nbsp; 13&lt;br /&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AMR 5.15&amp;nbsp; &amp;nbsp; 14&lt;br /&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AMR 5.9&amp;nbsp; &amp;nbsp; &amp;nbsp; 16&lt;br /&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AMR 6.7&amp;nbsp; &amp;nbsp; &amp;nbsp; 18&lt;br /&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AMR 7.4&amp;nbsp; &amp;nbsp; &amp;nbsp; 20&lt;br /&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AMR 7.95&amp;nbsp; &amp;nbsp; 21&lt;br /&gt;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AMR 10.2&amp;nbsp; &amp;nbsp; 27&lt;br /&gt;7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AMR 12.2&amp;nbsp; &amp;nbsp; 32&lt;br /&gt;&lt;br /&gt;Each frame consists of a 1 byte header, then the rest of the frame is audio data.&amp;nbsp; The entire frame is fed into the decoder (header too).&amp;nbsp; The frame size can be deduced from the frame header.&amp;nbsp; The top 4 bits of the header comprise the CMR, values 0-7 being valid for AMR, the top bit can actually be ignored, though it is used when AMR forms RTP payloads.&amp;nbsp; The lower 4-bits of the header are reserved and are not used.&lt;br /&gt;&lt;br /&gt;Possibly in the code above, you may want to read the frame header byte, deduce the frame size then read enough data to cover that one frame.&amp;nbsp; Decode that frame into the waiting 320byte PCM output buffer then write that buffer out to another file?&lt;br /&gt;&lt;br /&gt;None of this is necessary however as the MMF does all of this for you...&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Point 4:&lt;/b&gt;&lt;br /&gt;You&amp;#039;re output MMF buffer is set to be 320bytes, enough to hold 1 frame of decoded AMR.&amp;nbsp; OK&lt;br /&gt;&lt;br /&gt;You&amp;#039;re input buffer can be any size you like really as long as it&amp;#039;s big enough to hold at least one frame of AMR.&lt;br /&gt;&lt;br /&gt;How to use an MMF codec:&lt;br /&gt;Calling ProcessL() on a codec with a source buffer and a destination buffer will (in this instance) decode 1 frame of AMR from the source into the destination. The processing results in a TCodecProcessResult. This will have one of the following statuses:&lt;br /&gt;&lt;ul style=&quot;margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li&gt;EProcessComplete - all of the source data has been used and the destination buffer is full.&amp;nbsp; Read all new data into the source buffer and copy out the decoded frame from the destination buffer before calling ProcessL() again&lt;/li&gt;&lt;li&gt;EProcessIncomplete - the destination buffer is filled with one decoded frame, but there is still source data remaining.&amp;nbsp; Copy the decoded frame out of the destination buffer. Check the number of bytes remaining in the source buffer, if it&amp;#039;s less than the minimum AMR frame size (13bytes) copy in new data onto the end of the remaining data and call ProcessL() again &lt;/li&gt;&lt;li&gt;EDstNotFilled - should not happen in this case - decoding an AMR frame will ALWAYS produce 320bytes in the destination buffer&lt;/li&gt;&lt;li&gt;EEndOfData - not applicable to AMR decoding - once there is no data left in the file, the AMR stream has ended.&lt;/li&gt;&lt;li&gt;Other statuses are not used&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;Keep calling ProcessL() in a loop until all data in the file has been read and decoded.&amp;nbsp; Copy out the decoded PCM frame each time to another file and everything should be OK.&lt;br /&gt;&lt;br /&gt;Hope that helps.&lt;br /&gt;&lt;br /&gt;Andy&lt;/div&gt;</description>
 <pubDate>Wed, 17 Aug 2005 00:18:07 +0200</pubDate>
 <dc:creator>andrew.hayes</dc:creator>
 <guid isPermaLink="false">comment 22704 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: Converting from AMR to PCM16 does not work.</title>
 <link>http://www.newlc.com/topic-9211#comment-22703</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;&lt;div class=&quot;quoteheader&quot;&gt;Quote&lt;/div&gt;&lt;div class=&quot;quote&quot;&gt;I wonder why you chose a value of 320 bytes for the input for AMR. In a packed format, the maximum size for a frame for AMR is 32bytes (for the hishest possible bit rate in AMR).&lt;br /&gt;&lt;br /&gt;Symbian has a codec ported which is built in which does the AMR decoding? Which AMR decoder are you trying to use for the decoding?&lt;/div&gt;&lt;br /&gt;Please read the above code, you can see, I am not trying to decode. What I am doing is just converting AMR to PCM. &lt;/div&gt;</description>
 <pubDate>Wed, 27 Jul 2005 13:16:21 +0200</pubDate>
 <dc:creator>shagor</dc:creator>
 <guid isPermaLink="false">comment 22703 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: Converting from AMR to PCM16 does not work.</title>
 <link>http://www.newlc.com/topic-9211#comment-22702</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;I wonder why you chose a value of 320 bytes for the input for AMR. In a packed format, the maximum size for a frame for AMR is 32bytes (for the hishest possible bit rate in AMR).&lt;br /&gt;&lt;br /&gt;Symbian has a codec ported which is built in which does the AMR decoding? Which AMR decoder are you trying to use for the decoding? &lt;/div&gt;</description>
 <pubDate>Tue, 26 Jul 2005 12:26:44 +0200</pubDate>
 <dc:creator>Tony Francis</dc:creator>
 <guid isPermaLink="false">comment 22702 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: Converting from AMR to PCM16 does not work.</title>
 <link>http://www.newlc.com/topic-9211#comment-22701</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;thanks for your kindness, i hope you&amp;#039;ll get success&lt;br /&gt;&lt;/div&gt;</description>
 <pubDate>Fri, 22 Jul 2005 17:01:08 +0200</pubDate>
 <dc:creator>kesken</dc:creator>
 <guid isPermaLink="false">comment 22701 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: Converting from AMR to PCM16 does not work.</title>
 <link>http://www.newlc.com/topic-9211#comment-22700</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;Hello kesken,&lt;br /&gt;&lt;br /&gt;I completely agree with you. There is no good example about converting AMR to PCM. Those code snippets you may find around about conversion, does not work. I don&amp;#039;t know, why this should be so difficult. Anyway If I find any working solution, I will let you know.&lt;/div&gt;</description>
 <pubDate>Fri, 22 Jul 2005 08:44:30 +0200</pubDate>
 <dc:creator>shagor</dc:creator>
 <guid isPermaLink="false">comment 22700 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: Converting from AMR to PCM16 does not work.</title>
 <link>http://www.newlc.com/topic-9211#comment-22699</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;I&amp;#039;m also waiting for a good answer to this question desperately .&lt;br /&gt;pleaaaaassee! &lt;br /&gt;can&amp;#039;t somebody just put a working example code(project) to newlc.&lt;br /&gt;i think a tutorial is required about amr conversion issue.&lt;/div&gt;</description>
 <pubDate>Fri, 22 Jul 2005 08:17:27 +0200</pubDate>
 <dc:creator>kesken</dc:creator>
 <guid isPermaLink="false">comment 22699 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: Converting from AMR to PCM16 does not work.</title>
 <link>http://www.newlc.com/topic-9211#comment-22698</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;&lt;div class=&quot;quoteheader&quot;&gt;Quote&lt;/div&gt;&lt;div class=&quot;quote&quot;&gt;const TInt KAmrBufferSize = 320;&lt;br /&gt;const TInt KPcmBufferSize = 10000;&lt;/div&gt;&lt;br /&gt;320 is less than the actual amr file, so application crashes.&lt;/div&gt;</description>
 <pubDate>Thu, 21 Jul 2005 13:54:38 +0200</pubDate>
 <dc:creator>shagor</dc:creator>
 <guid isPermaLink="false">comment 22698 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: Converting from AMR to PCM16 does not work.</title>
 <link>http://www.newlc.com/topic-9211#comment-22697</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;try with thsese values:&lt;br /&gt;const TInt KAmrBufferSize = 320;&lt;br /&gt;const TInt KPcmBufferSize = 10000;&lt;br /&gt;&lt;br /&gt;might just work a bit better.&lt;br /&gt;&lt;br /&gt;yucca&lt;/div&gt;</description>
 <pubDate>Thu, 21 Jul 2005 12:22:32 +0200</pubDate>
 <dc:creator>yucca</dc:creator>
 <guid isPermaLink="false">comment 22697 at http://www.newlc.com</guid>
</item>
<item>
 <title>Converting from AMR to PCM16 does not work.</title>
 <link>http://www.newlc.com/topic-9211</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;&lt;/div&gt;&lt;p&gt;&lt;a href=&quot;http://www.newlc.com/topic-9211&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://www.newlc.com/topic-9211#comments</comments>
 <category domain="http://www.newlc.com/forums/audio">Audio</category>
 <pubDate>Thu, 21 Jul 2005 09:23:30 +0200</pubDate>
 <dc:creator>shagor</dc:creator>
 <guid isPermaLink="false">9707 at http://www.newlc.com</guid>
</item>
</channel>
</rss>
