hal: add support for 32/48KHz for voip

Enable support for 32/48KHz for voip applications.

Change-Id: Icfde47d14c9a0ee2b6efb0e2bed1642610f841df
This commit is contained in:
Shiv Maliyappanahalli 2016-01-27 16:08:57 -08:00 committed by Gerrit - the friendly Code Review server
parent 4a137d2026
commit e66aba2f74
2 changed files with 45 additions and 7 deletions

6
hal/audio_hw.c Normal file → Executable file
View File

@ -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);
}

View File

@ -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