How to port new audio codec into Android

 

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/fsl/.  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/fsl/. 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 alsa-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. Use SPDIF codec as example.
static 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     = NULL,
    .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,                  // which 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_hal.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_card,                        //please add the card before the null_card.
     &null_card,
 };


c. Finished. Compile the file and test.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值