struct audio_route * setup_audio_route(struct audio_tool_config *config) { struct audio_route *ar; ar = calloc(1, sizeof(struct audio_route)); if (!ar) { printf("Nae calloc!\n"); goto errr; } ar->mixer = mixer_open(config->card); if (!ar->mixer) { printf("Oofft, nae mixer\n"); goto errr; } ar->mixer_path = NULL; ar->mixer_path_size = 0; ar->num_mixer_paths = 0; return ar; errr: printf("BURNEY! - Couldn't SETUP AUDIO ROUTE\n"); exit(-1); }
bool audio_set_volume(audio_t *audio, unsigned volume) { struct mixer *mixer; bool res; mixer = mixer_open(audio->dev.card); if (! mixer) { fprintf(stderr, "Failed to open mixer\n"); return false; } if (audio->dev.playback) { res = do_set_volume(mixer, "PCM Playback Volume", volume) || mixer_set(mixer, "PCM Playback Route", 1); } else { res = do_set_volume(mixer, "Mic Capture Volume", volume) || mixer_set(mixer, "Mic Capture Switch", 1) || mixer_set(mixer, "Speaker Playback Switch", 0) || mixer_set(mixer, "Mic Playback Switch", 0); } mixer_close(mixer); return res; }
int offload_update_mixer_and_effects_ctl(int card, int device_id, struct mixer *mixer, struct mixer_ctl *ctl) { char mixer_string[128]; snprintf(mixer_string, sizeof(mixer_string), "%s %d", "Audio Effects Config", device_id); ALOGV("%s: mixer_string: %s", __func__, mixer_string); mixer = mixer_open(card); if (!mixer) { ALOGE("Failed to open mixer"); ctl = NULL; return -EINVAL; } else { ctl = mixer_get_ctl_by_name(mixer, mixer_string); if (!ctl) { ALOGE("mixer_get_ctl_by_name failed"); mixer_close(mixer); mixer = NULL; return -EINVAL; } } ALOGV("mixer: %p, ctl: %p", mixer, ctl); return 0; }
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 }
int list(int argc, char **argv) { int nMixer = -1; if (argc == 3) nMixer = atoi(argv[2]); if (argc != 3 || nMixer < 0 || nMixer > 7) { printf("Usage: ainfo list <card number>\n" "where <card number> is between 0 and 7\n"); return 0; } mixer *m = mixer_open(nMixer); if (m == NULL) { printf("Unable to open card #%d\n", nMixer); return 0; } int count = mixer_get_num_ctls(m); printf("Found %d controls:\n", count); for (int i = 0; i < count; i++) { char name[64], type[64]; mixer_ctl *ctl = mixer_get_ctl(m, i); mixer_ctl_get_name(ctl, name, sizeof(name)); printf("%d: %s (0x%x)\n", i, name, mixer_ctl_get_type(ctl)); } return 0; }
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; }
TEST(pcmtest, CheckMixerDevices) { struct mixer *mixer; for (unsigned int i = 0; i < mixers; i++) { mixer = mixer_open(i); EXPECT_TRUE(mixer != NULL); if (mixer) mixer_close(mixer); } }
/* * Parse the audio configuration file. * The file is named audio_conf.txt and must begin with the following header: * * card=<ALSA card number> * device=<ALSA device number> * period_size=<period size> * period_count=<period count> * * This header is followed by zero or more mixer settings, each with the format: * mixer "<name>" = <value list> * Since mixer names can contain spaces, the name must be enclosed in double quotes. * The values in the value list can be integers, booleans (represented by 0 or 1) * or strings for enum values. */ bool AudioPlayer::init(const char* config) { int tempInt; struct mixer* mixer = NULL; char name[MAX_LINE_LENGTH]; for (;;) { const char* endl = strstr(config, "\n"); if (!endl) break; String8 line(config, endl - config); if (line.length() >= MAX_LINE_LENGTH) { ALOGE("Line too long in audio_conf.txt"); return false; } const char* l = line.string(); if (sscanf(l, "card=%d", &tempInt) == 1) { ALOGD("card=%d", tempInt); mCard = tempInt; mixer = mixer_open(mCard); if (!mixer) { ALOGE("could not open mixer for card %d", mCard); return false; } } else if (sscanf(l, "device=%d", &tempInt) == 1) { ALOGD("device=%d", tempInt); mDevice = tempInt; } else if (sscanf(l, "period_size=%d", &tempInt) == 1) { ALOGD("period_size=%d", tempInt); mPeriodSize = tempInt; } else if (sscanf(l, "period_count=%d", &tempInt) == 1) { ALOGD("period_count=%d", tempInt); mPeriodCount = tempInt; } else if (sscanf(l, "mixer \"%[0-9a-zA-Z _]s\"", name) == 1) { const char* values = strchr(l, '='); if (values) { values++; // skip '=' ALOGD("name: \"%s\" = %s", name, values); setMixerValue(mixer, name, values); } else { ALOGE("values missing for name: \"%s\"", name); } } config = ++endl; } mixer_close(mixer); if (mCard >= 0 && mDevice >= 0) { return true; } return false; }
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 sun_mixer_open(int *vol_max) { const char *mixer_channel = "master"; /* set default mixer channel */ if (sun_mixer_channel == NULL) sun_mixer_channel = xstrdup(mixer_channel); if (mixer_open(sun_mixer_device) == 0) { *vol_max = AUDIO_MAX_GAIN; return 0; } return -1; }
int main(int argc, G_GNUC_UNUSED char **argv) { GError *error = NULL; struct mixer *mixer; bool success; int volume; if (argc != 2) { g_printerr("Usage: read_mixer PLUGIN\n"); return 1; } g_thread_init(NULL); mixer = mixer_new(&alsa_mixer_plugin, NULL, NULL, &error); if (mixer == NULL) { g_printerr("mixer_new() failed: %s\n", error->message); g_error_free(error); return 2; } success = mixer_open(mixer, &error); if (!success) { mixer_free(mixer); g_printerr("failed to open the mixer: %s\n", error->message); g_error_free(error); return 2; } volume = mixer_get_volume(mixer, &error); mixer_close(mixer); mixer_free(mixer); assert(volume >= -1 && volume <= 100); if (volume < 0) { if (error != NULL) { g_printerr("failed to read volume: %s\n", error->message); g_error_free(error); } else g_printerr("failed to read volume\n"); return 2; } g_print("%d\n", volume); return 0; }
size_t alsavol(char *dest, size_t n) { size_t ret; struct mixer *mx; if (!(mx = mixer_open(sndcrd))) die("couldn't open mixer for card %d\n", sndcrd); ret = actlstr(dest, n, (char*)swtchname, mx); if (strcmp(dest, "Off")) ret = actlstr(dest, n, (char*)volumname, mx); mixer_close(mx); return ret; }
struct mixer *TinyAlsaSubsystem::getMixerHandle(int32_t cardNumber) { MixerMap::const_iterator it = mMixers.find(cardNumber); if (it != mMixers.end()) { return it->second; } // create handle struct mixer *newMixer = mixer_open(cardNumber); if (newMixer == NULL) { return NULL; } mMixers.insert(std::make_pair(cardNumber, newMixer)); return newMixer; }
int audio_route_control_set_enum(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 */ type = mixer_ctl_get_type(ctl); if (type == MIXER_CTL_TYPE_ENUM) { if (mixer_ctl_set_enum_by_string(ctl, string)) { ALOGE("Error: invalid enum value"); ret = -1; } else { ALOGV("Setting %s to string %s", name, string); } } else { ALOGV("Error: only enum types can be set with strings"); ret = -1; } break; } } mixer_close(control_mixer); return ret; }
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; }
void send_channel_map_driver(struct pcm *pcm) { int i, ret; struct mixer *mixer; const char* device = "/dev/snd/controlC0"; mixer = mixer_open(device); if (!mixer) { fprintf(stderr,"oops: %s: %d\n", strerror(errno), __LINE__); return; } ret = pcm_set_channel_map(pcm, mixer, 8, channel_map); if (ret < 0) fprintf(stderr, "could not set channel mask\n"); mixer_close(mixer); return; }
static int loop_test(void) { struct mixer *mixer; int card = 0; mixer = mixer_open(card); if (!mixer) { fprintf(stderr, "Failed to open mixer\n"); return EXIT_FAILURE; } tinymix_set_value(mixer, 92, 1); tinymix_set_value(mixer, 93, 1); tinymix_set_value(mixer, 95, 1); tinymix_set_value(mixer, 100, 1); tinymix_set_value(mixer, 0, 60); tinymix_set_value(mixer, 34,7); tinymix_set_value(mixer, 18,7); mixer_close(mixer); return 0; }
static int exit_loop_mode() { struct mixer *mixer; int card = 0; mixer = mixer_open(card); if (!mixer) { fprintf(stderr, "Failed to open mixer\n"); return EXIT_FAILURE; } tinymix_set_value(mixer, 92, 0); tinymix_set_value(mixer, 93, 0); tinymix_set_value(mixer, 95, 0); tinymix_set_value(mixer, 100, 0); mixer_close(mixer); if(writeline("AT+ECHO1OFF")){ return -1; } return 0; }
TEST_F(MixerTest, tryTinyAlsaTest) { int hwId = AudioHardware::detectAudioHw(); ASSERT_TRUE(hwId >= 0); struct mixer* mixerp = mixer_open(hwId); ASSERT_TRUE(mixerp != NULL); int num_ctls = mixer_get_num_ctls(mixerp); LOGI("Number of mixel control %d", num_ctls); for (int i = 0; i < num_ctls; i++) { struct mixer_ctl* control = mixer_get_ctl(mixerp, i); ASSERT_TRUE(control != NULL); LOGI("Mixer control %s type %s value %d", mixer_ctl_get_name(control), mixer_ctl_get_type_string(control), mixer_ctl_get_num_values(control)); free(control); } // no mixer control for MobilePre. If this assumption fails, // mixer control should be added. ASSERT_TRUE(num_ctls == 0); mixer_close(mixerp); }
int write_percentage(int argc, char **argv) { int nMixer = -1, nControl = -1; int location = -1, value = -1; if (argc == 6) { nMixer = atoi(argv[2]); nControl = atoi(argv[3]); location = atoi(argv[4]); value = atoi(argv[5]); } if (argc != 6 || nMixer < 0 || nMixer > 7 || nControl < 0 || location < 0) { printf("Usage: ainfo write-percentage <card number> <control number> <location> <value>\n" "where <card number> is between 0 and 7\n" "<control number> is the control to be written\n" "<location> is the location to be written\n" "<value> is the value to be written\n"); return 0; } mixer *m = mixer_open(nMixer); if (m == NULL) { printf("Unable to open card #%d\n", nMixer); return 0; } mixer_ctl *c = mixer_get_ctl(m, nControl); if (c == NULL) { printf("Unable to open control #%d\n", nControl); return 0; } char name[64], type[64]; mixer_ctl_get_name(c, name, sizeof(name)); mixer_ctl_set_percent(c, location, value); printf("Control: %s\nPercent: %d\nValue: %d\n", name, mixer_ctl_get_percent(c, location), mixer_ctl_get_value(c, location)); return 0; }
static void do_mixer_settings(FILE *file) { struct mixer *mixer; char buf[256], *name, *value; mixer = mixer_open(0); if(!mixer) { log_info("cannot open mixer"); return; } log_info("processing mixer settings from %s", alsa_config_file); while(fgets(buf, sizeof(buf),file)) { if(parse_config_line(buf, &name, &value)) { log_info("%s -> %s", name, value); tinymix_set_value(mixer, name, value); } } mixer_close(mixer); log_info("mixer settings processed"); }
int SetAudio_pga_parameter_eng(AUDIO_TOTAL_T *aud_params_ptr, unsigned int params_size, uint32_t vol_level) { int ret = 0; int card_id; pga_gain_nv_t pga_gain_nv; struct mixer *mixer; struct audio_pga *pga; memset(&pga_gain_nv,0,sizeof(pga_gain_nv_t)); if (sizeof(AUDIO_TOTAL_T) != params_size) { ALOGE("%s, Error: params_size = %d, total size = %d", __func__,params_size, sizeof(AUDIO_TOTAL_T)); return -1; } ret = GetAudio_pga_nv(aud_params_ptr,&pga_gain_nv,vol_level); if(ret < 0){ return -1; } card_id = get_snd_card_number(CARD_SPRDPHONE); ALOGW("%s card_id = %d", __func__,card_id); if (card_id < 0) return -1; mixer = mixer_open(card_id); if (!mixer) { ALOGE("%s Failed to open mixer",__func__); return -1; } pga = audio_pga_init(mixer); if (!pga) { mixer_close(mixer); ALOGE("%s Warning: Unable to locate PGA from XML.",__func__); return -1; } ret = SetAudio_gain_4eng(pga,&pga_gain_nv,aud_params_ptr); if(ret < 0){ mixer_close(mixer); return -1; } mixer_close(mixer); return 0; }
int main(int argc, char **argv) { struct mixer *mixer; int card = 0; if ((argc > 2) && (strcmp(argv[1], "-D") == 0)) { argv++; if (argv[1]) { card = atoi(argv[1]); argv++; argc -= 2; } else { argc -= 1; } } mixer = mixer_open(card); if (!mixer) { fprintf(stderr, "Failed to open mixer\n"); return EXIT_FAILURE; } if (argc == 1) { printf("Mixer name: '%s'\n", mixer_get_name(mixer)); tinymix_list_controls(mixer); } else if (argc == 2) { tinymix_detail_control(mixer, argv[1], 1); } else if (argc >= 3) { tinymix_set_value(mixer, argv[1], &argv[2], argc - 2); } else { printf("Usage: tinymix [-D card] [control id] [value to set]\n"); } mixer_close(mixer); return 0; }
int main(int argc, char **argv) { struct mixer *mixer; mixer = mixer_open(0); if (!mixer) { fprintf(stderr, "Failed to open mixer\n"); return EXIT_FAILURE; } if (argc == 1) tinymix_list_controls(mixer); else if (argc == 2) tinymix_detail_control(mixer, atoi(argv[1]), 1); else if (argc == 3) tinymix_set_value(mixer, atoi(argv[1]), argv[2]); else printf("Usage: tinymix [control id] [value to set]\n"); mixer_close(mixer); return 0; }
int read_range(int argc, char **argv) { int nMixer = -1, nControl = -1; int location = -1; if (argc == 4) { nMixer = atoi(argv[2]); nControl = atoi(argv[3]); } if (argc != 4 || nMixer < 0 || nMixer > 7 || nControl < 0) { printf("Usage: ainfo read-range <card number> <control number> <location>\n" "where <card number> is between 0 and 7\n" "<control number> is the control to be read\n"); return 0; } mixer *m = mixer_open(nMixer); if (m == NULL) { printf("Unable to open card #%d\n", nMixer); return 0; } mixer_ctl *c = mixer_get_ctl(m, nControl); if (c == NULL) { printf("Unable to open control #%d\n", nControl); return 0; } char name[64], type[64]; mixer_ctl_get_name(c, name, sizeof(name)); printf("Control: %s\nMin: %d\nMax: %d\n", name, mixer_ctl_get_range_min(c), mixer_ctl_get_range_max(c)); return 0; }
struct audio_route *audio_route_init(void) { struct config_parse_state state; XML_Parser parser; FILE *file; int bytes_read; void *buf; int i; struct mixer_path *path; struct audio_route *ar; ar = calloc(1, sizeof(struct audio_route)); if (!ar) goto err_calloc; ar->mixer = mixer_open(MIXER_CARD); if (!ar->mixer) { ALOGE("Unable to open the mixer, aborting."); goto err_mixer_open; } ar->mixer_path = NULL; ar->mixer_path_size = 0; ar->num_mixer_paths = 0; /* allocate space for and read current mixer settings */ if (alloc_mixer_state(ar) < 0) goto err_mixer_state; file = fopen(MIXER_XML_PATH, "r"); if (!file) { ALOGE("Failed to open %s", MIXER_XML_PATH); goto err_fopen; } parser = XML_ParserCreate(NULL); if (!parser) { ALOGE("Failed to create XML parser"); goto err_parser_create; } memset(&state, 0, sizeof(state)); state.ar = ar; XML_SetUserData(parser, &state); XML_SetElementHandler(parser, start_tag, end_tag); for (;;) { buf = XML_GetBuffer(parser, BUF_SIZE); if (buf == NULL) goto err_parse; bytes_read = fread(buf, 1, BUF_SIZE, file); if (bytes_read < 0) goto err_parse; if (XML_ParseBuffer(parser, bytes_read, bytes_read == 0) == XML_STATUS_ERROR) { ALOGE("Error in mixer xml (%s)", MIXER_XML_PATH); goto err_parse; } if (bytes_read == 0) break; } audio_route_apply_path(ar, "init"); /* apply the initial mixer values, and save them so we can reset the mixer to the original values */ update_mixer_state(ar); save_mixer_state(ar); XML_ParserFree(parser); fclose(file); return ar; err_parse: XML_ParserFree(parser); err_parser_create: fclose(file); err_fopen: free_mixer_state(ar); err_mixer_state: mixer_close(ar->mixer); err_mixer_open: free(ar); ar = NULL; err_calloc: return NULL; }
int mcs_route_ctrl_set_path(struct mcs_route_ctrl_info * route_hdl, int acdb_id, int ena_flag, int * pcm_device) { char *p, array[100], *pmode; char en[] = "enable"; char dis[] = "disable"; int len = 0, found = 0, len2 = 0; struct mixer *mxr = NULL; struct mixer_ctl *ctl = 0; char *temp; int params, sublen, ret = 0; if (route_hdl == NULL) { ALOGE("Invalid MCS routing control handle."); return -EINVAL; } if (route_hdl->file_hdl == NULL) { ALOGE("Invalid configuration file handle."); return -EINVAL; } rewind(route_hdl->file_hdl); pmode = (ena_flag)?en:dis; /* Find the test case */ while((p = fgets(array, sizeof(array), route_hdl->file_hdl))) { if (strcasestr(p, ACDB_DEV_STR)) { if (atoi(&p[sizeof(ACDB_DEV_STR)-1]) == acdb_id) { found = 1; break; } } } if (!found) { ALOGE("Can't find ACDB ID %d from configuration file.", acdb_id); return -EACCES; } ALOGD("Found acdb_dev_id:%d %s", acdb_id, pmode); /* Find enable or disable commands*/ found = 0; while((p = fgets(array, sizeof(array), route_hdl->file_hdl))) { len = strnlen(p,sizeof(array)); p[len-1] = '\0'; len--; /* Comment added print comment */ if (!strncmp(&p[0], "#", 1)) { ALOGD("%s", p); } else if (strstr(p, "Rxdevice")) { temp = NULL; if ((temp = strstr(p,":"))) { sublen = temp - p; len = len - sublen - 1; temp++; temp[len] = '\0'; if (*temp >= '0' || *temp <= '9') *pcm_device = atoi(temp); else *pcm_device = -1; } } else if (strstr(p, "Txdevice")) { temp = NULL; if ((temp = strstr(p,":"))) { sublen = temp - p; len = len - sublen - 1; temp++; temp[len] = '\0'; if (*temp >= '0' || *temp <= '9') *pcm_device = atoi(temp); else *pcm_device = -1; } } else if (strstr(p, pmode)) { found = 1; break; } } if (!found) { ALOGE("Sequence for %s not found", pmode); return -1; } else { ALOGD("Sequence for %s found", pmode); } pmode = (!ena_flag)?en:dis; mxr = mixer_open(route_hdl->sndcard_num); if (!mxr) { ALOGE("Opening mixer control failed"); return -1; } while((p = fgets(array, sizeof(array), route_hdl->file_hdl))) { len = strnlen(p,sizeof(array)); p[len-1] = '\0'; len--; if (strstr(p, ACDB_DEV_STR) || strstr(p, pmode)) { break; } else { if (len) { char ctlname[100]; char ctlval[100]; temp = strstr(p,":"); if (temp) { sublen = temp - p; memcpy(ctlname, p, sublen); ctlname[sublen] = '\0'; ctl = get_ctl(mxr, ctlname); if (!ctl) { ALOGE("Failed to get %s\n", ctlname); break; } sublen = len - sublen; sublen--; temp++; memcpy(ctlval, temp, sublen); ctlval[sublen] = '\0'; int val = -1; while(sublen > 0) { if (*temp == ' ') { temp++; sublen--; }else if (*temp >= '0' && *temp <= '9') { val = atoi(temp); break; } else { val = 0; break; } } if (val < 0) { ALOGE("Invalid param for val"); return -EINVAL; } else if (!val) { ALOGD("Select %s %s", ctlname, ctlval); ret = mixer_ctl_select(ctl, ctlval); } else { ALOGD("Set %s %d", ctlname, val); ret = mixer_ctl_set(ctl, val); } } } } } mixer_close(mxr); return ret; }
static int laudio_alsa_open(void) { snd_pcm_hw_params_t *hw_params; snd_pcm_uframes_t bufsize; int ret; hw_params = NULL; ret = snd_pcm_open(&hdl, card_name, SND_PCM_STREAM_PLAYBACK, 0); if (ret < 0) { DPRINTF(E_LOG, L_LAUDIO, "Could not open playback device: %s\n", snd_strerror(ret)); return -1; } /* HW params */ ret = snd_pcm_hw_params_malloc(&hw_params); if (ret < 0) { DPRINTF(E_LOG, L_LAUDIO, "Could not allocate hw params: %s\n", snd_strerror(ret)); goto out_fail; } ret = snd_pcm_hw_params_any(hdl, hw_params); if (ret < 0) { DPRINTF(E_LOG, L_LAUDIO, "Could not retrieve hw params: %s\n", snd_strerror(ret)); goto out_fail; } ret = snd_pcm_hw_params_set_access(hdl, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED); if (ret < 0) { DPRINTF(E_LOG, L_LAUDIO, "Could not set access method: %s\n", snd_strerror(ret)); goto out_fail; } ret = snd_pcm_hw_params_set_format(hdl, hw_params, SND_PCM_FORMAT_S16_LE); if (ret < 0) { DPRINTF(E_LOG, L_LAUDIO, "Could not set S16LE format: %s\n", snd_strerror(ret)); goto out_fail; } ret = snd_pcm_hw_params_set_channels(hdl, hw_params, 2); if (ret < 0) { DPRINTF(E_LOG, L_LAUDIO, "Could not set stereo output: %s\n", snd_strerror(ret)); goto out_fail; } ret = snd_pcm_hw_params_set_rate(hdl, hw_params, 44100, 0); if (ret < 0) { DPRINTF(E_LOG, L_LAUDIO, "Hardware doesn't support 44.1 kHz: %s\n", snd_strerror(ret)); goto out_fail; } ret = snd_pcm_hw_params_get_buffer_size_max(hw_params, &bufsize); if (ret < 0) { DPRINTF(E_LOG, L_LAUDIO, "Could not get max buffer size: %s\n", snd_strerror(ret)); goto out_fail; } DPRINTF(E_DBG, L_LAUDIO, "Max buffer size is %lu samples\n", bufsize); ret = snd_pcm_hw_params_set_buffer_size_max(hdl, hw_params, &bufsize); if (ret < 0) { DPRINTF(E_LOG, L_LAUDIO, "Could not set buffer size to max: %s\n", snd_strerror(ret)); goto out_fail; } DPRINTF(E_DBG, L_LAUDIO, "Buffer size is %lu samples\n", bufsize); ret = snd_pcm_hw_params(hdl, hw_params); if (ret < 0) { DPRINTF(E_LOG, L_LAUDIO, "Could not set hw params: %s\n", snd_strerror(ret)); goto out_fail; } snd_pcm_hw_params_free(hw_params); hw_params = NULL; pcm_pos = 0; pcm_last_error = 0; pcm_recovery = 0; pcm_buf_threshold = (bufsize / AIRTUNES_V2_PACKET_SAMPLES) * AIRTUNES_V2_PACKET_SAMPLES; ret = mixer_open(); if (ret < 0) { DPRINTF(E_LOG, L_LAUDIO, "Could not open mixer\n"); goto out_fail; } update_status(LAUDIO_OPEN); return 0; out_fail: if (hw_params) snd_pcm_hw_params_free(hw_params); snd_pcm_close(hdl); hdl = NULL; return -1; }
static bool audio_output_open(struct audio_output *ao, const struct audio_format *audio_format, const struct music_pipe *mp) { bool open; assert(mp != NULL); if (ao->fail_timer != NULL) { g_timer_destroy(ao->fail_timer); ao->fail_timer = NULL; } if (ao->open && audio_format_equals(audio_format, &ao->in_audio_format)) { assert(ao->pipe == mp || (ao->always_on && ao->pause)); if (ao->pause) { ao->chunk = NULL; ao->pipe = mp; /* unpause with the CANCEL command; this is a hack, but suits well for forcing the thread to leave the ao_pause() thread, and we need to flush the device buffer anyway */ /* we're not using audio_output_cancel() here, because that function is asynchronous */ ao_command(ao, AO_COMMAND_CANCEL); /* the audio output is now waiting for a signal; wake it up immediately */ g_cond_signal(ao->cond); } return true; } ao->in_audio_format = *audio_format; ao->chunk = NULL; ao->pipe = mp; if (ao->thread == NULL) audio_output_thread_start(ao); ao_command(ao, ao->open ? AO_COMMAND_REOPEN : AO_COMMAND_OPEN); open = ao->open; if (open && ao->mixer != NULL) { GError *error = NULL; if (!mixer_open(ao->mixer, &error)) { g_warning("Failed to open mixer for '%s': %s", ao->name, error->message); g_error_free(error); } } return open; }
static int adev_open(const hw_module_t* module, const char* name, hw_device_t** device) { #if 0 //TARGET_AUDIO_PRIMARY struct mixer *mixer; struct mixer_ctl *ctl; #endif if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0) return -EINVAL; struct audio_device *adev = calloc(1, sizeof(struct audio_device)); if (!adev) return -ENOMEM; profile_init(&adev->out_profile, PCM_OUT); profile_init(&adev->in_profile, PCM_IN); adev->hw_device.common.tag = HARDWARE_DEVICE_TAG; adev->hw_device.common.version = AUDIO_DEVICE_API_VERSION_2_0; adev->hw_device.common.module = (struct hw_module_t *)module; adev->hw_device.common.close = adev_close; adev->hw_device.init_check = adev_init_check; adev->hw_device.set_voice_volume = adev_set_voice_volume; adev->hw_device.set_master_volume = adev_set_master_volume; adev->hw_device.set_mode = adev_set_mode; adev->hw_device.set_mic_mute = adev_set_mic_mute; adev->hw_device.get_mic_mute = adev_get_mic_mute; adev->hw_device.set_parameters = adev_set_parameters; adev->hw_device.get_parameters = adev_get_parameters; adev->hw_device.get_input_buffer_size = adev_get_input_buffer_size; adev->hw_device.open_output_stream = adev_open_output_stream; adev->hw_device.close_output_stream = adev_close_output_stream; adev->hw_device.open_input_stream = adev_open_input_stream; adev->hw_device.close_input_stream = adev_close_input_stream; adev->hw_device.dump = adev_dump; *device = &adev->hw_device.common; #if 0 //TARGET_AUDIO_PRIMARY mixer = mixer_open(0); if (mixer) { /* setting master volume to value 50 */ adev->master_volume = 50; int ret = 0; ctl = mixer_get_ctl_by_name(mixer, "HP Playback Switch"); ret = mixer_ctl_set_value(ctl,0,1); ret = mixer_ctl_set_value(ctl,1,1); 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)); ctl = mixer_get_ctl_by_name(mixer, "HPO MIX DAC1 Switch"); mixer_ctl_set_value(ctl,0,1); ctl = mixer_get_ctl_by_name(mixer, "HPO MIX DAC1 Switch"); mixer_ctl_set_value(ctl,0,1); ctl = mixer_get_ctl_by_name(mixer, "OUT MIXR DAC R1 Switch"); mixer_ctl_set_value(ctl,0,1); ctl = mixer_get_ctl_by_name(mixer, "OUT MIXL DAC L1 Switch"); mixer_ctl_set_value(ctl,0,1); ctl = mixer_get_ctl_by_name(mixer, "Stereo DAC MIXR DAC R1 Switch"); mixer_ctl_set_value(ctl,0,1); ctl = mixer_get_ctl_by_name(mixer, "Stereo DAC MIXL DAC L1 Switch"); mixer_ctl_set_value(ctl,0,1); mixer_close(mixer); } #endif return 0; }