How to port new audio codec into Android

goatishspyΚινητά – Ασύρματες Τεχνολογίες

10 Δεκ 2013 (πριν από 3 χρόνια και 8 μήνες)

110 εμφανίσεις

How to port new audio codec into Android


1.

Prepare

the codec driver

The codec driver is under alsa
-
driver, the code is in kernel_imx/sound. For each
codec driver , it includes three part: codec driver, machine driver and platform
driver.

a.

Codec driver

It is put in
sound/soc/codecs/
. If you do not find the codec driver you need,
please ask the codec vendor to supply.

b.

Platform driver

it is in sound/soc/imx/.

Platform driver is for the interface and dma operation in
the soc. We already have these drivers,

like
imx
-
ssi.c
,
imx
-
pcm
-
dma
-
mx2.c
.

c.

Machine driver

It is in sound/soc/imx/. This driver is the only one that user need to write. Which
is the connection of Codec driver and platform driver.

Please refer

imx
-
wm8962.c


2.

Test the codec driver

If you use the a
lsa
-
lib,
Use the alsa
-
player
,
alsa
-
recorder
,

alsa
-
mixer to verify the codec
driver, to found the issues.


If you use tinyalsa interface, please use tinycap, tinyplay, tinymix to test.


3.

Add the codec in the Audio HAL

We use the tinyalsa

as the default interface which is supplied by Google.
The audio HAL
for android is in hardware/imx/alsa/. It is easy to add new codec in this hal.

a.

Add a new configure file for the codec. Like config_wm8962.h, config_hdmi.h
.
U
se SPDIF

codec

as example.

sta
tic struct audio_card
spdif
_card

= {


.name = "imx
-
spdif
",


.driver_name = "
imx
-
spdif
",

//driver_name, which is used to scan the
supported sound card.


.supported_devices = AUDIO_DEVICE_OUT_AUX_DIGITAL |
AUDIO_DEVICE_IN_AUX_DIGITAL,

//which devices is supported by the card.


.defaults = NULL,

// mixer control for different route


.bt_output = NULL,


.speaker_output = NULL,


.hs_output = NULL,


.earpiece_output = NU
LL,


.vx_hs_mic_input = NULL,


.mm_main_mic_input = NULL,


.vx_main_mic_input = NULL,


.mm_hs_mic_input = NULL,


.vx_bt_mic_input = NULL,


.mm_bt_mic_input = NULL,


.card = 0,

// whic
h will be set by the HAL.


.out_rate = 0,

//which will be set by the HAL


.in_rate = 0,

//which will be set by the HAL.

};


b.

Add the configure file in the
tinyalsa_hal.c
.

diff
--
git a/alsa/tinyalsa_ha
l.c b/alsa/tinyalsa_hal.c

index 8cc37a4..22148d7 100644

---

a/alsa/tinyalsa_hal.c

+++ b/alsa/tinyalsa_hal.c

@@
-
44,6 +44,7 @@


#include "config_hdmi.h"


#include "config_usbaudio.h"


#include "config_nullcard.h"

+#include "config_spdif.h"




/* ALSA ports for IMX */

@@
-
85,7 +86,7 @@


#define PRODUCT_DEVICE_PROPERTY "ro.product.device"


#define PRODUCT_NAME_PROPERTY "ro.product.name"


#define PRODUCT_DEVICE_IMX "imx"

-
#define SUPPORT_CARD_NUM 5

+#define SUPPORT_CARD_NUM 6



/*"null_card" must be in the end of this array*/


struct audio_card *audio_card_list[SUPPORT_CARD_NUM] = {

@@
-
93,6 +94,7 @@ struct audio_card *audio_card_list[SUPPORT_CARD_NUM]
= {


&wm8962_card,


&hdmi_card,


&usbaudio_card,

+ &spdif_ca
rd,

//please add the card before the null_card.


&null_card,


};


c.

Finished. Compile the file and test.