How can I use I2S pins to output audio with Ubuntu image

I bought a DAC MAX98357A to convert I2S signal to analog signal for a speaker.

Can I output the audio to I2S pins on VIM3 under Ubuntu ?

Thank you very much

I found out how to do it correctly so here you are:

  • To connect MAX98357A <–> Khadas:

    • LRC <–> pin 32 I2SB_LRCK
    • BCLK <–> pin 29 I2SB_SCLK
    • DIN <–> pin 31 I2SB_SDO
  • Do aplay -l to find out the device number correspond to i2s:

**** List of PLAYBACK Hardware Devices ****
card 0: AMLAUGESOUND [AML-AUGESOUND], device 0: SPDIF-B-dit-hifi-alsaPORT-spdif-b dit-hifi-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: AMLAUGESOUND [AML-AUGESOUND], device 1: TDM-A-dummy-alsaPORT-pcm multicodec-1 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: AMLAUGESOUND [AML-AUGESOUND], device 2: TDM-B-dummy-alsaPORT-i2s multicodec-2 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: AMLAUGESOUND [AML-AUGESOUND], device 3: TDM-C-dummy multicodec-3 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: AMLAUGESOUND [AML-AUGESOUND], device 4: SPDIF-dit-hifi-alsaPORT-spdif dit-hifi-4 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
  • Here it is the device number 2 so do speaker-test -Dhw:0,2 -t wav to play test sound
  • For a wav file to be able to play with MAX98357A, it needs to be converted to 16-bit 1-channel with the commands
sox input.wav -b16 output.wav
sox input.wav onechannel.wav remix 1 # 1 for left channel and 2 for right channel
  • Then do speaker-test -Dhw:0,2 -c 2 -t wav -w input.wav
2 Likes

Can anyone answer my following questions:

  • Is there any DAC pins on 40-pin header that we can use to connect to 2 pins of speaker directly ?

  • And what are those other device on the aplay -l list ?

Thank you very much

@ptphucbk take a look at the GPIO pins: https://docs.khadas.com/vim3/GPIOPinout.html

Is there any DAC pins on 40-pin header that we can use to connect to 2 pins of speaker directly ?

I don’t think there are any real DAC pins but maybe you can output audio with the PWM pin 35 like the Arduino does? Arduino isn’t intended to do real audio stuff neither has audio outputs but people manage to get decent audio out from PWM pins. Maybe Khadas staff can help you with that question.

And what are those other device on the aplay -l list ?

Take a look at Odroid N2 webpage: odroid-n2:application_note:sound [ODROID Wiki]
They have good explanations there about the aplay devices list.
So I would say:

  • device 0 = HDMI audio output
  • device 4 = SPDIF output

Now, I’m not sure about devices 1 and 3, can anyone from Khadas confirm? They seem like dummy devices for ALSA testing purposes.

Were you successful playing the audio through I2S?

2 Likes
  • device 0 = HDMI audio output
  • device 1 = Bluetooth PCM
  • devide 2 = I2S from 40PIN headers
  • device 3 = I2S from M.2 connector
  • device 4 = SPDIF output
3 Likes

@numbqq thanks for the clarification! Does that mean then that any DAC can be connected to I2S without having to write an ALSA driver for it? Or in order for apps to use the DAC as a soundcard the ALSA driver is required?

Yes, you can connect to the I2S from 40 PIN herader and use device 2 to control it.

2 Likes

Amazing, appreciated

Thank you for your answer. I will checkout audio output by PWM.

I did successfully play the audio through I2S as I described in my second reply in this thread. You can use the pcm example here to output audio and control volume by scaling your data send to I2S.

2 Likes

Hello,
Any Idea on how to make it it work using the 5.16 kernel?, since it show only one device.
card 0: KHADASVIM3 [KHADAS-VIM3], device 0: fe.dai-link-0 (*) []
Subdevices: 0/1
Subdevice #0: subdevice #0

And there are much more options in alsamixer than when using the vendor kernel.
Thanks!