Skip to content

Commit 10d22b9

Browse files
Ramlal KarraGerrit - the friendly Code Review server
authored andcommitted
audio: Add HiFi Filter support
- Enable HiFi filter for 48kHz, 44.1kHz Music playback Change-Id: I87a87b0d719ac4ba82b3d16331711b85459a3edb Signed-off-by: Ramlal Karra <rkarra@codeaurora.org>
1 parent bf8c1ee commit 10d22b9

File tree

5 files changed

+165
-3
lines changed

5 files changed

+165
-3
lines changed

hal/audio_extn/audio_extn.c

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ static bool audio_extn_compress_in_enabled = false;
192192
static bool audio_extn_battery_listener_enabled = false;
193193
static bool audio_extn_maxx_audio_enabled = false;
194194
static bool audio_extn_audiozoom_enabled = false;
195+
static bool audio_extn_hifi_filter_enabled = false;
195196

196197
#define AUDIO_PARAMETER_KEY_AANC_NOISE_LEVEL "aanc_noise_level"
197198
#define AUDIO_PARAMETER_KEY_ANC "anc_enabled"
@@ -5164,6 +5165,87 @@ bool audio_extn_battery_properties_is_charging()
51645165
}
51655166
// END: BATTERY_LISTENER ================================================================
51665167

5168+
// START: HiFi Filter Feature ============================================================
5169+
void audio_extn_enable_hifi_filter(struct audio_device *adev, bool value)
5170+
{
5171+
const char *mixer_ctl_name = "HiFi Filter";
5172+
struct mixer_ctl *ctl = NULL;
5173+
ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
5174+
if (!ctl) {
5175+
ALOGE("%s: Could not get ctl for mixer cmd - %s, using default control",
5176+
__func__, mixer_ctl_name);
5177+
return;
5178+
} else {
5179+
mixer_ctl_set_value(ctl, 0, value);
5180+
ALOGD("%s: mixer_value set %d", __func__, value);
5181+
}
5182+
return;
5183+
}
5184+
5185+
void audio_extn_hifi_filter_set_params(struct str_parms *parms,
5186+
char *value, int len)
5187+
{
5188+
int ret = 0;
5189+
ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_HIFI_AUDIO_FILTER, value,len);
5190+
if (ret >= 0) {
5191+
if (value && !strncmp(value, "true", sizeof("true")))
5192+
audio_extn_hifi_filter_enabled = true;
5193+
else
5194+
audio_extn_hifi_filter_enabled = false;
5195+
str_parms_del(parms, AUDIO_PARAMETER_KEY_HIFI_AUDIO_FILTER);
5196+
}
5197+
}
5198+
5199+
bool audio_extn_hifi_check_usecase_params(int sample_rate, int usecase)
5200+
{
5201+
if (sample_rate != 48000 && sample_rate != 44100)
5202+
return false;
5203+
if (usecase == USECASE_AUDIO_PLAYBACK_LOW_LATENCY || usecase == USECASE_AUDIO_PLAYBACK_ULL)
5204+
return false;
5205+
return true;
5206+
}
5207+
5208+
bool audio_extn_is_hifi_filter_enabled(struct audio_device* adev, struct stream_out *out,
5209+
snd_device_t snd_device, char *codec_variant,
5210+
int channels, int usecase_init)
5211+
{
5212+
int na_mode = platform_get_native_support();
5213+
struct audio_usecase *uc = NULL;
5214+
struct listnode *node = NULL;
5215+
bool hifi_active = false;
5216+
5217+
if (audio_extn_hifi_filter_enabled) {
5218+
/*Restricting the feature for Tavil and WCD9375 codecs only*/
5219+
if ((strstr(codec_variant, "WCD9385") || strstr(codec_variant, "WCD9375"))
5220+
&& (na_mode == NATIVE_AUDIO_MODE_MULTIPLE_MIX_IN_DSP) && channels <=2) {
5221+
/*Upsampling 8 time should be restricited to headphones playback only */
5222+
if (snd_device == SND_DEVICE_OUT_HEADPHONES
5223+
|| snd_device == SND_DEVICE_OUT_HEADPHONES_44_1
5224+
|| snd_device == SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER
5225+
|| usecase_init) {
5226+
if (audio_extn_hifi_check_usecase_params(out->sample_rate,
5227+
out->usecase) && !usecase_init)
5228+
return true;
5229+
5230+
list_for_each(node, &adev->usecase_list) {
5231+
/* checking if hifi_filter is already active to set */
5232+
/* concurrent playback sessions with hifi_filter enabled*/
5233+
uc = node_to_item(node, struct audio_usecase, list);
5234+
struct stream_out *curr_out = (struct stream_out*) uc->stream.out;
5235+
if (uc->type == PCM_PLAYBACK && curr_out
5236+
&& audio_extn_hifi_check_usecase_params(
5237+
curr_out->sample_rate, curr_out->usecase) &&
5238+
(curr_out->channel_mask == AUDIO_CHANNEL_OUT_STEREO ||
5239+
curr_out->channel_mask == AUDIO_CHANNEL_OUT_MONO))
5240+
hifi_active = true;
5241+
}
5242+
}
5243+
}
5244+
}
5245+
return hifi_active;
5246+
}
5247+
// END: HiFi Filter Feature ==============================================================
5248+
51675249
// START: AUDIOZOOM_FEATURE =====================================================================
51685250
#ifdef __LP64__
51695251
#define AUDIOZOOM_LIB_PATH "/vendor/lib64/libaudiozoom.so"

