summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--audio/Android.mk3
-rw-r--r--audio/audio_hw.c34
-rw-r--r--audio/mixer_paths.xml151
-rw-r--r--midas.mk6
4 files changed, 193 insertions, 1 deletions
diff --git a/audio/Android.mk b/audio/Android.mk
index afa804f..cfe9ec9 100644
--- a/audio/Android.mk
+++ b/audio/Android.mk
@@ -29,11 +29,12 @@ LOCAL_MODULE_PATH_64 := $(TARGET_OUT_VENDOR)/lib64/hw
LOCAL_VENDOR_MODULE := true
LOCAL_SRC_FILES := audio_hw.c
-LOCAL_SHARED_LIBRARIES := liblog libcutils libtinyalsa
+LOCAL_SHARED_LIBRARIES := liblog libcutils libtinyalsa libaudioroute
LOCAL_CFLAGS := -Wno-unused-parameter
LOCAL_C_INCLUDES += \
external/tinyalsa/include \
external/expat/lib \
+ $(call include-path-for, audio-route) \
system/media/audio_utils/include \
system/media/audio_effects/include
diff --git a/audio/audio_hw.c b/audio/audio_hw.c
index d601ea8..7be7178 100644
--- a/audio/audio_hw.c
+++ b/audio/audio_hw.c
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#define MIXER_XML_PATH "/vendor/etc/mixer_paths.xml"
+
#define LOG_TAG "audio_hw_dragonboard"
//#define LOG_NDEBUG 0
@@ -33,6 +35,7 @@
#include <system/audio.h>
#include <hardware/audio.h>
+#include <audio_route/audio_route.h>
#include <sound/asound.h>
#include <tinyalsa/asoundlib.h>
#include <audio_utils/resampler.h>
@@ -69,6 +72,8 @@ struct alsa_audio_device {
int devices;
struct alsa_stream_in *active_input;
struct alsa_stream_out *active_output;
+ struct audio_route *audio_route;
+ struct mixer *mixer;
bool mic_mute;
};
@@ -671,6 +676,35 @@ static int adev_open(const hw_module_t* module, const char* name,
*device = &adev->hw_device.common;
+ /* TODO: Ideally we should use Alsa UCM instead of libaudioroute
+ * because with Alsa UCM:
+ * - We can share the work with GNU/Linux. For instance we
+ * might have automatic support for the PinePhone and our
+ * work would benefit GNU/Linux distributions as well.
+ * - It opens the door to generic images: With Alsa UCM, we
+ * don't need build time configuration anymore: we could
+ * ship a single audio library and Alsa UCM would take care
+ * of the routing and abstract away the device specific part
+ * for us. If we code that ourselves, it will probably not
+ * be as fine grained nor as good as Alsa UCM.
+ * - It can be experimented with without even recompiling, this
+ * could make porting Replicant to new devices much less time
+ * consuming and way easier.
+ */
+ adev->mixer = mixer_open(CARD_OUT);
+
+ if (!adev->mixer) {
+ ALOGE("Unable to open the mixer, aborting.");
+ return -EINVAL;
+ }
+
+ /* Set default audio route */
+ adev->audio_route = audio_route_init(CARD_OUT, MIXER_XML_PATH);
+ if (!adev->audio_route) {
+ ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
+ return -EINVAL;
+ }
+
return 0;
}
diff --git a/audio/mixer_paths.xml b/audio/mixer_paths.xml
new file mode 100644
index 0000000..7932fec
--- /dev/null
+++ b/audio/mixer_paths.xml
@@ -0,0 +1,151 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<mixer>
+ <!--
+ +==========+
+ | Defaults |
+ +==========+
+ -->
+
+ <!-- do not change the adc & dac source of AIF2 -->
+ <ctl name="AIF2DACL Source" value="0" />
+ <ctl name="AIF2DACR Source" value="0" />
+ <ctl name="AIF2ADCL Source" value="0" />
+ <ctl name="AIF2ADCR Source" value="1" />
+
+ <!-- AIF1->DAC1 -->
+ <ctl name="DAC1 Switch" value="1" />
+
+ <!-- general -->
+ <ctl name="IN1L ZC Switch" value="0" />
+ <ctl name="IN1R ZC Switch" value="0" />
+ <ctl name="IN2L ZC Switch" value="0" />
+ <ctl name="IN2R ZC Switch" value="0" />
+ <ctl name="Output ZC Switch" value="0" />
+ <ctl name="Speaker ZC Switch" value="0" />
+ <ctl name="Headphone ZC Switch" value="0" />
+
+ <!-- AIF1->DAC1 -->
+ <ctl name="DAC1L Mixer AIF1.1 Switch" value="1" />
+ <ctl name="DAC1R Mixer AIF1.1 Switch" value="1" />
+ <ctl name="DAC1 Switch" value="1" />
+
+ <!-- ADC->AIF2 -->
+ <ctl name="AIF2DAC2L Mixer Left Sidetone Switch" value="1" />
+ <ctl name="AIF2DAC2L Mixer Right Sidetone Switch" value="0" />
+ <ctl name="AIF2DAC2R Mixer Left Sidetone Switch" value="0" />
+ <ctl name="AIF2DAC2R Mixer Right Sidetone Switch" value="1" />
+ <ctl name="DAC2 Left Sidetone Volume" value="12" />
+ <ctl name="DAC2 Right Sidetone Volume" value="12" />
+ <ctl name="DAC2 Switch" value="1" />
+
+ <!-- DAC1->HP -->
+ <ctl name="Left Headphone Mux" value="Mixer" />
+ <ctl name="Right Headphone Mux" value="Mixer" />
+
+ <!-- DAC1->SPKL/R->SPKL/R Boost->SPK -->
+ <ctl name="SPKL DAC1 Switch" value="1" />
+ <ctl name="SPKR DAC1 Switch" value="1" />
+ <ctl name="SPKL Boost SPKL Switch" value="1" />
+ <ctl name="SPKL Boost SPKR Switch" value="1" />
+ <ctl name="SPKR Boost SPKL Switch" value="0" />
+ <ctl name="SPKR Boost SPKR Switch" value="1" />
+ <ctl name="Speaker Mixer Volume" value="3" />
+
+ <!-- DAC->Output mixer->Earpiece -->
+ <ctl name="Left Output Mixer DAC Switch" value="1" />
+ <ctl name="Right Output Mixer DAC Switch" value="1" />
+ <ctl name="Earpiece Mixer Left Output Switch" value="1" />
+ <ctl name="Earpiece Mixer Right Output Switch" value="1" />
+ <ctl name="Earpiece Switch" value="1" />
+
+ <!-- LINEOUT -->
+ <ctl name="LINEOUT2N Mixer Left Output Switch" value="1" />
+ <ctl name="LINEOUT2P Mixer Right Output Switch" value="1" />
+ <ctl name="LINEOUT1N Mixer Right Output Switch" value="1" />
+ <ctl name="LINEOUT1P Mixer Left Output Switch" value="1" />
+
+ <!-- Input mixer->ADC->AIF1.1 -->
+ <ctl name="AIF1ADC1L Mixer ADC/DMIC Switch" value="1" />
+ <ctl name="AIF1ADC1R Mixer ADC/DMIC Switch" value="1" />
+
+ <!-- Main Mic->IN1LP/N->Input Mixer with +30dB at mixer -->
+ <ctl name="IN1L PGA IN1LP Switch" value="1" />
+ <ctl name="IN1L PGA IN1LN Switch" value="1" />
+ <ctl name="MIXINL IN1L Volume" value="1" />
+ <ctl name="IN1L Switch" value="1" />
+
+ <!-- Sub Mic->IN1RP/N->Input Mixer with +30dB at mixer -->
+ <ctl name="IN1R PGA IN1RP Switch" value="1" />
+ <ctl name="IN1R PGA IN1RN Switch" value="1" />
+ <ctl name="MIXINR IN1R Volume" value="1" />
+ <ctl name="IN1R Switch" value="1" />
+
+ <!-- FM Radio->IN2RP/N->Input Mixer with +30dB at mixer -->
+ <ctl name="IN2R PGA IN2RP Switch" value="1" />
+ <ctl name="IN2R PGA IN2RN Switch" value="1" />
+ <ctl name="MIXINR IN2R Volume" value="1" />
+ <ctl name="IN2R Switch" value="1" />
+
+ <!-- Ear Mic->IN2LP/N->Input Mixer with +30dB at mixer -->
+ <ctl name="IN2L PGA IN2LP Switch" value="1" />
+ <ctl name="IN2L PGA IN2LN Switch" value="1" />
+ <ctl name="MIXINL IN2L Volume" value="1" />
+ <ctl name="IN2L Switch" value="1" />
+
+ <!-- Input mixer->ADC->AIF1 -->
+ <ctl name="AIF1ADC1L Mixer ADC/DMIC Switch" value="1" />
+ <ctl name="AIF1ADC1R Mixer ADC/DMIC Switch" value="1" />
+ <ctl name="ADCL Mux" value="ADC" />
+
+ <!-- HPF on to take out some bounce -->
+ <ctl name="Sidetone HPF Switch" value="0" />
+
+ <!-- Work around core issue -->
+ <ctl name="ADCL Mux" value="DMIC" />
+ <ctl name="ADCL Mux" value="ADC" />
+ <ctl name="ADCR Mux" value="DMIC" />
+ <ctl name="ADCR Mux" value="ADC" />
+
+ <!-- AIF2ADCDAT to AIF3ADC mux -->
+ <ctl name="AIF3ADC Mux" value="1" />
+
+ <!-- Default all outputs off -->
+ <ctl name="HP Switch" value="0" />
+ <!-- <ctl name="SPK Switch" value="0" /> -->
+ <ctl name="RCV Switch" value="0" />
+ <ctl name="LINE Switch" value="0" />
+ <ctl name="HDMI Switch" value="0" />
+
+ <!-- Default all inputs off -->
+ <ctl name="Main Mic Switch" value="0" />
+ <ctl name="Sub Mic Switch" value="0" />
+ <ctl name="Headset Mic Switch" value="0" />
+ <ctl name="FM In Switch" value="0" />
+
+ <!-- EQ Switches -->
+ <ctl name="AIF1DAC1 EQ Switch" value="1" />
+ <ctl name="AIF1DAC1 EQ1 Volume" value="9" />
+ <ctl name="AIF1DAC1 EQ2 Volume" value="7" />
+ <ctl name="AIF1DAC1 EQ3 Volume" value="10" />
+ <ctl name="AIF1DAC1 EQ4 Volume" value="13" />
+ <ctl name="AIF1DAC1 EQ5 Volume" value="12" />
+
+ <!--
+ +============+
+ | Speaker on |
+ +============+
+ -->
+
+ <ctl name="SPK Switch" value="1" />
+ <ctl name="AIF1DAC1 Volume" value="96" />
+ <ctl name="AIF1 Boost Volume" value="0" />
+ <ctl name="DAC1 Volume" value="96" />
+ <ctl name="Left Output Mixer DAC Volume" value="7" />
+ <ctl name="Right Output Mixer DAC Volume" value="7" />
+ <ctl name="SPKL DAC1 Volume" value="1" />
+ <ctl name="SPKR DAC1 Volume" value="1" />
+ <ctl name="Speaker Mixer Volume" value="3" />
+ <ctl name="Speaker Boost Volume" value="4" />
+ <ctl name="Speaker Volume" value="57" />
+
+ </mixer>
diff --git a/midas.mk b/midas.mk
index 6514cb0..aaba6ef 100644
--- a/midas.mk
+++ b/midas.mk
@@ -37,6 +37,12 @@ PRODUCT_PACKAGES += android.hardware.soundtrigger@2.2-impl
# HAL for handling audio frames
PRODUCT_PACKAGES += audio.primary.exynos4
+# Hal for handling alsa controls, for instance the switch between speakers and
+# headphones.
+PRODUCT_PACKAGES += libaudioroute
+PRODUCT_COPY_FILES += \
+ $(LOCAL_PATH)/audio/mixer_paths.xml:$(TARGET_COPY_OUT_VENDOR)/etc/mixer_paths.xml
+
# We do need debug utilities on the target to enable users to be able to give
# certain information without needing to recompile an image. In addition it
# makes experimenting with audio easier.