AnsweredAssumed Answered

How to write source code for Android Audio HAL

Question asked by felix yang on Jan 10, 2017
Latest reply on Jan 11, 2017 by felix yang

Hello everyone:

I'm porting the sound card wm8904 driver for Android 4.4.2, kernel version is 3.0.35, cpu is imx6q. I have some questions to ask everybody who know it:

1.I use tinyplay to test wm8904 driver.At a time when a song play over,I paly another right now.Then the system seems like blocking,and show some errors like that.I must wait about 20 seconds to play another.

 

2.When system start, it's shows some wrong:

Why failed to add route SPKOUT->EXT Spk, the sound card can work well on tinyplay?

 

3.How to write source code for Android Audio HAL?I 

Under the 'hardware/imx/alsa' directory,there are many sound cards configure files for android,I copy config_wm8962.h to config_wm8904.h,and change some,here are my codes:

#ifndef ANDROID_INCLUDE_IMX_CONFIG_WM8904_H
#define ANDROID_INCLUDE_IMX_CONFIG_WM8904_H

#include "audio_hardware.h"
//#define MIXER_WM8904_SPEAKER_VOLUME "Speaker Volume"
//#define MIXER_WM8904_SPEAKER_SWITCH "Speaker Switch"

#define MIXER_WM8904_HEADPHONE_VOLUME "Headphone Volume"
#define MIXER_WM8904_HEADPHONE_SWITCH "Headphone Switch"

#define MIXER_WM8904_LINEOUT_VOLUME "Line Output Volume"
#define MIXER_WM8904_LINEOUT_SWITCH "Line Output Switch"

#define MIXER_WM8904_CAPTURE_SWITCH "Capture Switch"
#define MIXER_WM8904_CAPTURE_VOLUME "Capture Volume"

#define MIXER_WM8904_INPGAR_IN3R_SWITCH "INPGAR IN3R Switch"
#define MIXER_WM8904_MIXINR_IN3R_SWITCH "MIXINR IN3R Switch"
#define MIXER_WM8904_MIXINR_IN3R_VOLUME "MIXINR IN3R Volume"

#define MIXER_WM8904_MIXINR_PGA_SWITCH "MIXINR PGA Switch"
#define MIXER_WM8904_MIXINR_PGA_VOLUME "MIXINR PGA Volume"

#define MIXER_WM8904_DIGITAL_CAPTURE_VOLUME "Digital Capture Volume"

#define MIXER_WM8904_DIGITAL_PLAYBACK_VOLUME "Digital Playback Volume"


/* These are values that never change */
static struct route_setting defaults_wm8904[] = {
/* general */
{
.ctl_name = MIXER_WM8904_DIGITAL_PLAYBACK_VOLUME,
.intval = 96,
},
{
.ctl_name = NULL,
},
};

static struct route_setting bt_output_wm8904[] = {
{
.ctl_name = NULL,
},
};

static struct route_setting speaker_output_wm8904[] = {
{
.ctl_name = MIXER_WM8904_HEADPHONE_SWITCH,
.intval = 0,
},
{
.ctl_name = MIXER_WM8904_HEADPHONE_VOLUME,
.intval = 63,
},
{
.ctl_name = NULL,
},
};

static struct route_setting hs_output_wm8904[] = {
{
.ctl_name = MIXER_WM8904_LINEOUT_SWITCH,
.intval = 1,
},
{
.ctl_name = MIXER_WM8904_LINEOUT_VOLUME,
.intval = 63,
},
{
.ctl_name = NULL,
},
};

static struct route_setting earpiece_output_wm8904[] = {
{
.ctl_name = NULL,
},
};

static struct route_setting vx_hs_mic_input_wm8904[] = {
{
.ctl_name = NULL,
},
};