hal/audio_extn/audio_extn.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ int audio_extn_parse_compress_metadata(struct stream_out *out,
116116
#define MAX_LENGTH_MIXER_CONTROL_IN_INT (128)
117117
#define HW_INFO_ARRAY_MAX_SIZE 32
118118

119+
#define AUDIO_PARAMETER_KEY_HIFI_AUDIO_FILTER "hifi_filter"
120+
119121
struct snd_card_split {
120122
char device[HW_INFO_ARRAY_MAX_SIZE];
121123
char snd_card[HW_INFO_ARRAY_MAX_SIZE];
@@ -261,6 +263,14 @@ int32_t audio_extn_read_afe_proxy_channel_masks(struct stream_out *out);
261263
int32_t audio_extn_get_afe_proxy_channel_count();
262264
//END: AFE_PROXY_FEATURE
263265

266+
//START: HIFI FILTER
267+
void audio_extn_enable_hifi_filter(struct audio_device *adev, bool value);
268+
void audio_extn_hifi_filter_set_params(struct str_parms *parms, char *value, int len);
269+
bool audio_extn_is_hifi_filter_enabled(struct audio_device* adev,struct stream_out *out,
270+
snd_device_t snd_device, char *codec_variant,
271+
int channels, int usecase_init);
272+
//END: HIFI FILTER
273+
264274
/// ---- USB feature ---------------------------------------------------------------
265275
void audio_extn_usb_init(void *adev);
266276
void audio_extn_usb_deinit();

hal/msm8974/hw_info.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ static const snd_device_t wsa_combo_devices[] = {
6464
SND_DEVICE_OUT_SPEAKER_AND_LINE,
6565
SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1,
6666
SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2,
67-
SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET
67+
SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET,
68+
SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_HIFI_FILTER
6869
};
6970

7071
static const snd_device_t taiko_fluid_variant_devices[] = {

hal/msm8974/platform.c

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,8 @@ static const char * const device_table[SND_DEVICE_MAX] = {
498498
[SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
499499
[SND_DEVICE_OUT_HEADPHONES] = "headphones",
500500
[SND_DEVICE_OUT_HEADPHONES_DSD] = "headphones-dsd",
501+
[SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER] = "headphones-hifi-filter",
502+
[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_HIFI_FILTER] = "speaker-and-headphones-hifi-filter",
501503
[SND_DEVICE_OUT_HEADPHONES_44_1] = "headphones-44.1",
502504
[SND_DEVICE_OUT_LINE] = "line",
503505
[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
@@ -830,6 +832,8 @@ static int acdb_device_table[SND_DEVICE_MAX] = {
830832
[SND_DEVICE_OUT_TRANSMISSION_FM] = 0,
831833
[SND_DEVICE_OUT_ANC_HEADSET] = 26,
832834
[SND_DEVICE_OUT_ANC_FB_HEADSET] = 27,
835+
[SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER] = 188,
836+
[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_HIFI_FILTER] = 188,
833837
[SND_DEVICE_OUT_VOICE_ANC_HEADSET] = 26,
834838
[SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = 27,
835839
[SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = 26,
@@ -999,6 +1003,8 @@ static struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
9991003
{TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
10001004
{TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
10011005
{TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES_DSD)},
1006+
{TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER)},
1007+
{TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_HIFI_FILTER)},
10021008
{TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES_44_1)},
10031009
{TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
10041010
{TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
@@ -2118,6 +2124,9 @@ static void set_platform_defaults(struct platform_data * my_data)
21182124
backend_tag_table[SND_DEVICE_IN_CAPTURE_FM] = strdup("capture-fm");
21192125
backend_tag_table[SND_DEVICE_OUT_TRANSMISSION_FM] = strdup("transmission-fm");
21202126
backend_tag_table[SND_DEVICE_OUT_HEADPHONES_DSD] = strdup("headphones-dsd");
2127+
backend_tag_table[SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER] = strdup("headphones-hifi-filter");
2128+
backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_HIFI_FILTER] =
2129+
strdup("speaker-and-headphones-hifi-filter");
21212130
backend_tag_table[SND_DEVICE_OUT_HEADPHONES_44_1] = strdup("headphones-44.1");
21222131
backend_tag_table[SND_DEVICE_OUT_VOICE_SPEAKER_VBAT] = strdup("voice-speaker-vbat");
21232132
backend_tag_table[SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT] = strdup("voice-speaker-2-vbat");
@@ -4882,6 +4891,9 @@ int platform_get_backend_index(snd_device_t snd_device)
48824891
if (strncmp(backend_tag_table[snd_device], "headphones-44.1",
48834892
sizeof("headphones-44.1")) == 0)
48844893
port = HEADPHONE_44_1_BACKEND;
4894+
else if (strncmp(backend_tag_table[snd_device], "headphones-hifi-filter",
4895+
sizeof("headphones-hifi-filter")) == 0)
4896+
port = HEADPHONE_BACKEND;
48854897
else if (strncmp(backend_tag_table[snd_device], "headphones-dsd",
48864898
sizeof("headphones-dsd")) == 0)
48874899
port = DSD_NATIVE_BACKEND;
@@ -5508,6 +5520,12 @@ int platform_split_snd_device(void *platform,
55085520
new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
55095521
new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
55105522
ret = 0;
5523+
} else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_HIFI_FILTER &&
5524+
!platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER)) {
5525+
*num_devices = 2;
5526+
new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
5527+
new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER;
5528+
ret = 0;
55115529
} else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
55125530
!platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_BT_SCO)) {
55135531
*num_devices = 2;
@@ -5691,6 +5709,9 @@ snd_device_t platform_get_output_snd_device(void *platform, struct stream_out *o
56915709
snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2;
56925710
else if (is_active_voice_call)
56935711
snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_HEADPHONES;
5712+
else if (audio_extn_is_hifi_filter_enabled(adev, out, snd_device,
5713+
my_data->codec_variant, channel_count, 1))
5714+
snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_HIFI_FILTER;
56945715
else
56955716
snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
56965717
} else if (devices == (AUDIO_DEVICE_OUT_LINE |
@@ -5714,6 +5735,9 @@ snd_device_t platform_get_output_snd_device(void *platform, struct stream_out *o
57145735
snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1;
57155736
else if (my_data->external_spk_2)
57165737
snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2;
5738+
else if (audio_extn_is_hifi_filter_enabled(adev, out, snd_device,
5739+
my_data->codec_variant, channel_count, 1))
5740+
snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_HIFI_FILTER;
57175741
else {
57185742
if (is_active_voice_call)
57195743
snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_HEADPHONES;
@@ -5980,6 +6004,11 @@ snd_device_t platform_get_output_snd_device(void *platform, struct stream_out *o
59806004
snd_device = SND_DEVICE_OUT_HEADPHONES_44_1;
59816005
} else if (out->format == AUDIO_FORMAT_DSD) {
59826006
snd_device = SND_DEVICE_OUT_HEADPHONES_DSD;
6007+
} else if (audio_extn_is_hifi_filter_enabled(adev, out, snd_device,
6008+
my_data->codec_variant, channel_count, 1)) {
6009+
snd_device = SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER;
6010+
} else if (devices & SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER) {
6011+
snd_device = SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER;
59836012
} else if (devices & AUDIO_DEVICE_OUT_LINE) {
59846013
snd_device = SND_DEVICE_OUT_LINE;
59856014
} else
@@ -7177,7 +7206,7 @@ static void true_32_bit_set_params(struct str_parms *parms,
71777206
ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_TRUE_32_BIT,
71787207
value,len);
71797208
if (ret >= 0) {
7180-
if (value && !strncmp(value, "true", sizeof("src")))
7209+
if (value && !strncmp(value, "true", sizeof("true")))
71817210
supports_true_32_bit = true;
71827211
else
71837212
supports_true_32_bit = false;
@@ -7527,6 +7556,7 @@ int platform_set_parameters(void *platform, struct str_parms *parms)
75277556
audio_extn_hfp_set_parameters(my_data->adev, parms);
75287557
perf_lock_set_params(platform, parms, value, len);
75297558
true_32_bit_set_params(parms, value, len);
7559+
audio_extn_hifi_filter_set_params(parms, value, len);
75307560
platform_spkr_device_set_params(platform, parms, value, len);
75317561
done:
75327562
ALOGV("%s: exit with code(%d)", __func__, ret);
@@ -8602,6 +8632,12 @@ static bool platform_check_codec_backend_cfg(struct audio_device* adev,
86028632
if (channels < out_channels)
86038633
channels = out_channels;
86048634
}
8635+
if ((snd_device == SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER) &&
8636+
(usecase->id==USECASE_AUDIO_PLAYBACK_LOW_LATENCY ||
8637+
usecase->id == USECASE_AUDIO_PLAYBACK_ULL)) {
8638+
sample_rate = my_data->current_backend_cfg[backend_idx].sample_rate;
8639+
bit_width = my_data->current_backend_cfg[backend_idx].bit_width;
8640+
}
86058641
}
86068642
}
86078643
}
@@ -8701,6 +8737,37 @@ static bool platform_check_codec_backend_cfg(struct audio_device* adev,
87018737
}
87028738
}
87038739

8740+
if (backend_idx != platform_get_voice_call_backend(adev)
8741+
&& usecase->type == PCM_PLAYBACK) {
8742+
struct stream_out *out = (struct stream_out*) usecase->stream.out;
8743+
if(audio_extn_is_hifi_filter_enabled(adev, out, snd_device,
8744+
my_data->codec_variant, channels, 0)) {
8745+
switch (sample_rate) {
8746+
case 48000:
8747+
audio_extn_enable_hifi_filter(adev, true);
8748+
if (audio_is_true_native_stream_active(adev))
8749+
sample_rate = 352800;
8750+
else
8751+
sample_rate = 384000;
8752+
bit_width = 32;
8753+
break;
8754+
case 44100:
8755+
audio_extn_enable_hifi_filter(adev, true);
8756+
sample_rate = 352800;
8757+
bit_width = 32;
8758+
break;
8759+
default:
8760+
audio_extn_enable_hifi_filter(adev, false);
8761+
}
8762+
}
8763+
if (snd_device != SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER)
8764+
audio_extn_enable_hifi_filter(adev, false);
8765+
ALOGD("%s:becf: updated afe: bitwidth %d, samplerate %d channels %d,"
8766+
"backend_idx %d usecase = %d device (%s)", __func__, bit_width,
8767+
sample_rate, channels, backend_idx, usecase->id,
8768+
platform_get_snd_device_name(snd_device));
8769+
}
8770+
87048771
/*
87058772
* Handset and speaker may have diffrent backend. Check if the device is speaker or handset,
87068773
* and these devices are restricited to 48kHz.
@@ -8813,7 +8880,7 @@ static bool platform_check_codec_backend_cfg(struct audio_device* adev,
88138880
}
88148881

88158882
if (snd_device == SND_DEVICE_OUT_HEADPHONES || snd_device ==
8816-
SND_DEVICE_OUT_HEADPHONES_44_1) {
8883+
SND_DEVICE_OUT_HEADPHONES_44_1 || snd_device == SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER) {
88178884
if (sample_rate > 48000 ||
88188885
(bit_width >= 24 && (sample_rate == 48000 || sample_rate == 44100))) {
88198886
ALOGI("%s: apply HPH HQ mode\n", __func__);

hal/msm8974/platform.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ enum {
9292
SND_DEVICE_OUT_LINE,
9393
SND_DEVICE_OUT_HEADPHONES,
9494
SND_DEVICE_OUT_HEADPHONES_DSD,
95+
SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER,
9596
SND_DEVICE_OUT_HEADPHONES_44_1,
9697
SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES,
98+
SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_HIFI_FILTER,
9799
SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES,
98100
SND_DEVICE_OUT_SPEAKER_AND_LINE,
99101
SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE,

0 commit comments

Comments
 (0)