#include #include "config.h" #include "f2f.h" #include "../drv/sport.h" extern u16 mCodecNum ; extern struct AudioCodec mAudioCodec[16]; static u16 mInputNum = 0; static u16 mOutputNum = 0; static ufloat* mRxChannel[MAX_INPUT_NUM]; static ufloat* mTxChannel[MAX_OUTPUT_NUM]; uvoid SetNumOfChannels(u16 rxNum, u16 txNum) { if(rxNum > MAX_INPUT_NUM) rxNum = MAX_INPUT_NUM; if(txNum > MAX_OUTPUT_NUM) txNum = MAX_OUTPUT_NUM; mInputNum = rxNum; mOutputNum = txNum; } inline uvoid floatData(ufloat *output, const s32 *input, u32 instep, u32 length) { for(u32 i = 0; i < length; i++) { output[i] = __builtin_conv_RtoF(input[instep*i]); } } // Unoptimized function to convert the outgoing floating-point data to 1.31 fixed-point format. inline uvoid fixData(s32 *output, const ufloat *input, u32 outstep, u32 length) { for(u32 i = 0; i < length; i++) { output[outstep*i] = __builtin_conv_FtoR(input[i]); } } uvoid SetRxChannelPtr(u32 channel ,ufloat* rxBuffer) { if (channel < MAX_INPUT_NUM) { mRxChannel[channel] = rxBuffer; } } uvoid SetTxChannelPtr(u32 channel, ufloat* txBuffer) { if (channel < MAX_OUTPUT_NUM) { mTxChannel[channel] = txBuffer; } } uvoid SetTxRxNullBufferPtr() { memset(mRxChannel, 0, sizeof(ufloat*)*MAX_INPUT_NUM); memset(mTxChannel, 0, sizeof(ufloat*)*MAX_OUTPUT_NUM); } uvoid MuteOutput() { // for(u32 i =0 ;i< mOutputNum;i++) { // memset(mTxChannel[i],0 , SAMPLE_NUM*sizeof(ufloat)); // } for(u32 i =0 ;i < mCodecNum ;i++) { struct AudioCodec* codec = &mAudioCodec[i]; if(codec->rx == ufalse) { s32* dataPtr0 = codec->dataPtr[0] ; s32* dataPtr1 = codec->dataPtr[1] ; if(codec->enable_sec){ memset(dataPtr0, 0 ,sizeof(s32)*codec->slot_num*2*SAMPLE_NUM); memset(dataPtr1, 0 ,sizeof(s32)*codec->slot_num*2*SAMPLE_NUM); } else{ memset(dataPtr0, 0 ,sizeof(s32)*codec->slot_num*SAMPLE_NUM); memset(dataPtr1, 0 ,sizeof(s32)*codec->slot_num*SAMPLE_NUM); } } } } #define CHANNEL_OF(c) (2*((c)&(codec->slot_num-1))+ (c)/codec->slot_num) /* * sec ÅÅÁз½Ê½: 0,16,1,17,2,18,...,15,31 */ uvoid UpdateInput(u32 blockIndex) { u32 channel = 0; for(u32 i =0 ;i < mCodecNum ;i++) { struct AudioCodec* codec = &mAudioCodec[i]; if(codec->rx) { s32* dataPtr = codec->dataPtr[blockIndex] ; if(codec->enable_sec){ for(u32 j = 0; channel < mInputNum && j < codec->channel_num*2 ;j ++,channel++) { if(mRxChannel[channel] != NULL) floatData(mRxChannel[channel], dataPtr + CHANNEL_OF(j),codec->slot_num*2, SAMPLE_NUM); } } else{ for(u32 j = 0; channel < mInputNum && j < codec->channel_num ;j ++,channel++) { if(mRxChannel[channel] != NULL) floatData(mRxChannel[channel], dataPtr + j,codec->slot_num, SAMPLE_NUM); } } } } } uvoid UpdateOutput(u32 blockIndex) { u32 channel = 0; for(u32 i =0 ;i < mCodecNum ;i++) { struct AudioCodec* codec = &mAudioCodec[i]; if(codec->rx == ufalse) { s32* dataPtr = codec->dataPtr[blockIndex] ; if(codec->enable_sec){ for(u32 j = 0; channel < mOutputNum && j < codec->channel_num*2 ;j ++,channel++) { if(mTxChannel[channel] != NULL) fixData(dataPtr + CHANNEL_OF(j), mTxChannel[channel], codec->slot_num*2, SAMPLE_NUM); } } else{ for(u32 j = 0; channel < mOutputNum && j < codec->channel_num ;j ++,channel++) { if(mTxChannel[channel] != NULL) fixData(dataPtr + j, mTxChannel[channel], codec->slot_num, SAMPLE_NUM); } } } } }