#endif
config->channels = pcm_params_get_min(alsa_hw_params, PCM_PARAM_CHANNELS);
+ // For output devices, let's make sure we choose at least stereo
+ // (assuming the device supports it).
+ if (profile->direction == PCM_OUT &&
+ config->channels < 2 && pcm_params_get_max(alsa_hw_params, PCM_PARAM_CHANNELS) >= 2) {
+ config->channels = 2;
+ }
config->rate = pcm_params_get_min(alsa_hw_params, PCM_PARAM_RATE);
+ // Prefer 48K or 44.1K
+ if (config->rate < 48000 &&
+ pcm_params_get_max(alsa_hw_params, PCM_PARAM_RATE) >= 48000) {
+ config->rate = 48000;
+ } else if (config->rate < 441000 &&
+ pcm_params_get_max(alsa_hw_params, PCM_PARAM_RATE) >= 44100) {
+ config->rate = 44100;
+ }
config->period_size = profile_calc_min_period_size(profile, config->rate);
config->period_count = pcm_params_get_min(alsa_hw_params, PCM_PARAM_PERIODS);
config->format = get_pcm_format_for_mask(pcm_params_get_mask(alsa_hw_params, PCM_PARAM_FORMAT));
log_pcm_config(config, "proxy_setup()");
#endif
- proxy->alsa_config.format =
- config->format != PCM_FORMAT_INVALID && profile_is_format_valid(profile, config->format)
- ? config->format : profile->default_config.format;
- proxy->alsa_config.rate =
- config->rate != 0 && profile_is_sample_rate_valid(profile, config->rate)
- ? config->rate : profile->default_config.rate;
- proxy->alsa_config.channels =
- config->channels != 0 && profile_is_channel_count_valid(profile, config->channels)
- ? config->channels : profile->default_config.channels;
+ if (config->format != PCM_FORMAT_INVALID && profile_is_format_valid(profile, config->format)) {
+ proxy->alsa_config.format = config->format;
+ } else {
+ ALOGW("Invalid format %d - using default %d.",
+ config->format, profile->default_config.format);
+ proxy->alsa_config.format = profile->default_config.format;
+ }
+
+ if (config->rate != 0 && profile_is_sample_rate_valid(profile, config->rate)) {
+ proxy->alsa_config.rate = config->rate;
+ } else {
+ ALOGW("Invalid sample rate %u - using default %u.",
+ config->rate, profile->default_config.rate);
+ proxy->alsa_config.rate = profile->default_config.rate;
+ }
+
+ if (config->channels != 0 && profile_is_channel_count_valid(profile, config->channels)) {
+ proxy->alsa_config.channels = config->channels;
+ } else {
+ ALOGW("Invalid channel count %u - using default %u.",
+ config->channels, profile->default_config.channels);
+ proxy->alsa_config.channels = profile->default_config.channels;
+
+ }
proxy->alsa_config.period_count = profile->default_config.period_count;
proxy->alsa_config.period_size =