diff --git a/hal/audio_extn/utils.c b/hal/audio_extn/utils.c index 9542fbdc..eb3213c4 100644 --- a/hal/audio_extn/utils.c +++ b/hal/audio_extn/utils.c @@ -666,6 +666,18 @@ int audio_extn_utils_send_app_type_cfg(struct audio_device *adev, if ((24 == usecase->stream.out->bit_width) && (usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER)) { usecase->stream.out->app_type_cfg.sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; + } else if ((snd_device == SND_DEVICE_OUT_HDMI || + snd_device == SND_DEVICE_OUT_USB_HEADSET || + snd_device == SND_DEVICE_OUT_DISPLAY_PORT) && + (usecase->stream.out->sample_rate >= OUTPUT_SAMPLING_RATE_44100)) { + /* + * To best utlize DSP, check if the stream sample rate is supported/multiple of + * configured device sample rate, if not update the COPP rate to be equal to the + * device sample rate, else open COPP at stream sample rate + */ + platform_check_and_update_copp_sample_rate(adev->platform, snd_device, + usecase->stream.out->sample_rate, + &usecase->stream.out->app_type_cfg.sample_rate); } else if ((snd_device != SND_DEVICE_OUT_HEADPHONES_44_1 && usecase->stream.out->sample_rate == OUTPUT_SAMPLING_RATE_44100) || (usecase->stream.out->sample_rate < OUTPUT_SAMPLING_RATE_44100)) { diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c index a42f9849..45ef1fa1 100644 --- a/hal/msm8916/platform.c +++ b/hal/msm8916/platform.c @@ -5016,6 +5016,29 @@ int platform_set_stream_channel_map(void *platform, audio_channel_mask_t channel return ret; } +void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device, + unsigned int stream_sr, int* sample_rate) +{ + struct platform_data* my_data = (struct platform_data *)platform; + int backend_idx = platform_get_backend_index(snd_device); + int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate; + /*Check if device SR is multiple of 8K or 11.025 Khz + *check if the stream SR is multiple of same base, if not set + *copp sample rate equal to device sample rate. + */ + if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) && + (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) || + ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) && + (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) { + *sample_rate = device_sr; + } else + *sample_rate = stream_sr; + + ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr +, *sample_rate); + +} + int platform_get_edid_info(void *platform) { struct platform_data *my_data = (struct platform_data *)platform; diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c index d209359b..bb1e485b 100644 --- a/hal/msm8974/platform.c +++ b/hal/msm8974/platform.c @@ -5299,6 +5299,32 @@ uint32_t platform_get_compress_passthrough_buffer_size( return fragment_size; } +void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device, + unsigned int stream_sr, int* sample_rate) +{ + struct platform_data* my_data = (struct platform_data *)platform; + int backend_idx = platform_get_backend_index(snd_device); + int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate; + /* + *Check if device SR is multiple of 8K or 11.025 Khz + *check if the stream SR is multiple of same base, if yes + *then have copp SR equal to stream SR, this ensures that + *post processing happens at stream SR, else have + *copp SR equal to device SR. + */ + if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) && + (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) || + ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) && + (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) { + *sample_rate = device_sr; + } else + *sample_rate = stream_sr; + + ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr +, *sample_rate); + +} + void platform_reset_edid_info(void *platform) { ALOGV("%s:", __func__); diff --git a/hal/platform_api.h b/hal/platform_api.h index 61f42de1..a12f865a 100644 --- a/hal/platform_api.h +++ b/hal/platform_api.h @@ -25,7 +25,9 @@ #define CODEC_BACKEND_DEFAULT_SAMPLE_RATE 48000 #define CODEC_BACKEND_DEFAULT_CHANNELS 2 #define CODEC_BACKEND_DEFAULT_TX_CHANNELS 1 - +#define SAMPLE_RATE_8000 8000 +#define SAMPLE_RATE_11025 11025 +#define sample_rate_multiple(sr, base) ((sr % base)== 0?true:false) enum { NATIVE_AUDIO_MODE_SRC = 1, @@ -187,4 +189,6 @@ int platform_retrieve_audio_cal(void* platform, int acdb_dev_id, int acdb_device unsigned char* platform_get_license(void* platform, int* size); int platform_get_max_mic_count(void *platform); +void platform_check_and_update_copp_sample_rate(void *platform, snd_device_t snd_device, + unsigned int stream_sr,int *sample_rate); #endif // AUDIO_PLATFORM_API_H