2013-05-11 105 views
1

我又来了。这次我正在使用音频,我有一些内存泄漏问题之前,但现在他们解决了,这次我在这里有一个新问题,当我配置portaudio立体声(通道= 2),音频输出在质量差。立体声模式下音频输出不良 - FFMPEG PortAudio C++

只输出单声道不错,有在谷歌几乎没有溶液(或我是一个坏“Google员工”),这里是代码:

线程播放音频:

int16_t* audioBuffer=(int16_t*)av_malloc(FRAME_SZ_AV); 


int sz = MEDIA->DecodeAudioFrame(audioBuffer,0); 

if(sz==1) 
    Pa_WriteStream(MEDIA->output_stream,audioBuffer,MEDIA->_audio_ccontext->frame_size); 

if(sz!=1) 
    MessageBox(0,"error","error",MB_OK); 

ZeroMemory(audioBuffer,FRAME_SZ_AV); 
av_freep(&audioBuffer); 


DecodeAudioFrame功能

int WbMedia::DecodeAudioFrame(int16_t *audio_buf, int buf_size){ 
int return_status=0; 
AVPacket t_pack; 

while(!audio_packets.empty()){ 
    // Get new packet 
    WaitForSingleObject(Queue_Audio_Mutex,INFINITE); 
    t_pack = audio_packets.front(); 
    audio_packets.pop(); 
    ReleaseMutex(Queue_Audio_Mutex); 

    int obt_size = AVCODEC_MAX_AUDIO_FRAME_SIZE; 
    int consm = avcodec_decode_audio3(_audio_ccontext,audio_buf,&obt_size,&t_pack); 
    if(consm > 0 && obt_size > 0){ 
     return_status=1; 
     break; 
    } 
    return_status=-1; 
    break; 
} 

av_free_packet(&t_pack); 

return return_status; 
} 


PortAudio设置

output_params.device = Pa_GetDefaultOutputDevice(); //choosen_device.dev_index; 
output_params.sampleFormat=paInt16; 
output_params.channelCount=channel_count; 
output_params.suggestedLatency=choosen_device.dev_inf->defaultLowOutputLatency; 
output_params.hostApiSpecificStreamInfo=NULL; 

// Start with PA opening 
PaError pa_opening_err = Pa_OpenStream(&output_stream, 
    NULL, 
    &output_params, 
    sample_fr, 
    _audio_ccontext->frame_size, 
    paNoFlag, 
    NULL, 
    NULL 
); 

为什么音频立体声质量不好,不是单声道输出?我该如何解决它?

+0

您可能正在混合交错式和非交错式音频。 – 2013-05-13 01:06:20

+0

嗯,这是如何工作的?交错音频和平面音频?我知道交错是什么,平面是什么?那么,我需要使用交错立体声吗? – Spamdark 2013-05-13 22:26:40

+1

交错音频被格式化为交替的左右采样:LRLRLRLR。非交错格式化为左侧块,然后是右侧块:LLLLLRRRRR。这可能有所帮助:http://blog.bjornroche.com/2011/11/slides-from-fundamentals-of-audio.html – 2013-05-14 16:15:16

回答

0

不知道,

而是采用paInt16可以使用paInt24(24位sampleformat)获得更好的音质,但。我确实同意bjornroche,您可能在左右之间交错立体声输出,但请检查回调函数和输出数据