From e66aba2f74dcc440020c5570d0fd5955233d2633 Mon Sep 17 00:00:00 2001 From: Shiv Maliyappanahalli Date: Wed, 27 Jan 2016 16:08:57 -0800 Subject: [PATCH] hal: add support for 32/48KHz for voip Enable support for 32/48KHz for voip applications. Change-Id: Icfde47d14c9a0ee2b6efb0e2bed1642610f841df --- hal/audio_hw.c | 6 +++-- hal/voice_extn/compress_voip.c | 46 ++++++++++++++++++++++++++++++---- 2 files changed, 45 insertions(+), 7 deletions(-) mode change 100644 => 100755 hal/audio_hw.c diff --git a/hal/audio_hw.c b/hal/audio_hw.c old mode 100644 new mode 100755 index f18d4cf4..d7a3169c --- a/hal/audio_hw.c +++ b/hal/audio_hw.c @@ -2782,7 +2782,8 @@ static int in_set_parameters(struct audio_stream *stream, const char *kvpairs) if ((in->source == AUDIO_SOURCE_VOICE_COMMUNICATION) && (in->dev->mode == AUDIO_MODE_IN_COMMUNICATION) && (voice_extn_compress_voip_is_format_supported(in->format)) && - (in->config.rate == 8000 || in->config.rate == 16000) && + (in->config.rate == 8000 || in->config.rate == 16000 || + in->config.rate == 32000 || in->config.rate == 48000 ) && (audio_channel_count_from_in_mask(in->channel_mask) == 1)) { err = voice_extn_compress_voip_open_input_stream(in); if (err != 0) { @@ -3786,7 +3787,8 @@ static int adev_open_input_stream(struct audio_hw_device *dev, if ((in->source == AUDIO_SOURCE_VOICE_COMMUNICATION) && (in->dev->mode == AUDIO_MODE_IN_COMMUNICATION) && (voice_extn_compress_voip_is_format_supported(in->format)) && - (in->config.rate == 8000 || in->config.rate == 16000) && + (in->config.rate == 8000 || in->config.rate == 16000 || + in->config.rate == 32000 || in->config.rate == 48000) && (audio_channel_count_from_in_mask(in->channel_mask) == 1)) { voice_extn_compress_voip_open_input_stream(in); } diff --git a/hal/voice_extn/compress_voip.c b/hal/voice_extn/compress_voip.c index 61a7f3e7..74046179 100644 --- a/hal/voice_extn/compress_voip.c +++ b/hal/voice_extn/compress_voip.c @@ -38,6 +38,8 @@ #define COMPRESS_VOIP_IO_BUF_SIZE_NB 320 #define COMPRESS_VOIP_IO_BUF_SIZE_WB 640 +#define COMPRESS_VOIP_IO_BUF_SIZE_SWB 1280 +#define COMPRESS_VOIP_IO_BUF_SIZE_FB 1920 struct pcm_config pcm_config_voip_nb = { .channels = 1, @@ -55,6 +57,22 @@ struct pcm_config pcm_config_voip_wb = { .format = PCM_FORMAT_S16_LE, }; +struct pcm_config pcm_config_voip_swb = { + .channels = 1, + .rate = 32000, /* changed when the stream is opened */ + .period_size = COMPRESS_VOIP_IO_BUF_SIZE_SWB/2, + .period_count = 10, + .format = PCM_FORMAT_S16_LE, +}; + +struct pcm_config pcm_config_voip_fb = { + .channels = 1, + .rate = 48000, /* changed when the stream is opened */ + .period_size = COMPRESS_VOIP_IO_BUF_SIZE_FB/2, + .period_count = 10, + .format = PCM_FORMAT_S16_LE, +}; + struct voip_data { struct pcm *pcm_rx; struct pcm *pcm_tx; @@ -467,15 +485,24 @@ void voice_extn_compress_voip_in_get_parameters(struct stream_in *in, int voice_extn_compress_voip_out_get_buffer_size(struct stream_out *out) { - if (out->config.rate == 16000) + if (out->config.rate == 48000) + return COMPRESS_VOIP_IO_BUF_SIZE_FB; + else if (out->config.rate== 32000) + return COMPRESS_VOIP_IO_BUF_SIZE_SWB; + else if (out->config.rate == 16000) return COMPRESS_VOIP_IO_BUF_SIZE_WB; else return COMPRESS_VOIP_IO_BUF_SIZE_NB; + } int voice_extn_compress_voip_in_get_buffer_size(struct stream_in *in) { - if (in->config.rate == 16000) + if (in->config.rate == 48000) + return COMPRESS_VOIP_IO_BUF_SIZE_FB; + else if (in->config.rate== 32000) + return COMPRESS_VOIP_IO_BUF_SIZE_SWB; + else if (in->config.rate == 16000) return COMPRESS_VOIP_IO_BUF_SIZE_WB; else return COMPRESS_VOIP_IO_BUF_SIZE_NB; @@ -570,7 +597,11 @@ int voice_extn_compress_voip_open_output_stream(struct stream_out *out) out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_MONO; out->channel_mask = AUDIO_CHANNEL_OUT_MONO; out->usecase = USECASE_COMPRESS_VOIP_CALL; - if (out->sample_rate == 16000) + if (out->sample_rate == 48000) + out->config = pcm_config_voip_fb; + else if (out->sample_rate == 32000) + out->config = pcm_config_voip_swb; + else if (out->sample_rate == 16000) out->config = pcm_config_voip_wb; else out->config = pcm_config_voip_nb; @@ -624,7 +655,11 @@ int voice_extn_compress_voip_open_input_stream(struct stream_in *in) goto done; in->usecase = USECASE_COMPRESS_VOIP_CALL; - if (in->config.rate == 16000) + if (in->config.rate == 48000) + in->config = pcm_config_voip_fb; + else if (in->config.rate == 32000) + in->config = pcm_config_voip_swb; + else if (in->config.rate == 16000) in->config = pcm_config_voip_wb; else in->config = pcm_config_voip_nb; @@ -716,7 +751,8 @@ bool voice_extn_compress_voip_is_config_supported(struct audio_config *config) ret = voice_extn_compress_voip_is_format_supported(config->format); if (ret) { if ((popcount(config->channel_mask) == 1) && - (config->sample_rate == 8000 || config->sample_rate == 16000)) + (config->sample_rate == 8000 || config->sample_rate == 16000 || + config->sample_rate == 32000 || config->sample_rate == 48000)) ret = ((voip_data.sample_rate == 0) ? true: (voip_data.sample_rate == config->sample_rate)); else