4343#define GOOGLE_RTC_NUM_INPUT_PINS 2
4444#define GOOGLE_RTC_NUM_OUTPUT_PINS 1
4545
46+ #if CONFIG_COMP_GOOGLE_RTC_USE_32_BIT_FLOAT_API
47+ #define BUF_TYPE float
48+ #else
49+ #define BUF_TYPE int16_t
50+ #endif
51+
4652LOG_MODULE_REGISTER (google_rtc_audio_processing , CONFIG_SOF_LOG_LEVEL );
4753
4854/* b780a0a6-269f-466f-b477-23dfa05af758 */
@@ -59,10 +65,10 @@ struct google_rtc_audio_processing_comp_data {
5965 int num_aec_reference_channels ;
6066 int num_capture_channels ;
6167 GoogleRtcAudioProcessingState * state ;
62- float * aec_reference_buffer ;
63- float * aec_reference_buffer_ptrs [SOF_IPC_MAX_CHANNELS ];
64- float * process_buffer ;
65- float * process_buffer_ptrs [SOF_IPC_MAX_CHANNELS ];
68+ BUF_TYPE * aec_reference_buffer ;
69+ BUF_TYPE * aec_reference_buffer_ptrs [SOF_IPC_MAX_CHANNELS ];
70+ BUF_TYPE * process_buffer ;
71+ BUF_TYPE * process_buffer_ptrs [SOF_IPC_MAX_CHANNELS ];
6672 uint8_t * memory_buffer ;
6773 struct comp_data_blob_handler * tuning_handler ;
6874 bool reconfigure ;
@@ -591,8 +597,9 @@ static int google_rtc_audio_processing_reset(struct processing_module *mod)
591597 return 0 ;
592598}
593599
594- static int16_t convert_float_to_uint16_hifi ( float data )
600+ static inline int16_t convert_google_aec_format_to_int16 ( BUF_TYPE data )
595601{
602+ #if CONFIG_COMP_GOOGLE_RTC_USE_32_BIT_FLOAT_API
596603 const xtfloat ratio = 2 << 14 ;
597604 xtfloat x0 = data ;
598605 xtfloat x1 ;
@@ -602,17 +609,24 @@ static int16_t convert_float_to_uint16_hifi(float data)
602609 x = XT_TRUNC_S (x1 , 0 );
603610
604611 return x ;
612+ #else /* CONFIG_COMP_GOOGLE_RTC_USE_32_BIT_FLOAT_API */
613+ return data ;
614+ #endif
605615}
606616
607- static float convert_uint16_to_float_hifi (int16_t data )
617+ static inline BUF_TYPE convert_int16_to_google_aec_format (int16_t data )
608618{
619+ #if CONFIG_COMP_GOOGLE_RTC_USE_32_BIT_FLOAT_API
609620 const xtfloat ratio = 2 << 14 ;
610621 xtfloat x0 = data ;
611622 float x ;
612623
613624 x = XT_DIV_S (x0 , ratio );
614625
615626 return x ;
627+ #else /* CONFIG_COMP_GOOGLE_RTC_USE_32_BIT_FLOAT_API */
628+ return data ;
629+ #endif
616630}
617631
618632/* todo CONFIG_FORMAT_S32LE */
@@ -679,17 +693,22 @@ static int google_rtc_audio_processing_process(struct processing_module *mod,
679693 for (int i = 0 ; i < cd -> num_frames ; i ++ ) {
680694 for (channel = 0 ; channel < cd -> num_aec_reference_channels ; ++ channel ) {
681695 cd -> aec_reference_buffer_ptrs [channel ][i ] =
682- convert_uint16_to_float_hifi (ref [channel ]);
696+ convert_int16_to_google_aec_format (ref [channel ]);
683697 }
684698 ref += cd -> num_aec_reference_channels ;
685699 if ((void * )ref >= (void * )ref_buf_end )
686700 ref = (void * )ref_buf_start ;
687701 }
688702
703+ #if CONFIG_COMP_GOOGLE_RTC_USE_32_BIT_FLOAT_API
689704 GoogleRtcAudioProcessingAnalyzeRender_float32 (
690705 cd -> state ,
691706 (const float * * )cd -> aec_reference_buffer_ptrs );
692-
707+ #else
708+ GoogleRtcAudioProcessingAnalyzeRender_int16 (
709+ cd -> state ,
710+ (const int16_t * )cd -> aec_reference_buffer );
711+ #endif
693712 source_release_data (ref_stream , num_of_bytes_to_process );
694713
695714 /* process main stream - de interlace and convert */
@@ -702,7 +721,7 @@ static int google_rtc_audio_processing_process(struct processing_module *mod,
702721 for (int i = 0 ; i < cd -> num_frames ; i ++ ) {
703722 for (channel = 0 ; channel < cd -> num_capture_channels ; channel ++ )
704723 cd -> process_buffer_ptrs [channel ][i ] =
705- convert_uint16_to_float_hifi (src [channel ]);
724+ convert_int16_to_google_aec_format (src [channel ]);
706725
707726 src += cd -> num_capture_channels ;
708727 if ((void * )src >= (void * )src_buf_end )
@@ -712,9 +731,15 @@ static int google_rtc_audio_processing_process(struct processing_module *mod,
712731 source_release_data (src_stream , num_of_bytes_to_process );
713732
714733 /* call the library, use same in/out buffers */
734+ #if CONFIG_COMP_GOOGLE_RTC_USE_32_BIT_FLOAT_API
715735 GoogleRtcAudioProcessingProcessCapture_float32 (cd -> state ,
716736 (const float * * )cd -> process_buffer_ptrs ,
717737 cd -> process_buffer_ptrs );
738+ #else
739+ GoogleRtcAudioProcessingProcessCapture_int16 (cd -> state ,
740+ (const int16_t * )cd -> process_buffer ,
741+ cd -> process_buffer );
742+ #endif
718743
719744 /* same numnber of bytes to process for output stream as for mic stream */
720745 ret = sink_get_buffer (dst_stream , num_of_bytes_to_process , (void * * )& dst ,
@@ -724,8 +749,8 @@ static int google_rtc_audio_processing_process(struct processing_module *mod,
724749
725750 for (int i = 0 ; i < cd -> num_frames ; i ++ ) {
726751 for (channel = 0 ; channel < cd -> num_capture_channels ; channel ++ )
727- dst [channel ] =
728- convert_float_to_uint16_hifi ( cd -> process_buffer_ptrs [channel ][i ]);
752+ dst [channel ] = convert_google_aec_format_to_int16 (
753+ cd -> process_buffer_ptrs [channel ][i ]);
729754 dst += cd -> num_capture_channels ;
730755 if ((void * )dst >= (void * )dst_buf_end )
731756 dst = (void * )dst_buf_start ;
0 commit comments