static void tinymix_set_value(struct mixer *mixer, char *name, char *value) { struct mixer_ctl *ctl; enum mixer_ctl_type type; unsigned int i, num_values; ctl = mixer_get_ctl_by_name(mixer, name); if(!ctl) { log_err("cannot find control \'%s\'", name); return; } type = mixer_ctl_get_type(ctl); num_values = mixer_ctl_get_num_values(ctl); if(isdigit(value[0])) { int val = atoi(value); for(i = 0; i < num_values; i++) { if(mixer_ctl_set_value(ctl, i, val)) { log_err("value %d not accepted for %s", val, name); return; } } } else if(type == MIXER_CTL_TYPE_ENUM) { if(mixer_ctl_set_enum_by_string(ctl, value)) log_err("value %s not accepted for %s", value, name); } else if(type == MIXER_CTL_TYPE_BOOL) { if(strcasecmp(value,"on") == 0) i = 1; else if(strcasecmp(value, "off") == 0) i = 0; else { log_err("cannot set %s to \'%s\', on/off or 1/0 expected", name, value); return; } if(mixer_ctl_set_value(ctl, 0, i)) log_err("value %d not accepted for %s", i, name); } else log_err("type mismatch for %s, ignored", name); }
int mixer_cache_apply(struct audio_tool_mixer_cache *cache, struct mixer *mixer) { struct audio_tool_mixer_control_info *cur; struct mixer_ctl *ctl; int n, k, ret=0; for (n = 0 ; n < cache->count ; ++n) { cur = &cache->ctrls[n]; ctl = mixer_get_ctl(mixer, n); for (k = 0 ; k < cur->num_values ; ++k) { switch (cur->type) { case MIXER_CTL_TYPE_BOOL: case MIXER_CTL_TYPE_INT: mixer_ctl_set_value(ctl, k, cur->value.integer[k]); break; case MIXER_CTL_TYPE_ENUM: mixer_ctl_set_enum_by_string(ctl, cur->value.enumerated[k]); break; case MIXER_CTL_TYPE_BYTE: mixer_ctl_set_value(ctl, k, cur->value.byte[k]); break; case MIXER_CTL_TYPE_INT64: mixer_ctl_set_value(ctl, k, cur->value.integer64[k]); break; default: ret = 1; } } } return ret; }
static int adev_set_master_volume(struct audio_hw_device *dev, float volume) { #if 0 //TARGET_AUDIO_PRIMARY struct mixer *mixer; struct mixer_ctl *ctl; struct audio_device * adev = (struct audio_device *)dev; if ((0 > volume) || (1 < volume) || (NULL == adev)) return -EINVAL; pthread_mutex_lock(&adev->lock); adev->master_volume = (int)(volume*100); if (!(mixer = mixer_open(0))) { pthread_mutex_unlock(&adev->lock); return -ENOSYS; } ctl = mixer_get_ctl_by_name(mixer, "HP Playback Volume"); mixer_ctl_set_value(ctl,0,adjust_volume(adev->master_volume)); mixer_ctl_set_value(ctl,1,adjust_volume(adev->master_volume)); mixer_close(mixer); pthread_mutex_unlock(&adev->lock); return 0; #else return -ENOSYS; #endif }
static void tinymix_set_value(struct mixer *mixer, const char *control, char **values, unsigned int num_values) { struct mixer_ctl *ctl; enum mixer_ctl_type type; unsigned int num_ctl_values; unsigned int i; if (isdigit(control[0])) ctl = mixer_get_ctl(mixer, atoi(control)); else ctl = mixer_get_ctl_by_name(mixer, control); if (!ctl) { fprintf(stderr, "Invalid mixer control\n"); return; } type = mixer_ctl_get_type(ctl); num_ctl_values = mixer_ctl_get_num_values(ctl); if (isdigit(values[0][0])) { if (num_values == 1) { /* Set all values the same */ int value = atoi(values[0]); for (i = 0; i < num_ctl_values; i++) { if (mixer_ctl_set_value(ctl, i, value)) { fprintf(stderr, "Error: invalid value\n"); return; } } } else { /* Set multiple values */ if (num_values > num_ctl_values) { fprintf(stderr, "Error: %d values given, but control only takes %d\n", num_values, num_ctl_values); return; } for (i = 0; i < num_values; i++) { if (mixer_ctl_set_value(ctl, i, atoi(values[i]))) { fprintf(stderr, "Error: invalid value for index %d\n", i); return; } } } } else { if (type == MIXER_CTL_TYPE_ENUM) { if (num_values != 1) { fprintf(stderr, "Enclose strings in quotes and try again\n"); return; } if (mixer_ctl_set_enum_by_string(ctl, values[0])) fprintf(stderr, "Error: invalid enum value\n"); } else { fprintf(stderr, "Error: only enum types can be set with strings\n"); } } }
static int set_normal_record_enable(struct codec_client *client, bool enable) { mixer_ctl_set_value(client->mixer_ctls->audio_fm_record, 0, 0); mixer_ctl_set_value(client->mixer_ctls->audio_phone_voice_record, 0, 0); ALOGV("normal record mode 4,****LINE:%d,FUNC:%s",__LINE__,__FUNCTION__); return 0; }
static int set_fm_volume(struct codec_client *client, int path, int volume) { int speaker_on=0,headset_on=0 ,headphone_on=0; int level; headset_on = path & AUDIO_DEVICE_OUT_WIRED_HEADSET; // hp4p headphone_on = path & AUDIO_DEVICE_OUT_WIRED_HEADPHONE; // hp3p speaker_on = path & AUDIO_DEVICE_OUT_SPEAKER; if (volume >= 10) { level = 5; } else if (volume >= 8){ level = 4; } else if (volume >= 6){ level = 3; } else if (volume >= 4){ level = 2; } else if (volume >= 2){ level = 1; } else { level = 0; } if (speaker_on){ mixer_ctl_set_value(client->mixer_ctls->linein_g_boost_stage_output_mixer_control, 0, client->vol_array->fm_speaker_line_gain[level]); mixer_ctl_set_value(client->mixer_ctls->lineout_volume_control, 0, client->vol_array->fm_speaker_spk_gain[level]); } else { mixer_ctl_set_value(client->mixer_ctls->linein_g_boost_stage_output_mixer_control, 0, client->vol_array->fm_headset_line_gain[level]); mixer_ctl_set_value(client->mixer_ctls->master_playback_volume, 0, client->vol_array->fm_headset_hp_gain[level]); } ALOGV("4 set fm , adev_set_voice_volume, volume: %d, level=%d", volume, level); return 0; }
void mixer_ctl_set(struct mixer *mixer, const char *name, int val) { struct mixer_ctl *ctl = mixer_get_ctl_by_name(mixer, name); int ret = mixer_ctl_set_value(ctl, 0, val); if (ret != 0) LOGE("Failed to set %s to %d\n", name, val); mixer_ctl_set_value(ctl, 1, val); }
static int set_fm_record_enable(struct codec_client *client, bool enable) { mixer_ctl_set_value(client->mixer_ctls->audio_phone_voice_record, 0, 0); if (enable){ mixer_ctl_set_value(client->mixer_ctls->audio_linein_record, 0, 1); } else { mixer_ctl_set_value(client->mixer_ctls->audio_linein_record, 0, 0); } ALOGV("fm record mode 4,****LINE:%d,FUNC:%s",__LINE__,__FUNCTION__); return 0; }
static int SetAudio_gain_4eng(struct audio_pga *pga, pga_gain_nv_t *pga_gain_nv, AUDIO_TOTAL_T *aud_params_ptr) { int card_id = 0; int32_t lmode = 0; struct mixer *mixer = NULL; struct mixer_ctl *pa_config_ctl = NULL; ALOGD("vb_pga.c %s", __func__); if((NULL == aud_params_ptr) || (NULL == pga_gain_nv) || (NULL == pga)){ ALOGE("%s aud_params_ptr or pga_gain_nv or audio_pga is NULL",__func__); return -1; } card_id = get_snd_card_number(CARD_SPRDPHONE); if (card_id < 0){ ALOGE("%s get_snd_card_number error(%d)",__func__,card_id); return -1; } mixer = mixer_open(card_id); if (!mixer) { ALOGE("%s Unable to open the mixer, aborting.",__func__); return -1; } pa_config_ctl = mixer_get_ctl_by_name(mixer, MIXER_CTL_INNER_PA_CONFIG); lmode = GetAudio_mode_number_from_nv(aud_params_ptr); ALOGD("vb_pga.c %s, mode: %d", __func__, lmode); if(0 == lmode){ //Headset audio_pga_apply(pga,pga_gain_nv->fm_pga_gain_l,"linein-hp-l"); audio_pga_apply(pga,pga_gain_nv->fm_pga_gain_r,"linein-hp-r"); audio_pga_apply(pga,pga_gain_nv->dac_pga_gain_l,"headphone-l"); audio_pga_apply(pga,pga_gain_nv->dac_pga_gain_r,"headphone-r"); audio_pga_apply(pga,pga_gain_nv->adc_pga_gain_l,"capture-l"); audio_pga_apply(pga,pga_gain_nv->adc_pga_gain_r,"capture-r"); }else if(1 == lmode){ //Headfree audio_pga_apply(pga,pga_gain_nv->dac_pga_gain_l,"headphone-spk-l"); audio_pga_apply(pga,pga_gain_nv->dac_pga_gain_r,"headphone-spk-r"); mixer_ctl_set_value(pa_config_ctl, 0, pga_gain_nv->pa_config); }else if(2 == lmode){ //Handset audio_pga_apply(pga,pga_gain_nv->dac_pga_gain_l,"earpiece"); audio_pga_apply(pga,pga_gain_nv->adc_pga_gain_l,"capture-l"); audio_pga_apply(pga,pga_gain_nv->adc_pga_gain_r,"capture-r"); }else if(3 == lmode){ //Handsfree audio_pga_apply(pga,pga_gain_nv->fm_pga_gain_l,"linein-spk-l"); audio_pga_apply(pga,pga_gain_nv->fm_pga_gain_r,"linein-spk-r"); audio_pga_apply(pga,pga_gain_nv->dac_pga_gain_l,"speaker-l"); audio_pga_apply(pga,pga_gain_nv->dac_pga_gain_r,"speaker-r"); mixer_ctl_set_value(pa_config_ctl, 0, pga_gain_nv->pa_config); audio_pga_apply(pga,pga_gain_nv->adc_pga_gain_l,"capture-l"); audio_pga_apply(pga,pga_gain_nv->adc_pga_gain_r,"capture-r"); } mixer_close(mixer); ALOGW("%s, set cp mode(0x%x) ",__func__,lmode); return 0; }
static int set_phone_volume(struct codec_client *client, int path, int volume) { int level; int speaker_on=0,headset_on=0 ,headphone_on=0,earpiece_on=0; int speaker_vol=0, headset_vol=0, earpiece_vol=0; speaker_on = path & AUDIO_DEVICE_OUT_SPEAKER; headset_on = path & AUDIO_DEVICE_OUT_WIRED_HEADSET; // with mic headphone_on = path & AUDIO_DEVICE_OUT_WIRED_HEADPHONE; // no mic earpiece_on = path & AUDIO_DEVICE_OUT_EARPIECE; if (volume >= 10) { level = 5; } else if (volume >= 8){ level = 4; } else if (volume >= 6){ level = 3; } else if (volume >= 4){ level = 2; } else if (volume >= 2){ level = 1; } else { level = 0; } ALOGD("adev_set_voice_volume, speaker_on: %d, earpiece_on: %d, headset_on: %d", speaker_on ,earpiece_on, headset_on); ALOGD("adev_set_voice_volume, volume:%d, level: %d", volume, level); if (speaker_on || (earpiece_on && (no_earpiece == 1))){ //mixer_ctl_set_value(client->mixer_ctls->phonep_phonen_pre_amp_gain_control, 0, client->vol_array->speaker_phonepn_gain[level]); //mixer_ctl_set_value(client->mixer_ctls->phone_g_boost_stage_output_mixer_control, 0, client->vol_array->speaker_mixer_gain[level]); mixer_ctl_set_value(client->mixer_ctls->speaker_volume_control, 0, client->vol_array->speaker_spk_gain[level]); //set_headphone_volume(client->mixer_ctls->lineout_volume_control,client->vol_array->speaker_spk_gain[level]); ALOGD("adev_set_voice_volume, speaker volume:%d ", client->vol_array->speaker_spk_gain[level]); } else if (earpiece_on && (no_earpiece == 0) ){ //mixer_ctl_set_value(client->mixer_ctls->phonep_phonen_pre_amp_gain_control, 0, client->vol_array->earpiece_phonepn_gain[level]); //mixer_ctl_set_value(client->mixer_ctls->phone_g_boost_stage_output_mixer_control, 0, client->vol_array->earpiece_mixer_gain[level]); mixer_ctl_set_value(client->mixer_ctls->earpiece_volume_control, 0, client->vol_array->earpiece_hp_gain[level]); //set_headphone_volume(client->mixer_ctls->master_playback_volume, client->vol_array->earpiece_hp_gain[level]); ALOGD("adev_set_voice_volume, earpiece volume:%d ", client->vol_array->earpiece_hp_gain[level]); } else if (headset_on || headphone_on){ //mixer_ctl_set_value(client->mixer_ctls->phonep_phonen_pre_amp_gain_control, 0, client->vol_array->headset_phonepn_gain[level]); //mixer_ctl_set_value(client->mixer_ctls->phone_g_boost_stage_output_mixer_control, 0, client->vol_array->headset_mixer_gain[level]); mixer_ctl_set_value(client->mixer_ctls->headphone_volume_control, 0, client->vol_array->headset_hp_gain[level]); //set_headphone_volume(client->mixer_ctls->master_playback_volume,client->vol_array->headset_hp_gain[level]); ALOGD("adev_set_voice_volume, headset volume:%d ", client->vol_array->headset_hp_gain[level]); } return 0; }
static int set_factory_path(struct codec_client *client, int path) { mixer_ctl_set_value(client->mixer_ctls->audio_phone_end_call, 0, 1); mixer_ctl_set_value(client->mixer_ctls->audio_linein_in, 0, 1); #if 0 if (g_is_bp_thread_running == false){ plan_two_start_voice(); g_is_bp_thread_running = true; } #endif if(no_earpiece == 0) { mixer_ctl_set_value(client->mixer_ctls->audio_analog_headsetmic, 0, 0); mixer_ctl_set_value(client->mixer_ctls->audio_analog_main_mic, 0, 1); mixer_ctl_set_enum_by_string(client->mixer_ctls->audio_spk_headset_switch, "earpiece");// "spk" : "headset"); ALOGV("in earpiece ****LINE:%d,FUNC:%s",__LINE__,__FUNCTION__); } else if(no_earpiece == 1) { mixer_ctl_set_value(client->mixer_ctls->audio_analog_headsetmic, 0, 0); mixer_ctl_set_value(client->mixer_ctls->audio_analog_main_mic, 0, 1); mixer_ctl_set_enum_by_string(client->mixer_ctls->audio_spk_headset_switch, "spk");// "spk" : "headset"); } mixer_ctl_set_value(client->mixer_ctls->headphone_volume_control, 0, 60); mixer_ctl_set_value(client->mixer_ctls->speaker_volume_control, 0, 30); //set_headphone_volume(client->mixer_ctls->master_playback_volume, 60); ALOGV("****LINE:%d,FUNC:%s",__LINE__,__FUNCTION__); return 0; }
static int set_fm_volume(struct codec_client *client, int path, int volume) { int speaker_on=0,headset_on=0 ,headphone_on=0; int speaker_vol=0, headset_vol=0; headset_on = path & AUDIO_DEVICE_OUT_WIRED_HEADSET; // hp4p headphone_on = path & AUDIO_DEVICE_OUT_WIRED_HEADPHONE; // hp3p speaker_on = path & AUDIO_DEVICE_OUT_SPEAKER; int val = 0; if (volume >= 10) { val = 7 ; speaker_vol = 25; headset_vol = 35; } else if (volume >= 8){ val = 6 ; speaker_vol = 25; headset_vol = 35; } else if (volume >= 6){ val = 5 ; speaker_vol = 25; headset_vol = 35; } else if (volume >= 4){ val = 4 ; speaker_vol = 25; headset_vol = 35; } else if (volume >= 2){ val = 3 ; speaker_vol = 25; headset_vol = 35; } else { val = 2 ; speaker_vol = 25; headset_vol = 35; } mixer_ctl_set_value(client->mixer_ctls->linein_g_boost_stage_output_mixer_control, 0, mixer_vol[val]); if (speaker_on){ mixer_ctl_set_value(client->mixer_ctls->lineout_volume_control, 0, spk_vol[val]); } else { mixer_ctl_set_value(client->mixer_ctls->master_playback_volume, 0, hp_vol[val]); } ALOGV("4 set fm , adev_set_voice_volume, volume: %d, val=%d", volume, val); return 0; }
int mixer_ctl_set_percent(struct mixer_ctl *ctl, unsigned int id, int percent) { if (!ctl || (ctl->info.type != SNDRV_CTL_ELEM_TYPE_INTEGER)) return -EINVAL; return mixer_ctl_set_value(ctl, id, percent_to_int(&ctl->info, percent)); }
static int set_clocks_enabled(bool enable) { enum mixer_ctl_type type; struct mixer_ctl *ctl; struct mixer *mixer = mixer_open(0); if (mixer == NULL) { ALOGE("Error opening mixer 0"); return -1; } ctl = mixer_get_ctl_by_name(mixer, AMP_MIXER_CTL); if (ctl == NULL) { mixer_close(mixer); ALOGE("%s: Could not find %s\n", __func__, AMP_MIXER_CTL); return -ENODEV; } type = mixer_ctl_get_type(ctl); if (type != MIXER_CTL_TYPE_ENUM) { ALOGE("%s: %s is not supported\n", __func__, AMP_MIXER_CTL); mixer_close(mixer); return -ENOTTY; } mixer_ctl_set_value(ctl, 0, enable); mixer_close(mixer); return 0; }
static void tinymix_set_value(struct mixer *mixer, unsigned int id, char *string) { struct mixer_ctl *ctl; enum mixer_ctl_type type; unsigned int num_values; unsigned int i; ctl = mixer_get_ctl(mixer, id); type = mixer_ctl_get_type(ctl); num_values = mixer_ctl_get_num_values(ctl); if (isdigit(string[0])) { int value = atoi(string); for (i = 0; i < num_values; i++) { if (mixer_ctl_set_value(ctl, i, value)) { fprintf(stderr, "Error: invalid value\n"); return; } } } else { if (type == MIXER_CTL_TYPE_ENUM) { if (mixer_ctl_set_enum_by_string(ctl, string)) fprintf(stderr, "Error: invalid enum value\n"); } else { fprintf(stderr, "Error: only enum types can be set with strings\n"); } } }
bool TinyAmixerControlValue::writeControl(struct mixer_ctl *mixerControl, size_t elementCount, std::string &error) { uint32_t elementNumber; // Write element // Go through all elements for (elementNumber = 0; elementNumber < elementCount; elementNumber++) { int32_t value; // Read data from blackboard (beware this code is OK on Little Endian machines only) value = fromBlackboard(); if (isDebugEnabled()) { info() << "Writing alsa element " << getControlName() << ", index " << elementNumber << " with value " << value; } // Write element int err; if ((err = mixer_ctl_set_value(mixerControl, elementNumber, value)) < 0) { error = "Failed to write value in mixer control: " + getControlName() + ": " + strerror(-err); return false; } } return true; }
void update_mixer_state(struct audio_route *ar) { unsigned int i; unsigned int j; if (!ar) { ALOGE("%s: invalid audio_route", __func__); return; } for (i = 0; i < ar->num_mixer_ctls; i++) { /* if the value has changed, update the mixer */ if (ar->mixer_state[i].old_value != ar->mixer_state[i].new_value) { if (!(ar->mixer_state[i].ignored)) { for (j = 0; j < ar->mixer_state[i].ctl_vals; j++) { #if 0 ALOGV("%s: '%s'[%u] -> %d", __func__, mixer_ctl_get_name(ar->mixer_state[i].ctl), j, ar->mixer_state[i].new_value[j]); #endif #if 0 mixer_ctl_set_value(ar->mixer_state[i].ctl, j, ar->mixer_state[i].new_value[j]); #endif ar->mixer_state[i].old_value[j] = ar->mixer_state[i].new_value[j]; } } } } }
static int set_normal_path(struct codec_client *client, int path) { int headset_on=0, headphone_on=0, speaker_on=0, earpiece_on=0; headset_on = path & AUDIO_DEVICE_OUT_WIRED_HEADSET; // hp4p headphone_on = path & AUDIO_DEVICE_OUT_WIRED_HEADPHONE; // hp3p speaker_on = path & AUDIO_DEVICE_OUT_SPEAKER; earpiece_on = path & AUDIO_DEVICE_OUT_EARPIECE; if (g_is_bp_thread_running){ g_is_bp_thread_running = false; plan_two_stop_voice(); mixer_ctl_set_value(client->mixer_ctls->audio_phone_end_call, 0, 1); } if(last_path_is_bt){ last_path_is_bt = false; plan_two_stop_bt_voice(); mixer_ctl_set_value(client->mixer_ctls->audio_phone_end_call, 0, 1); } if(wake_lock){ releaseWakeLock(); wake_lock=false; } mixer_ctl_set_value(client->mixer_ctls->audio_linein_in, 0, 0); //turn off fm if ((headset_on || headphone_on) && speaker_on){ ALOGV("in normal mode, headset and speaker on,****LINE:%d,FUNC:%s",__LINE__,__FUNCTION__); mixer_ctl_set_enum_by_string(client->mixer_ctls->audio_spk_headset_switch, "spk_headset"); } else if(earpiece_on && (no_earpiece!=1)) { mixer_ctl_set_enum_by_string(client->mixer_ctls->audio_spk_headset_switch, "earpiece");// "spk" : "headset"); ALOGV("in normal mode, earpiece on,****LINE:%d,FUNC:%s",__LINE__,__FUNCTION__); } else if(headset_on | headphone_on) { mixer_ctl_set_enum_by_string(client->mixer_ctls->audio_spk_headset_switch, "headset"); ALOGV("in normal mode, headset on,****LINE:%d,FUNC:%s",__LINE__,__FUNCTION__); } else { ALOGV("in normal mode, speaker on,****LINE:%d,FUNC:%s, speaker_on=%d", __LINE__,__FUNCTION__, speaker_on); mixer_ctl_set_enum_by_string(client->mixer_ctls->audio_spk_headset_switch, "spk" ); } return 0; }
static int set_phone_record_enable(struct codec_client *client, bool enable) { int ret = 0; mixer_ctl_set_value(client->mixer_ctls->audio_linein_record, 0, 0); if (enable){ mixer_ctl_set_value(client->mixer_ctls->audio_phone_voice_record, 0, 1); is_in_record = true; } else { if (is_in_record == true){ mixer_ctl_set_value(client->mixer_ctls->audio_phone_voice_record, 0, 0); is_in_record = false; } } ALOGV("phone record mode 4,****LINE:%d,FUNC:%s",__LINE__,__FUNCTION__); return 0; }
static int set_normal_volume(struct codec_client *client, int path, int vol) { int headset_on=0, headphone_on=0, speaker_on=0; headset_on = path & AUDIO_DEVICE_OUT_WIRED_HEADSET; // hp4p headphone_on = path & AUDIO_DEVICE_OUT_WIRED_HEADPHONE; // hp3p speaker_on = path & AUDIO_DEVICE_OUT_SPEAKER; if (speaker_on){ ALOGV("****LINE:%d,FUNC:%s",__LINE__,__FUNCTION__); mixer_ctl_set_value(client->mixer_ctls->line_volume, 0, vol); } else if ((headset_on || headphone_on)){ ALOGV("****LINE:%d,FUNC:%s",__LINE__,__FUNCTION__); mixer_ctl_set_value(client->mixer_ctls->master_playback_volume, 0, vol); } return 0; }
static int set_fm_path(struct codec_client *client, int path) { int headset_on=0, headphone_on=0, speaker_on=0; headset_on = path & AUDIO_DEVICE_OUT_WIRED_HEADSET; // hp4p headphone_on = path & AUDIO_DEVICE_OUT_WIRED_HEADPHONE; // hp3p speaker_on = path & AUDIO_DEVICE_OUT_SPEAKER; mixer_ctl_set_value(client->mixer_ctls->audio_linein_in, 0, 1); if (speaker_on){ mixer_ctl_set_value(client->mixer_ctls->audio_headphone_out, 0, 0); mixer_ctl_set_value(client->mixer_ctls->audio_speaker_out, 0, 1); } else { mixer_ctl_set_value(client->mixer_ctls->audio_speaker_out, 0, 0); mixer_ctl_set_value(client->mixer_ctls->audio_headphone_out, 0, 1); } ALOGV("FM mode 4, devices is %s, ****LINE:%d,FUNC:%s", speaker_on ? "spk" : "headset",__LINE__,__FUNCTION__); return 0; }
static bool setMixerValue(struct mixer* mixer, const char* name, const char* values) { if (!mixer) { ALOGE("no mixer in setMixerValue"); return false; } struct mixer_ctl *ctl = mixer_get_ctl_by_name(mixer, name); if (!ctl) { ALOGE("mixer_get_ctl_by_name failed for %s", name); return false; } enum mixer_ctl_type type = mixer_ctl_get_type(ctl); int numValues = mixer_ctl_get_num_values(ctl); int intValue; char stringValue[MAX_LINE_LENGTH]; for (int i = 0; i < numValues && values; i++) { // strip leading space while (*values == ' ') values++; if (*values == 0) break; switch (type) { case MIXER_CTL_TYPE_BOOL: case MIXER_CTL_TYPE_INT: if (sscanf(values, "%d", &intValue) == 1) { if (mixer_ctl_set_value(ctl, i, intValue) != 0) { ALOGE("mixer_ctl_set_value failed for %s %d", name, intValue); } } else { ALOGE("Could not parse %s as int for %s", values, name); } break; case MIXER_CTL_TYPE_ENUM: if (sscanf(values, "%s", stringValue) == 1) { if (mixer_ctl_set_enum_by_string(ctl, stringValue) != 0) { ALOGE("mixer_ctl_set_enum_by_string failed for %s %s", name, stringValue); } } else { ALOGE("Could not parse %s as enum for %s", values, name); } break; default: ALOGE("unsupported mixer type %d for %s", type, name); break; } values = strchr(values, ' '); } return true; }
static int set_phone_record_enable(struct codec_client *client, bool enable) { mixer_ctl_set_value(client->mixer_ctls->audio_fm_record, 0, 0); if (enable){ mixer_ctl_set_value(client->mixer_ctls->audio_phone_voice_record, 0, 1); is_in_record = true; } else { if (is_in_record == true){ mixer_ctl_set_value(client->mixer_ctls->audio_phone_voice_record, 0, 0); if( bluetooth_in_record ){ bluetooth_in_record = false; plan_one_stop_bt_record(); } client->record_ops->stop_record(); is_in_record = false; bluetooth_in_record = false; } } ALOGV("phone record mode 4,****LINE:%d,FUNC:%s",__LINE__,__FUNCTION__); return 0; }
/* Update the mixer with any changed values */ int audio_route_update_mixer(struct audio_route *ar) { unsigned int i; unsigned int j; for (i = 0; i < ar->num_mixer_ctls; i++) { unsigned int num_values = ar->mixer_state[i].num_values; /* if the value has changed, update the mixer */ if (ar->mixer_state[i].new_linked) { if (ar->mixer_state[i].old_value[0] != ar->mixer_state[i].new_value[0]) { /* linked ctl, so set all ctl values the same */ for (j = 0; j < num_values; j++) mixer_ctl_set_value(ar->mixer_state[i].ctl, j, ar->mixer_state[i].new_value[0]); ar->mixer_state[i].old_value[0] = ar->mixer_state[i].new_value[0]; } } else { for (j = 0; j < num_values; j++) { /* * unlinked ctl, so set each value if necessary. * Note that if the new value is unlinked but the old is * linked, only value 0 is valid, so we always have to * update the mixer for the other values. */ if (ar->mixer_state[i].old_linked || (ar->mixer_state[i].old_value[j] != ar->mixer_state[i].new_value[j])) { mixer_ctl_set_value(ar->mixer_state[i].ctl, j, ar->mixer_state[i].new_value[j]); ar->mixer_state[i].old_value[j] = ar->mixer_state[i].new_value[j]; } } } ar->mixer_state[i].old_linked = ar->mixer_state[i].new_linked; } return 0; }
static void set_headphone_volume(struct mixer_ctl *reg, int volume) { int i = 0; int val=0; val = mixer_ctl_get_value(reg, 0); if(val == volume){ //ALOGV("volume equal"); return; } if(val >volume){ for(i=val; i>=volume; i--){ mixer_ctl_set_value(reg, 0, i); usleep(5000); } } else { for(i=val; i<=volume; i++){ mixer_ctl_set_value(reg, 0, i); usleep(5000); } } }
static int set_normal_path(struct codec_client *client, int path) { int headset_on=0, headphone_on=0, speaker_on=0, earpiece_on=0; int switch_to_headset =0; int ret = -1, fd=0; char prop_value[PROPERTY_VALUE_MAX]={0}; char h2w_state[2]={0}; headset_on = path & AUDIO_DEVICE_OUT_WIRED_HEADSET; // hp4p headphone_on = path & AUDIO_DEVICE_OUT_WIRED_HEADPHONE; // hp3p speaker_on = path & AUDIO_DEVICE_OUT_SPEAKER; earpiece_on = path & AUDIO_DEVICE_OUT_EARPIECE; mixer_ctl_set_value(client->mixer_ctls->audio_linein_in, 0, 0); //turn off fm ret = property_get("dev.bootcomplete", prop_value, "0"); if (ret > 0) { if (atoi(prop_value) == 0){ fd = open("/sys/class/switch/h2w/state", O_RDONLY); if(fd>0){ ret = read(fd, h2w_state, sizeof(h2w_state)); close(fd); if ( (atoi(h2w_state) == 2 || atoi(h2w_state) == 1) ) { switch_to_headset =1; } } } } if (((headset_on || headphone_on) && speaker_on)){ ALOGV("in normal mode, headset and speaker on,****LINE:%d,FUNC:%s",__LINE__,__FUNCTION__); mixer_ctl_set_enum_by_string(client->mixer_ctls->audio_spk_headset_switch, "spk_headset"); } else if(earpiece_on) { mixer_ctl_set_enum_by_string(client->mixer_ctls->audio_spk_headset_switch, "spk"); ALOGV("in earpiece mode, pad no earpiece but spk,****LINE:%d,FUNC:%s",__LINE__,__FUNCTION__); //no earpiece } else if(switch_to_headset) { mixer_ctl_set_enum_by_string(client->mixer_ctls->audio_spk_headset_switch, "headset"); ALOGV("in boot switch_to_headset mode, headset,****LINE:%d,FUNC:%s",__LINE__,__FUNCTION__); switch_to_headset = 0; } else { ALOGV("in normal mode, headset or speaker on,****LINE:%d,FUNC:%s",__LINE__,__FUNCTION__); mixer_ctl_set_enum_by_string(client->mixer_ctls->audio_spk_headset_switch, speaker_on ? "spk" : "headset"); } return 0; }
void update_mixer_state(struct audio_route *ar) { unsigned int i; unsigned int j; for (i = 0; i < ar->num_mixer_ctls; i++) { /* if the value has changed, update the mixer */ if (ar->mixer_state[i].old_value != ar->mixer_state[i].new_value) { /* set all ctl values the same */ for (j = 0; j < mixer_ctl_get_num_values(ar->mixer_state[i].ctl); j++) mixer_ctl_set_value(ar->mixer_state[i].ctl, j, ar->mixer_state[i].new_value); ar->mixer_state[i].old_value = ar->mixer_state[i].new_value; } } }
int audio_route_control_set_number(unsigned int card_slot, char *control_name, char *string) { struct mixer *control_mixer; struct mixer_ctl *ctl; const char *name; unsigned int num_ctls, num_values; unsigned int i, j; enum mixer_ctl_type type; int value; int ret, mixer_ret; control_mixer = mixer_open(card_slot); if (!control_mixer) { ALOGE("Unable to open the control mixer, aborting."); return -1; } ALOGV("Control mixer open successful."); num_ctls = mixer_get_num_ctls(control_mixer); ret = 0; for (i = 0; i < num_ctls; i++) { ctl = mixer_get_ctl(control_mixer, i); name = mixer_ctl_get_name(ctl); if (name && strcmp(name, control_name) == 0) { /* Found the control, update and exit */ value = atoi(string); num_values = mixer_ctl_get_num_values(ctl); for (j = 0; j < num_values; j++) { mixer_ret = mixer_ctl_set_value(ctl, j, value); if (mixer_ret) { ALOGE("Error: invalid value (%s to %d)", name, value); mixer_close(control_mixer); /* Add up the number of failed controller values */ ret += -1; } } if (ret == 0) ALOGV("Setting %s to int %d", name, value); break; } } return ret; }
static int path_apply(struct audio_route *ar, struct mixer_path *path) { unsigned int i; unsigned int j; unsigned int k; if (!ar) { ALOGE("%s: invalid audio_route", __func__); return -1; } for (i = 0; i < path->length; i++) { struct mixer_ctl *ctl = path->setting[i].ctl; /* locate the mixer ctl in the list */ for (j = 0; j < ar->num_mixer_ctls; j++) { if (ar->mixer_state[j].ctl == ctl) break; } /* apply the new value */ #if 0 for (k = 0; k < path->setting[i].ctl_vals; k++) { ar->mixer_state[j].new_value[k] = path->setting[i].value[k]; mixer_ctl_set_value(ctl, k, ar->mixer_state[j].new_value[k]); } #else for (k = 0; k < path->setting[i].ctl_vals; k++) { ar->mixer_state[j].new_value[k] = path->setting[i].value[k]; } ALOGV("mixer_set: '%s' %d,%d,%d\n", mixer_ctl_get_name(ctl), path->setting[i].value[0], path->setting[i].value[1], path->setting[i].value[2] ); mixer_ctl_set_multivalue(ctl, path->setting[i].ctl_vals, path->setting[i].value); #endif ar->mixer_state[j].ctl_vals = path->setting[i].ctl_vals; } return 0; }
static bool mixer_set(struct mixer *mixer, const char *name, int value) { struct mixer_ctl *ctl; unsigned i; ctl = mixer_get_ctl_by_name(mixer, name); if (! ctl) { fprintf(stderr, "Failed to find control: %s\n", name); mixer_close(mixer); return false; } for (i = 0; i < mixer_ctl_get_num_values(ctl); i++) { mixer_ctl_set_value(ctl, i, value); } return true; }