关闭

android6.0 framework修改使用两个声卡

1999人阅读 评论(0) 收藏 举报
分类:


底层有两个声卡,一个声卡播放alarm通道的声音,另外一个播放其他通道的声音

1)增加一个hal层库

复制Z:\myandroid\hardware\imx\alsa代码,修改Android.mk编译生成另外一个so库

2)修改代码一个hal层库播放一种声音。

系统起来以后会加载audio的hardware库,检测声卡,保存声卡信息。在使用mediaplayer或者audiotrack播放声音时,会通过stream_type 找对应的设备,在通过设备在要使用哪个声卡。

修改scan_available_device()函数实现,因为两个声卡的驱动名字一样,不能通过这个来加载,要不然两个audio库都会加载两个声卡。

// change compare name , because two sound card have same driver name
            //if(strstr(control_card_info_get_driver(imx_control), audio_card_list[j]->driver_name) != NULL){
            if(strstr(control_card_info_get_name(imx_control), audio_card_list[j]->name) != NULL){

修改audio_policy.conf文件:增加:

这个代表第二个hardware库的信息。支持哪些设备等。

 sub {    
      outputs {
      sub_device  {
        sampling_rates 48000
        channel_masks AUDIO_CHANNEL_OUT_STEREO
        formats AUDIO_FORMAT_PCM_16_BIT
        devices AUDIO_DEVICE_OUT_SPEAKER|AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET
      }
    }
  }


修改声卡设置信息:主要支持的设备和audio_policy.conf中配置的设备要一致。第一个声卡:

static struct audio_card  wm8958_card = {

    //modified by leo, change sound card
    //.name = "wm8958-audio",
    //.driver_name = "wm8958-audio",
    .name = "imx-audio-ms6323",
    .driver_name = "imx-audio-ms6323",

supported_out_devices = (AUDIO_DEVICE_OUT_EARPIECE |
            AUDIO_DEVICE_OUT_SPEAKER |
            AUDIO_DEVICE_OUT_WIRED_HEADSET |
            AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
            AUDIO_DEVICE_OUT_ALL_SCO |
            AUDIO_DEVICE_OUT_DEFAULT),

第二个声卡:

/* ALSA cards for IMX, these must be defined according different board / kernel config*/
static struct audio_card  wm8958_card = {

    //modified by leo, change sound card
    //.name = "wm8958-audio",
    //.driver_name = "wm8958-audio",
    .name = "imx-audio-ms6324",
    .driver_name = "imx-audio-ms6324",
    .supported_out_devices = (AUDIO_DEVICE_OUT_SPEAKER|AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET),


好了,剩下的就是把特定的straem_type导向到那个声卡:

首先在RoutingStrategy.h中增加一个路由节点:

enum routing_strategy {
    STRATEGY_MEDIA,
    STRATEGY_PHONE,
    STRATEGY_SONIFICATION,
    STRATEGY_SONIFICATION_RESPECTFUL,
    STRATEGY_DTMF,
    STRATEGY_ENFORCED_AUDIBLE,
    STRATEGY_TRANSMITTED_THROUGH_SPEAKER,
    STRATEGY_ACCESSIBILITY,
    STRATEGY_REROUTING,

    //modified by leo, change alarm sound use another sound card, 2016-5-18
    STRATEGY_SUB,
    NUM_STRATEGIES
};

在修改Engine.cpp,把stream_type中的alarm通道声音导向这个路由:

routing_strategy Engine::getStrategyForStream(audio_stream_type_t stream)
{
    // stream to strategy mapping
    switch (stream) {
    case AUDIO_STREAM_VOICE_CALL:
    case AUDIO_STREAM_BLUETOOTH_SCO:
        return STRATEGY_PHONE;
    case AUDIO_STREAM_RING:
        return STRATEGY_SONIFICATION;
    case AUDIO_STREAM_ALARM:
        //return STRATEGY_SONIFICATION;
        ////modified by leo, change alarm sound use another sound card, 2016-5-18
        ALOGV("change alarm sound use another sound card");
        return STRATEGY_SUB;
    case AUDIO_STREAM_NOTIFICATION:
        return STRATEGY_SONIFICATION_RESPECTFUL;
    case AUDIO_STREAM_DTMF:
        return STRATEGY_DTMF;
    default:
        ALOGE("unknown stream type %d", stream);
    case AUDIO_STREAM_SYSTEM:
        // NOTE: SYSTEM stream uses MEDIA strategy because muting music and switching outputs
        // while key clicks are played produces a poor result
    case AUDIO_STREAM_MUSIC:
        return STRATEGY_MEDIA;
    case AUDIO_STREAM_ENFORCED_AUDIBLE:
        return STRATEGY_ENFORCED_AUDIBLE;
    case AUDIO_STREAM_TTS:
        return STRATEGY_TRANSMITTED_THROUGH_SPEAKER;
    case AUDIO_STREAM_ACCESSIBILITY:
        return STRATEGY_ACCESSIBILITY;
    case AUDIO_STREAM_REROUTING:
        return STRATEGY_REROUTING;
    }
}


routing_strategy Engine::getStrategyForUsage(audio_usage_t usage)
{
    const SwAudioOutputCollection &outputs = mApmObserver->getOutputs();

    // usage to strategy mapping
    switch (usage) {
    case AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY:
        if (outputs.isStreamActive(AUDIO_STREAM_RING) ||
                outputs.isStreamActive(AUDIO_STREAM_ALARM)) {
            return STRATEGY_SONIFICATION;
        }
        if (isInCall()) {
            return STRATEGY_PHONE;
        }
        return STRATEGY_ACCESSIBILITY;

    case AUDIO_USAGE_MEDIA:
    case AUDIO_USAGE_GAME:
    case AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE:
    case AUDIO_USAGE_ASSISTANCE_SONIFICATION:
        return STRATEGY_MEDIA;

    case AUDIO_USAGE_VOICE_COMMUNICATION:
        return STRATEGY_PHONE;

    case AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING:
        return STRATEGY_DTMF;

    case AUDIO_USAGE_ALARM:
    case AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE:
        //return STRATEGY_SONIFICATION;
        ////modified by leo, change alarm sound use another sound card, 2016-5-18
        return STRATEGY_SUB;
    
    case AUDIO_USAGE_NOTIFICATION:
    case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST:
    case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT:
    case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED:
    case AUDIO_USAGE_NOTIFICATION_EVENT:
        return STRATEGY_SONIFICATION_RESPECTFUL;

    case AUDIO_USAGE_UNKNOWN:
    default:
        return STRATEGY_MEDIA;
    }
}


再在audio_devices_t Engine::getDeviceForStrategy(routing_strategy strategy) const函数中,把这个路由节点的设备改为AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET

这个设备只在第二个声卡配置中才支持,所以就使用第二个声卡播放alarm的声音。

    case STRATEGY_SUB:        
        ALOGV("do getDeviceForStrategy availableOutputDevices.types()=0x%x",availableOutputDevices.types());
        device = AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET;    
        break;




0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:3612次
    • 积分:120
    • 等级:
    • 排名:千里之外
    • 原创:9篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档