static struct route_setting mm_main_mic_input_wm8904[] = {
{
.ctl_name = MIXER_WM8904_CAPTURE_SWITCH,
.intval = 1,
},
{
.ctl_name = MIXER_WM8904_CAPTURE_VOLUME,
.intval = 63,
},
{
.ctl_name = MIXER_WM8904_DIGITAL_CAPTURE_VOLUME,
.intval = 127,
},/*
{
.ctl_name = MIXER_WM8904_INPGAR_IN3R_SWITCH,
.intval = 1,
},
{
.ctl_name = MIXER_WM8904_MIXINR_PGA_SWITCH,
.intval = 1,
},
{
.ctl_name = MIXER_WM8904_MIXINR_PGA_VOLUME,
.intval = 7,
},*/
{
.ctl_name = MIXER_WM8904_MIXINR_IN3R_SWITCH,
.intval = 1,
},
{
.ctl_name = MIXER_WM8904_MIXINR_IN3R_VOLUME,
.intval = 7,
},
{
.ctl_name = NULL,
},
};


static struct route_setting vx_main_mic_input_wm8904[] = {
{
.ctl_name = NULL,
},
};

/*hs_mic exchanged with main mic for sabresd, because the the main is no implemented*/
static struct route_setting mm_hs_mic_input_wm8904[] = {
{
.ctl_name = MIXER_WM8904_CAPTURE_SWITCH,
.intval = 1,
},
{
.ctl_name = MIXER_WM8904_CAPTURE_VOLUME,
.intval = 63,
},
{
.ctl_name = MIXER_WM8904_DIGITAL_CAPTURE_VOLUME,
.intval = 127,
},/*
{
.ctl_name = MIXER_WM8904_INPGAR_IN3R_SWITCH,
.intval = 1,
},
{
.ctl_name = MIXER_WM8904_MIXINR_PGA_SWITCH,
.intval = 1,
},
{
.ctl_name = MIXER_WM8904_MIXINR_PGA_VOLUME,
.intval = 7,
},*/
{
.ctl_name = MIXER_WM8904_MIXINR_IN3R_SWITCH,
.intval = 1,
},
{
.ctl_name = MIXER_WM8904_MIXINR_IN3R_VOLUME,
.intval = 7,
},
{
.ctl_name = NULL,
},
};

static struct route_setting vx_bt_mic_input_wm8904[] = {
{
.ctl_name = NULL,
},
};


static struct route_setting mm_bt_mic_input_wm8904[] = {
{
.ctl_name = NULL,
},
};

/* ALSA cards for IMX, these must be defined according different board / kernel config*/
static struct audio_card wm8904_card = {
.name = "wm8904-audio",
.driver_name = "wm8904-audio",
.supported_out_devices = (AUDIO_DEVICE_OUT_EARPIECE |
AUDIO_DEVICE_OUT_SPEAKER |
AUDIO_DEVICE_OUT_WIRED_HEADSET |
AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET |
AUDIO_DEVICE_OUT_ALL_SCO |
AUDIO_DEVICE_OUT_DEFAULT ),
.supported_in_devices = (
AUDIO_DEVICE_IN_COMMUNICATION |
AUDIO_DEVICE_IN_AMBIENT |
AUDIO_DEVICE_IN_BUILTIN_MIC |
AUDIO_DEVICE_IN_WIRED_HEADSET |
AUDIO_DEVICE_IN_BACK_MIC |
AUDIO_DEVICE_IN_ALL_SCO |
AUDIO_DEVICE_IN_DEFAULT),
.defaults = defaults_wm8904,
.bt_output = bt_output_wm8904,
.speaker_output = speaker_output_wm8904,
.hs_output = hs_output_wm8904,
.earpiece_output = earpiece_output_wm8904,
.vx_hs_mic_input = vx_hs_mic_input_wm8904,
.mm_main_mic_input = mm_main_mic_input_wm8904,
.vx_main_mic_input = vx_main_mic_input_wm8904,
.mm_hs_mic_input = mm_hs_mic_input_wm8904,
.vx_bt_mic_input = vx_bt_mic_input_wm8904,
.mm_bt_mic_input = mm_bt_mic_input_wm8904,
.card = 0,
.out_rate = 0,
.out_channels = 0,
.out_format = 0,
.in_rate = 0,
.in_channels = 0,
.in_format = 0,
};

#endif /* ANDROID_INCLUDE_IMX_CONFIG_WM8904_H */

 

 

The android system can't play any songs,I test my driver with tinyplay,and it's work well.

So,How to code config_wm8904.h ? I'm very hopeless!!

 

That are my questions.Thanks very much.

Outcomes