Select I2S0 for audio output in Android

Hi,

I have an I2S DAC connected to I2S0. I can play back audio files using tinyplay. How can I configure Android to play back audio files on the selected card/device (Card 0, Device 1 in this case)?

I have the Java code set up and that is showing the right logging messages, but Iḿ not hearing anyhting :slight_smile:

Same goes for an I2S microphone I have connected to I2S0 (Card 0, Device 1) and/or a USB microphone (Card 1, Device 0).

Ok I found it. /device/linaro/hikey/audio/audio_hw.c.

This allows me to select the output card/device and that works. However, I can’t find a way to select an audio input device. Is the Audio HAL even complete in that sense?

Audio input is NOT implemented in that HAL.

Mine is much more complete. It implements input, HOWEVER, I haven’t actually tested input despite it being implemented.

Thanks I’ll have a look at it tonight.

One thing you will have to be aware of is that you may have to make adjustments based on the topology of your audio devices. I’ve entirely removed the HDMI audio sink from DT on my kernel.

I simply dropped in your HAL and it worked right away. I am now using a USB mic/speaker device which was automatically selected. The hardware I have now set up with the direct I2S devices doesn’t have a display so it would be quite cumbersome to grant recording permissions in an Android app.

A notable difference from using tinycap (which works great with the USB mic levels-wise) is that in Android (using MediaRecorder) the mic levels are pretty low again. That should be fixable though…

Thanks again! I would be nowhere without your contributions…

[edit]

I’m trying to follow what happens in your HAL, but for some reason logcat only shows a few lines:

    04-04 19:19:55.562  2203  2330 D modules.car96audio_hal.hikey: adev_set_parameters: kvpairs: A2dpSuspended=false
04-04 19:19:55.563  2203  2330 D modules.car96audio_hal.hikey: adev_set_parameters: kvpairs: BT_SCO=off
04-04 19:20:23.250  2203  2203 D modules.car96audio_hal.hikey: adev_set_parameters: kvpairs: A2dpSuspended=false
04-04 21:11:08.861  2203  2203 D modules.car96audio_hal.hikey: adev_set_parameters: kvpairs: card=1;connect=16384;device=0
04-04 21:11:09.177  2203  2203 D modules.car96audio_hal.hikey: SCANDIR found SoC card at 0
04-04 21:11:09.179  2203  2330 D modules.car96audio_hal.hikey: adev_set_parameters: kvpairs: card=1;connect=-2147479552;device=0

But nothing when it actually plays back audio or records audio. is that normal? or…is something else actually doing the playback and recording and I’m just thinking it is your HAL?

If you’re using a usb device then it won’t be using my hal – it’ll be using the usb audio hal instead.

Yeah I figured that out just now…a combination of setting the right output format & encoder and call volume (?) actually also fixed the low levels and bad quality.

Ideally I’d like to use I2S, not in the least because of the so-so debugging over WiFi you’ll need to do when using USB clients.