Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
344 views
in Technique[技术] by (71.8m points)

How do you make Android use a particular sound card?

I'm porting AOSP to an iMX8 board.

I have a working sgtl5000 driver and codec.

i.e. When I run:

smarc_mx8mq:/sdcard/Alarms # tinyplay file_example_WAV_1MG.wav                                                           
Playing sample: 2 ch, 8000 hz, 16 bit 1072948 bytes

music is played.

Android does not normally make any sound at all.

There are continuous errors of the form:

01-05 14:31:47.809  3383  4814 I audio_hw_primary: start_output_stream_primary... 0xedafe000, device 2, address , mode 0
01-05 14:31:47.809  3383  4814 I audio_hw_primary: select_output_device(), headphone 0 ,headset 0 ,speaker 2, earpiece 0, 
01-05 14:31:47.809  3383  4814 W audio_hw_primary: card -1, port 0 device 0x2
01-05 14:31:47.809  3383  4814 W audio_hw_primary: rate 48000, channel 2 period_size 0xc0
01-05 14:31:47.809  3383  4814 E audio_hw_primary: cannot open pcm_out driver 0: cannot open device '/dev/snd/pcmC4294967295D0p': No such file or directory

If apply a very ugly hack:

smarc_mx8mq:/dev/snd # ln -s pcmC0D0p pcmC4294967295D0p

sound now works in Android, until the next reboot.


I've found a file called imx/alsa/config_sgtl5000.h which has a section:

static struct audio_card sgtl5000_card = {
    .name = "sgtl5000-audio",
    .driver_name = "sgtl5000-audio",
    .bus_name = "I2S1",
    .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_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 | AUDIO_DEVICE_IN_BUS),
    .defaults = NULL,
    .bt_output = NULL,
    .speaker_output = speaker_output_sgtl5000,
    .hs_output = NULL,
    .earpiece_output = NULL,
    .vx_hs_mic_input = NULL,
    .mm_main_mic_input = mm_main_mic_input_sgtl5000,
    .vx_main_mic_input = NULL,
    .mm_hs_mic_input = NULL,
    .vx_bt_mic_input = NULL,
    .mm_bt_mic_input = NULL,
    .card = 0,
    .out_rate = 0,
    .out_channels = 0,
    .out_format = 0,
    .in_rate = 0,
    .in_channels = 0,
    .in_format = 0,
};

I'm currently inferring that Android asks for a sound card that can do X and that the return value is -1 (4294967295 as a uint32_t).

There is than a lack of error-checking which causes an attempt to open sound card -1 at /dev/snd/pcmC4294967295D0p.

How do I make the sgtl5000 become the default sound card for Android?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...