From 9e0c17153dc97a6ce43e21008f94523a22885855 Mon Sep 17 00:00:00 2001 From: Marten Richter Date: Sat, 9 Mar 2013 16:48:17 +0100 Subject: [PATCH] Fix in downmix code + integer mixing code --- audioomx.cc | 31 +++++++++++++++++-------------- audioomx.h | 2 +- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/audioomx.cc b/audioomx.cc index b37279d..5e5926b 100644 --- a/audioomx.cc +++ b/audioomx.cc @@ -1617,7 +1617,7 @@ unsigned int AudioOMX::AdvanceAacLatmAudioSync(const UCHAR *data,unsigned int si #define SQRT3_2 1.22474487139158904909 void AudioOMX::getDownMixMatrix(unsigned long long channels, - double *left_mat,double *right_mat) + int *left_mat,int *right_mat) { int i,j; double downmix_matrix[2][64]; @@ -1628,6 +1628,9 @@ void AudioOMX::getDownMixMatrix(unsigned long long channels, } downmix_matrix[0/*links*/][/*FRONT_LEFT*/0]=1.; downmix_matrix[1/*rechts*/][/*FRONT_RIGHT*/1]=1.; + downmix_matrix[0/*links*/] [/*FRONT_CENTER*/2] = M_SQRT1_2; + downmix_matrix[1/*rechts*/] [/*FRONT_CENTER*/2] = M_SQRT1_2; + if (channels & (AV_CH_BACK_LEFT | AV_CH_SIDE_LEFT) ) { downmix_matrix[0/*links*/][/*BACK_CENTER*/8]=-M_SQRT1_2*M_SQRT1_2; downmix_matrix[1/*rechts*/][/*BACK_CENTER*/8]=M_SQRT1_2*M_SQRT1_2; @@ -1650,8 +1653,8 @@ void AudioOMX::getDownMixMatrix(unsigned long long channels, for (i=0,j=0;i<64;i++) { if ((1ULL << i)& channels) { - left_mat[j]=downmix_matrix[0][i]; - right_mat[j]=downmix_matrix[1][i]; + left_mat[j]=(int)(downmix_matrix[0][i]*(1<<16)); + right_mat[j]=(int)(downmix_matrix[1][i]*(1<<16)); j++; } } @@ -1976,7 +1979,7 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, min(haveToCopy,decompress_buffer_size-decompress_buffer_filled)); incoming_paket_libav.size = decompress_buffer_filled +min(haveToCopy,decompress_buffer_size-decompress_buffer_filled); - //Log::getInstance()->log("Audio", Log::DEBUG,"Use saved audio buffer %d",packet.type); + //Log::getInstance()->log("Audio", Log::DEBUG,"Use saved audio buffer %d %d %d",packet.type,decompress_buffer_filled,packet.synced); } else { incoming_paket_libav.data =(uint8_t*) buffer+packet.pos_buffer+*samplepos; incoming_paket_libav.size = haveToCopy; @@ -2171,8 +2174,8 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, } } else { unsigned int channels=current_context->channels; - double left_mat[channels]; - double right_mat[channels]; + int left_mat[channels]; + int right_mat[channels]; getDownMixMatrix(current_context->channel_layout,left_mat,right_mat); short* startbuffer=(short* )decode_frame_libav->data[0]; @@ -2181,20 +2184,20 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, while (startbuffer!=endbuffer) { short* cur_buf=startbuffer; short* cur_buf_end=startbuffer+channels; - double work1=0.; - double work2=0.; - double *mat1=left_mat; - double *mat2=right_mat; + int work1=0.; + int work2=0.; + int *mat1=left_mat; + int *mat2=right_mat; while (cur_buf!=cur_buf_end) { - work1+= ((*mat1)*((double)*cur_buf)); - work2+= ((*mat2)*((double)*cur_buf)); + work1+= ((*mat1)*(*cur_buf)); + work2+= ((*mat2)*(*cur_buf)); cur_buf++; mat1++; mat2++; } - *destbuffer=work1; + *destbuffer=work1>>16; destbuffer++; - *destbuffer=work2; + *destbuffer=work2>>16; destbuffer++; startbuffer+=channels; diff --git a/audioomx.h b/audioomx.h index 9e49b65..74ac21d 100644 --- a/audioomx.h +++ b/audioomx.h @@ -189,7 +189,7 @@ class AudioOMX : public Audio #ifdef USE_LIBRESAMPLE AVAudioResampleContext *resam_con_libav; #else - void getDownMixMatrix(unsigned long long channels,double *left_mat,double *right_mat); + void getDownMixMatrix(unsigned long long channels,int *left_mat,int *right_mat); #endif UCHAR * decompress_buffer; -- 2.39.5