int offload_eq_send_params(struct mixer_ctl *ctl, struct eq_params eq, unsigned param_send_flags) { int param_values[128] = {0}; int *p_param_values = param_values; uint32_t i; ALOGV("%s: flags 0x%x", __func__, param_send_flags); if ((eq.config.preset_id < -1) || ((param_send_flags & OFFLOAD_SEND_EQ_PRESET) && (eq.config.preset_id == -1))) { ALOGV("No Valid preset to set"); return 0; } *p_param_values++ = EQ_MODULE; *p_param_values++ = eq.device; *p_param_values++ = 0; /* num of commands*/ if (param_send_flags & OFFLOAD_SEND_EQ_ENABLE_FLAG) { *p_param_values++ = EQ_ENABLE; *p_param_values++ = CONFIG_SET; *p_param_values++ = 0; /* start offset if param size if greater than 128 */ *p_param_values++ = EQ_ENABLE_PARAM_LEN; *p_param_values++ = eq.enable_flag; param_values[2] += 1; } if (param_send_flags & OFFLOAD_SEND_EQ_PRESET) { *p_param_values++ = EQ_CONFIG; *p_param_values++ = CONFIG_SET; *p_param_values++ = 0; /* start offset if param size if greater than 128 */ *p_param_values++ = EQ_CONFIG_PARAM_LEN; *p_param_values++ = eq.config.eq_pregain; *p_param_values++ = map_eq_opensl_preset_2_offload_preset[eq.config.preset_id]; *p_param_values++ = 0; param_values[2] += 1; } if (param_send_flags & OFFLOAD_SEND_EQ_BANDS_LEVEL) { *p_param_values++ = EQ_CONFIG; *p_param_values++ = CONFIG_SET; *p_param_values++ = 0; /* start offset if param size if greater than 128 */ *p_param_values++ = EQ_CONFIG_PARAM_LEN + eq.config.num_bands * EQ_CONFIG_PER_BAND_PARAM_LEN; *p_param_values++ = eq.config.eq_pregain; *p_param_values++ = CUSTOM_OPENSL_PRESET; *p_param_values++ = eq.config.num_bands; for (i=0; i<eq.config.num_bands; i++) { *p_param_values++ = eq.per_band_cfg[i].band_idx; *p_param_values++ = eq.per_band_cfg[i].filter_type; *p_param_values++ = eq.per_band_cfg[i].freq_millihertz; *p_param_values++ = eq.per_band_cfg[i].gain_millibels; *p_param_values++ = eq.per_band_cfg[i].quality_factor; } param_values[2] += 1; } if (param_values[2] && ctl) mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values)); return 0; }
int TinyAmixerControlArray::doSetArrayMixer(struct mixer_ctl *mixerControl, const void *array, size_t elementCount) { if (isDebugEnabled()) { logControlValues(false, array, elementCount); } return mixer_ctl_set_array(mixerControl, array, elementCount); }
int offload_virtualizer_send_params(struct mixer_ctl *ctl, struct virtualizer_params virtualizer, unsigned param_send_flags) { int param_values[128] = {0}; int *p_param_values = param_values; ALOGV("%s: flags 0x%x", __func__, param_send_flags); *p_param_values++ = VIRTUALIZER_MODULE; *p_param_values++ = virtualizer.device; *p_param_values++ = 0; /* num of commands*/ if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG) { *p_param_values++ = VIRTUALIZER_ENABLE; *p_param_values++ = CONFIG_SET; *p_param_values++ = 0; /* start offset if param size if greater than 128 */ *p_param_values++ = VIRTUALIZER_ENABLE_PARAM_LEN; *p_param_values++ = virtualizer.enable_flag; param_values[2] += 1; } if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_STRENGTH) { *p_param_values++ = VIRTUALIZER_STRENGTH; *p_param_values++ = CONFIG_SET; *p_param_values++ = 0; /* start offset if param size if greater than 128 */ *p_param_values++ = VIRTUALIZER_STRENGTH_PARAM_LEN; *p_param_values++ = virtualizer.strength; param_values[2] += 1; } if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_OUT_TYPE) { *p_param_values++ = VIRTUALIZER_OUT_TYPE; *p_param_values++ = CONFIG_SET; *p_param_values++ = 0; /* start offset if param size if greater than 128 */ *p_param_values++ = VIRTUALIZER_OUT_TYPE_PARAM_LEN; *p_param_values++ = virtualizer.out_type; param_values[2] += 1; } if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_GAIN_ADJUST) { *p_param_values++ = VIRTUALIZER_GAIN_ADJUST; *p_param_values++ = CONFIG_SET; *p_param_values++ = 0; /* start offset if param size if greater than 128 */ *p_param_values++ = VIRTUALIZER_GAIN_ADJUST_PARAM_LEN; *p_param_values++ = virtualizer.gain_adjust; param_values[2] += 1; } if (param_values[2] && ctl) mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values)); return 0; }
static void tinymix_set_byte_ctl(struct mixer_ctl *ctl, char **values, unsigned int num_values) { int ret; char *buf; char *end; unsigned int i; long n; buf = calloc(1, num_values); if (buf == NULL) { fprintf(stderr, "set_byte_ctl: Failed to alloc mem for bytes %d\n", num_values); exit(EXIT_FAILURE); } for (i = 0; i < num_values; i++) { errno = 0; n = strtol(values[i], &end, 0); if (*end) { fprintf(stderr, "%s not an integer\n", values[i]); goto fail; } if (errno) { fprintf(stderr, "strtol: %s: %s\n", values[i], strerror(errno)); goto fail; } if (n < 0 || n > 0xff) { fprintf(stderr, "%s should be between [0, 0xff]\n", values[i]); goto fail; } buf[i] = n; } ret = mixer_ctl_set_array(ctl, buf, num_values); if (ret < 0) { fprintf(stderr, "Failed to set binary control\n"); goto fail; } free(buf); return; fail: free(buf); exit(EXIT_FAILURE); }
static void send_app_type_cfg(void *platform, struct mixer *mixer, struct listnode *streams_output_cfg_list) { int app_type_cfg[MAX_LENGTH_MIXER_CONTROL_IN_INT] = {-1}; int length = 0, i, num_app_types = 0; struct listnode *node; bool update; struct mixer_ctl *ctl = NULL; const char *mixer_ctl_name = "App Type Config"; struct streams_output_cfg *so_info; if (!mixer) { ALOGE("%s: mixer is null",__func__); return; } ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name); if (!ctl) { ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name); return; } if (streams_output_cfg_list == NULL) { app_type_cfg[length++] = 1; app_type_cfg[length++] = platform_get_default_app_type(platform); app_type_cfg[length++] = 48000; app_type_cfg[length++] = 16; mixer_ctl_set_array(ctl, app_type_cfg, length); return; } app_type_cfg[length++] = num_app_types; list_for_each(node, streams_output_cfg_list) { so_info = node_to_item(node, struct streams_output_cfg, list); update = true; for (i=0; i<length; i=i+3) { if (app_type_cfg[i+1] == -1) break; else if (app_type_cfg[i+1] == so_info->app_type_cfg.app_type) { update = false; break; } } if (update && ((length + 3) <= MAX_LENGTH_MIXER_CONTROL_IN_INT)) { num_app_types += 1 ; app_type_cfg[length++] = so_info->app_type_cfg.app_type; app_type_cfg[length++] = so_info->app_type_cfg.sample_rate; app_type_cfg[length++] = so_info->app_type_cfg.bit_width; } }
static int set_stream_app_type_mixer_ctrl(struct audio_device *adev, int pcm_device_id, int app_type, int acdb_dev_id, int sample_rate, int stream_type, snd_device_t snd_device) { char mixer_ctl_name[MAX_LENGTH_MIXER_CONTROL_IN_INT]; struct mixer_ctl *ctl; int app_type_cfg[MAX_LENGTH_MIXER_CONTROL_IN_INT], len = 0, rc = 0; int snd_device_be_idx = -1; if (stream_type == PCM_PLAYBACK) { snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), "Audio Stream %d App Type Cfg", pcm_device_id); } else if (stream_type == PCM_CAPTURE) { snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), "Audio Stream Capture %d App Type Cfg", pcm_device_id); } ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); if (!ctl) { ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, mixer_ctl_name); rc = -EINVAL; goto exit; } app_type_cfg[len++] = app_type; app_type_cfg[len++] = acdb_dev_id; app_type_cfg[len++] = sample_rate; snd_device_be_idx = platform_get_snd_device_backend_index(snd_device); if (snd_device_be_idx > 0) app_type_cfg[len++] = snd_device_be_idx; ALOGV("%s: stream type %d app_type %d, acdb_dev_id %d " "sample rate %d, snd_device_be_idx %d", __func__, stream_type, app_type, acdb_dev_id, sample_rate, snd_device_be_idx); mixer_ctl_set_array(ctl, app_type_cfg, len); exit: return rc; }
int offload_bassboost_send_params(struct mixer_ctl *ctl, struct bass_boost_params bassboost, unsigned param_send_flags) { int param_values[128] = {0}; int *p_param_values = param_values; ALOGV("%s: flags 0x%x", __func__, param_send_flags); *p_param_values++ = BASS_BOOST_MODULE; *p_param_values++ = bassboost.device; *p_param_values++ = 0; /* num of commands*/ if (param_send_flags & OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG) { *p_param_values++ = BASS_BOOST_ENABLE; *p_param_values++ = CONFIG_SET; *p_param_values++ = 0; /* start offset if param size if greater than 128 */ *p_param_values++ = BASS_BOOST_ENABLE_PARAM_LEN; *p_param_values++ = bassboost.enable_flag; param_values[2] += 1; } if (param_send_flags & OFFLOAD_SEND_BASSBOOST_STRENGTH) { *p_param_values++ = BASS_BOOST_STRENGTH; *p_param_values++ = CONFIG_SET; *p_param_values++ = 0; /* start offset if param size if greater than 128 */ *p_param_values++ = BASS_BOOST_STRENGTH_PARAM_LEN; *p_param_values++ = bassboost.strength; param_values[2] += 1; } if (param_send_flags & OFFLOAD_SEND_BASSBOOST_MODE) { *p_param_values++ = BASS_BOOST_MODE; *p_param_values++ = CONFIG_SET; *p_param_values++ = 0; /* start offset if param size if greater than 128 */ *p_param_values++ = BASS_BOOST_MODE_PARAM_LEN; *p_param_values++ = bassboost.mode; param_values[2] += 1; } if (param_values[2] && ctl) mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values)); return 0; }
static void tinymix_set_byte_ctl(struct mixer_ctl *ctl, const char *control, char **values, unsigned int num_values) { int ret; char buf[512] = { 0 }; char *end; int i; long n; if (num_values > sizeof(buf)) { fprintf(stderr, "Truncating set to %zu bytes\n", sizeof(buf)); num_values = sizeof(buf); } for (i = 0; i < num_values; i++) { errno = 0; n = strtol(values[i], &end, 0); if (*end) { fprintf(stderr, "%s not an integer\n", values[i]); exit(EXIT_FAILURE); } if (errno) { fprintf(stderr, "strtol: %s: %s\n", values[i], strerror(errno)); exit(EXIT_FAILURE); } if (n < 0 || n > 0xff) { fprintf(stderr, "%s should be between [0, 0xff]\n", values[i]); exit(EXIT_FAILURE); } buf[i] = n; } ret = mixer_ctl_set_array(ctl, buf, num_values); if (ret < 0) { fprintf(stderr, "Failed to set binary control\n"); exit(EXIT_FAILURE); } }
void audio_extn_utils_send_default_app_type_cfg(void *platform, struct mixer *mixer) { int app_type_cfg[MAX_LENGTH_MIXER_CONTROL_IN_INT] = {-1}; int length = 0, app_type = 0,rc = 0; struct mixer_ctl *ctl = NULL; const char *mixer_ctl_name = "App Type Config"; ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name); if (!ctl) { ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name); return; } rc = platform_get_default_app_type_v2(platform, PCM_PLAYBACK, &app_type); if (rc == 0) { app_type_cfg[length++] = 1; app_type_cfg[length++] = app_type; app_type_cfg[length++] = 48000; app_type_cfg[length++] = 16; mixer_ctl_set_array(ctl, app_type_cfg, length); } return; }
/* Update the mixer with any changed values */ int audio_route_update_mixer(struct audio_route *ar) { unsigned int i; unsigned int j; struct mixer_ctl *ctl; for (i = 0; i < ar->num_mixer_ctls; i++) { unsigned int num_values = ar->mixer_state[i].num_values; enum mixer_ctl_type type; ctl = ar->mixer_state[i].ctl; /* Skip unsupported types */ type = mixer_ctl_get_type(ctl); if ((type != MIXER_CTL_TYPE_BOOL) && (type != MIXER_CTL_TYPE_INT) && (type != MIXER_CTL_TYPE_ENUM)) continue; /* if the value has changed, update the mixer */ bool changed = false; for (j = 0; j < num_values; j++) { if (ar->mixer_state[i].old_value[j] != ar->mixer_state[i].new_value[j]) { changed = true; break; } } if (changed) { if (type == MIXER_CTL_TYPE_ENUM) mixer_ctl_set_value(ctl, 0, ar->mixer_state[i].new_value[0]); else mixer_ctl_set_array(ctl, ar->mixer_state[i].new_value, num_values); memcpy(ar->mixer_state[i].old_value, ar->mixer_state[i].new_value, num_values * sizeof(int)); } } return 0; }
static void tinymix_set_byte_ctl(struct mixer_ctl *ctl, char **values, unsigned int num_values) { int ret; char *buf; char *end; unsigned int i; long n; unsigned int *tlv, tlv_size; unsigned int tlv_header_size = 0; if (mixer_ctl_is_access_tlv_rw(ctl) != 0) { tlv_header_size = TLV_HEADER_SIZE; } tlv_size = num_values + tlv_header_size; buf = calloc(1, tlv_size); if (buf == NULL) { fprintf(stderr, "set_byte_ctl: Failed to alloc mem for bytes %u\n", num_values); exit(EXIT_FAILURE); } tlv = (unsigned int *)buf; tlv[0] = 0; tlv[1] = num_values; for (i = 0; i < num_values; i++) { errno = 0; n = strtol(values[i], &end, 0); if (*end) { fprintf(stderr, "%s not an integer\n", values[i]); goto fail; } if (errno) { fprintf(stderr, "strtol: %s: %s\n", values[i], strerror(errno)); goto fail; } if (n < 0 || n > 0xff) { fprintf(stderr, "%s should be between [0, 0xff]\n", values[i]); goto fail; } /* start filling after tlv header */ buf[i + tlv_header_size] = n; } ret = mixer_ctl_set_array(ctl, buf, tlv_size); if (ret < 0) { fprintf(stderr, "Failed to set binary control\n"); goto fail; } free(buf); return; fail: free(buf); exit(EXIT_FAILURE); }
int offload_reverb_send_params(struct mixer_ctl *ctl, struct reverb_params reverb, unsigned param_send_flags) { int param_values[128] = {0}; int *p_param_values = param_values; ALOGV("%s: flags 0x%x", __func__, param_send_flags); *p_param_values++ = REVERB_MODULE; *p_param_values++ = reverb.device; *p_param_values++ = 0; /* num of commands*/ if (param_send_flags & OFFLOAD_SEND_REVERB_ENABLE_FLAG) { *p_param_values++ = REVERB_ENABLE; *p_param_values++ = CONFIG_SET; *p_param_values++ = 0; /* start offset if param size if greater than 128 */ *p_param_values++ = REVERB_ENABLE_PARAM_LEN; *p_param_values++ = reverb.enable_flag; param_values[2] += 1; } if (param_send_flags & OFFLOAD_SEND_REVERB_MODE) { *p_param_values++ = REVERB_MODE; *p_param_values++ = CONFIG_SET; *p_param_values++ = 0; /* start offset if param size if greater than 128 */ *p_param_values++ = REVERB_MODE_PARAM_LEN; *p_param_values++ = reverb.mode; param_values[2] += 1; } if (param_send_flags & OFFLOAD_SEND_REVERB_PRESET) { *p_param_values++ = REVERB_PRESET; *p_param_values++ = CONFIG_SET; *p_param_values++ = 0; /* start offset if param size if greater than 128 */ *p_param_values++ = REVERB_PRESET_PARAM_LEN; *p_param_values++ = reverb.preset; param_values[2] += 1; } if (param_send_flags & OFFLOAD_SEND_REVERB_WET_MIX) { *p_param_values++ = REVERB_WET_MIX; *p_param_values++ = CONFIG_SET; *p_param_values++ = 0; /* start offset if param size if greater than 128 */ *p_param_values++ = REVERB_WET_MIX_PARAM_LEN; *p_param_values++ = reverb.wet_mix; param_values[2] += 1; } if (param_send_flags & OFFLOAD_SEND_REVERB_GAIN_ADJUST) { *p_param_values++ = REVERB_GAIN_ADJUST; *p_param_values++ = CONFIG_SET; *p_param_values++ = 0; /* start offset if param size if greater than 128 */ *p_param_values++ = REVERB_GAIN_ADJUST_PARAM_LEN; *p_param_values++ = reverb.gain_adjust; param_values[2] += 1; } if (param_send_flags & OFFLOAD_SEND_REVERB_ROOM_LEVEL) { *p_param_values++ = REVERB_ROOM_LEVEL; *p_param_values++ = CONFIG_SET; *p_param_values++ = 0; /* start offset if param size if greater than 128 */ *p_param_values++ = REVERB_ROOM_LEVEL_PARAM_LEN; *p_param_values++ = reverb.room_level; param_values[2] += 1; } if (param_send_flags & OFFLOAD_SEND_REVERB_ROOM_HF_LEVEL) { *p_param_values++ = REVERB_ROOM_HF_LEVEL; *p_param_values++ = CONFIG_SET; *p_param_values++ = 0; /* start offset if param size if greater than 128 */ *p_param_values++ = REVERB_ROOM_HF_LEVEL_PARAM_LEN; *p_param_values++ = reverb.room_hf_level; param_values[2] += 1; } if (param_send_flags & OFFLOAD_SEND_REVERB_DECAY_TIME) { *p_param_values++ = REVERB_DECAY_TIME; *p_param_values++ = CONFIG_SET; *p_param_values++ = 0; /* start offset if param size if greater than 128 */ *p_param_values++ = REVERB_DECAY_TIME_PARAM_LEN; *p_param_values++ = reverb.decay_time; param_values[2] += 1; } if (param_send_flags & OFFLOAD_SEND_REVERB_DECAY_HF_RATIO) { *p_param_values++ = REVERB_DECAY_HF_RATIO; *p_param_values++ = CONFIG_SET; *p_param_values++ = 0; /* start offset if param size if greater than 128 */ *p_param_values++ = REVERB_DECAY_HF_RATIO_PARAM_LEN; *p_param_values++ = reverb.decay_hf_ratio; param_values[2] += 1; } if (param_send_flags & OFFLOAD_SEND_REVERB_REFLECTIONS_LEVEL) { *p_param_values++ = REVERB_REFLECTIONS_LEVEL; *p_param_values++ = CONFIG_SET; *p_param_values++ = 0; /* start offset if param size if greater than 128 */ *p_param_values++ = REVERB_REFLECTIONS_LEVEL_PARAM_LEN; *p_param_values++ = reverb.reflections_level; param_values[2] += 1; } if (param_send_flags & OFFLOAD_SEND_REVERB_REFLECTIONS_DELAY) { *p_param_values++ = REVERB_REFLECTIONS_DELAY; *p_param_values++ = CONFIG_SET; *p_param_values++ = 0; /* start offset if param size if greater than 128 */ *p_param_values++ = REVERB_REFLECTIONS_DELAY_PARAM_LEN; *p_param_values++ = reverb.reflections_delay; param_values[2] += 1; } if (param_send_flags & OFFLOAD_SEND_REVERB_LEVEL) { *p_param_values++ = REVERB_LEVEL; *p_param_values++ = CONFIG_SET; *p_param_values++ = 0; /* start offset if param size if greater than 128 */ *p_param_values++ = REVERB_LEVEL_PARAM_LEN; *p_param_values++ = reverb.level; param_values[2] += 1; } if (param_send_flags & OFFLOAD_SEND_REVERB_DELAY) { *p_param_values++ = REVERB_DELAY; *p_param_values++ = CONFIG_SET; *p_param_values++ = 0; /* start offset if param size if greater than 128 */ *p_param_values++ = REVERB_DELAY_PARAM_LEN; *p_param_values++ = reverb.delay; param_values[2] += 1; } if (param_send_flags & OFFLOAD_SEND_REVERB_DIFFUSION) { *p_param_values++ = REVERB_DIFFUSION; *p_param_values++ = CONFIG_SET; *p_param_values++ = 0; /* start offset if param size if greater than 128 */ *p_param_values++ = REVERB_DIFFUSION_PARAM_LEN; *p_param_values++ = reverb.diffusion; param_values[2] += 1; } if (param_send_flags & OFFLOAD_SEND_REVERB_DENSITY) { *p_param_values++ = REVERB_DENSITY; *p_param_values++ = CONFIG_SET; *p_param_values++ = 0; /* start offset if param size if greater than 128 */ *p_param_values++ = REVERB_DENSITY_PARAM_LEN; *p_param_values++ = reverb.density; param_values[2] += 1; } if (param_values[2] && ctl) mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values)); return 0; }