Dears,<div><br><div>Hello, all. I'm a student in China majoring in Computer Science, and I'm working on my final year project.</div><div>In my project, I want to make a software to compare sounds. So, I must write C codes to decode mp3, grab wave data and implement some algorithm.</div>
<div>I've search a lot of websites and try some method, but my problem is not solved.</div><div><br></div><div>Now, I have some mp3 that record sounds. All of them are stereo which contains 2 channels. I can use ffmpeg command line to extract each channels into 2 mono files which contains only 1 channel. But this is a lot of troubles.</div>
<div><br></div><div>I've read the tutorials on <a href="http://ffmpeg.org">ffmpeg.org</a> and know how to decode mp3.   Here's some codes. </div><div><br></div><div><div><span class="Apple-tab-span" style="white-space:pre">     </span>while ( av_read_frame( pFmtCtx, &packet ) == 0 ) {</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">             </span>if ( packet.stream_index != audioStream ) {</div><div><span class="Apple-tab-span" style="white-space:pre">                  </span>continue;</div><div><span class="Apple-tab-span" style="white-space:pre">            </span>}</div>
<div><span class="Apple-tab-span" style="white-space:pre">              </span>// all packet are audio packet</div><div><span class="Apple-tab-span" style="white-space:pre">               </span>sample_size = AVCODEC_MAX_AUDIO_FRAME_SIZE;</div><div>
<span class="Apple-tab-span" style="white-space:pre">         </span>memset( sample, 0, sizeof( int16_t ) * AVCODEC_MAX_AUDIO_FRAME_SIZE );</div><div>//<span class="Apple-tab-span" style="white-space:pre">             </span>printf( "%d\n", packet.size );</div>
<div><span class="Apple-tab-span" style="white-space:pre">              </span>if ( avcodec_decode_audio3( pCodecCtx, sample, &sample_size, &packet ) >= 0 )</div><div><span class="Apple-tab-span" style="white-space:pre">                     </span>printf( "%d %d %d\n", ++i, packet.size, sample_size );</div>
<div><span class="Apple-tab-span" style="white-space:pre">              </span>av_free_packet( &packet );</div><div><span class="Apple-tab-span" style="white-space:pre">       </span>}</div></div><div><br></div><div>This is what I can get from the two tutorials on ffmpeg.org...  But I don't know the meanings of the data in the sample buffer. Are they 16 bit PCM??</div>
<div><br></div><div>Further more, there are two channel in the mp3, and I don't know how to extract the data of each channel and decode it into different buffer ??</div><div><br></div><div>Can anyone give me some sample codes in C language ??? </div>
<div><br></div><div>Thanks to all. I need your helps.</div></div>