the input mp3 is single channel with 32000 sample rate, 16bit signed.
I am using ffmpeg 2.6 to decode mp3 on ios9.3.2 pad. It get white noise only. but it works on windows.I record the decoded PCM to file and use tool to play it. when I changed the bit set to 32. I can hear the original sound with noise in background ,and faster playing speed. if set to 8bit or 16bit, only white noise can be heard.
When I update the ffmpeg to 3.1.1, decoding failed for inconsistent channel configuration. I was really puzzled , how could this happened. I have not set any channel parameter yet nor necessary.
please help me.
What I have tried:
I have compare the input mp3 frame and output pcm on both system.
the input is the same as I read the mp3 frame from mp3 file , but get the totally different output. code as below.
int FfmpegAudioDecoder::InitDecoderFFMpeg()
{
codec_ = avcodec_find_decoder((AVCodecID)param_->codec_id);
if (!codec_)
{
failed_ = true;
av_log(0, log_level_, "Unsupported codec!");
return -1;
}
codec_ctx_ = avcodec_alloc_context3(codec_);
if (avcodec_open2(codec_ctx_, codec_, 0) < 0)
{
failed_ = true;
return -1;
}
if (!decoded_frame_) {
if (!(decoded_frame_ = av_frame_alloc())) {
av_log(0, log_level_, "Could not allocate audio frame\n");
return -1;
}
}
}
<pre>int FfmpegAudioDecoder::DecodeAudio(const WktData * encode_packet , WktData* pcm_packet)
{
int len = 0;
int pkt_size = 0;
unsigned char * pkt_data = 0;
AVPacket avpkt;
avpkt.data = encode_packet->data;
avpkt.size = encode_packet->data_length;
av_init_packet(&avpkt);
int got_frame = 0;
pkt_size = avpkt.size;
pkt_data = avpkt.data;
while (pkt_size > 0)
{
len = avcodec_decode_audio4(codec_ctx_, decoded_frame_, &got_frame, &avpkt);
if (len < 0)
{
return -1;
}
pkt_size -= len;
pkt_data += len;
}
return 0;
}