Embedded Linux Encounters

A peek in to the world of Embedded Linux and stuff

  • Linux is addictive, I'm hooked!

         Geek@WastingTime>

Android Audio

Posted by Vaisakh P S On 10:54 PM 0 comments

Phew... this one was one major headache for me...
It was my first experience in linux and ALSA. So didn't have a single clue about how to configure audio ALSA. But finally I was able to do it.

The first daunting task was to bring up the audio interface for my board (as it was fresh porting of linux on to this hardware). About the audio hardware, the board is having a WM9713L IC which is used to interface Speaker and touch screen to the PXA270 processor. So I added the definition for the same under ' sound/soc/pxa/myboard.c' under my linux source tree and enabled the same in my build configuration.

After doing this, the Codec IC was detected from kernel. I tested it using mplayer which I built using buildroot. But still there was no audio output. So I started to dig into ALSA configuration. There I stumbled in to new useful utility programs:
  • amixer
  • alsamixer
Using these tools and the board schematics (especially the audio routing layout), I was to enable and route the audio with the following commands in my buildroot environment:
amixer set 'Speaker Mixer Aux Playback Swit' on
amixer set 'Speaker Mixer PC Beep Playback ' on
amixer set 'Speaker Mixer PCM Playback Swit' on
amixer set 'Left Speaker Out Mux' 'Speaker'
amixer set 'Out4' 100% on
amixer set 'Speaker' 100% on
amixer set 'PCM' 100%
amixer set 'PC Beep Playback Speaker' 100%
After this mplayer was able play audio files and the sound was clearly audible in Speaker.

Now moving on to Android, the original build tree will not contain the ALSA utils in it. So I modified the local_manifest.xml under .repo directory and added the following:

Along with that in my vendor definition file, I added the following lines (thanks many discussion in Google groups), so that Alsa Utils gets included on to the system image.

HAVE_HTC_AUDIO_DRIVER := false
BOARD_USES_GENERIC_AUDIO := false
BOARD_USES_ALSA_AUDIO := true
BUILD_WITH_ALSA_UTILS := true
Once the build was completed, I booted up Android with the kernel and new system image. After booting, in shell issued the same commands(but this time the name is alsa_amixer), and audio started working in Android too...

After this, my next aim was to automatically route the audio. On further investigation, I found that there needs to be a configuration file(/etc/asound.conf) for doing this. Also in the file, there needs be entries for 'pcm.AndroidPlayback' , 'pcm.AndroidPlayback_Speaker' etc which will be like profiles used by Android for routing Audio.

I tried putting the same "Audio Control" names that I used in alsa_amixer command. But didn't work out. Got stuck again...

I analyzed the output for various options alsa_amixer command. With one particular option - alsa_amixer -contents, I got the names of the controls and used them in asound.conf

# #
# # Mixer devices
# #

ctl.AndroidOut {
type hw
card 0
}

ctl.AndroidIn {
type hw
card 0
}

ctl.AndroidPlayback {
type hw
card 0 # Can replace with drivers name from /proc/asound/cards
}
ctl.AndroidCapture {
type hw
card 0
}

# #
# # Playback devices
# #
pcm.AndroidPlayback {
type hooks
slave.pcm {
type hw
card 0
device 0
}
hooks.0 {
type ctl_elems
hook_args [
{ name 'Speaker Mixer Aux Playback Swit' value on }
{ name 'Speaker Mixer PC Beep Playback ' value on }
{ name 'Speaker Mixer PCM Playback Swit' value on }
{ name 'Left Speaker Out Mux' value 'Speaker' }
{ name 'Out4 Playback Switch' value on }
{ name 'PC Beep Playback Speaker Volume' value 7 }
]
}
}
There you have it... Audio is working like a charm in Android. :)

Hope this helps someone... :)

Categories: , , ,

0 Response for the "Android Audio"

Post a Comment