OSDN Git Service

USB MONOtization issue fix.
authorPaul McLean <pmclean@google.com>
Tue, 3 Nov 2015 20:25:24 +0000 (12:25 -0800)
committerPaul Mclean <pmclean@google.com>
Thu, 5 Nov 2015 16:52:30 +0000 (16:52 +0000)
Profile default outputs to STEREO if available.
Profile default to 48K or 44.1K if available.

Bug: 24366970
Change-Id: Ib3685668ede236d3faf79cd9a471ba0f0bb641c6

alsa_utils/alsa_device_profile.c
alsa_utils/alsa_device_proxy.c

index 054c77a..9e74449 100644 (file)
@@ -332,7 +332,21 @@ static int read_alsa_device_config(alsa_device_profile * profile, struct pcm_con
 #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));
index ac948f1..ee92ed0 100644 (file)
@@ -50,15 +50,30 @@ void proxy_prepare(alsa_device_proxy * proxy, alsa_device_profile* profile,
     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 =