Jump to content

I2S on Orange Pi H3


Recommended Posts

tkaiser has built a new Kernel with i2s Modules. With this Kernel and some cheap DAC  e.g. (http://www.ebay.de/itm/Audiophonics-I2S-DAC-ES9023-Sabre-to-Analog-24bit-192KHZ-fur-Raspberry-PI-/291573327639?hash=item43e31fe717:g:TTwAAOSw~OdVZXtm)  it is possible to get good quality sound  out of the Orange Pis. After installing the Kernel

Two Things have to be changed in the fex File:

 

Change Directory to boot:

cd /boot

Turn the script.bin to a fex-File and open it in an Editor

sudo bin2fex script.bin script.fex
sudo nano script.fex

Now change the following Entries:

[twi1]
twi_used = 1

to

[twi1]
twi_used = 0

and

[pcm0]
daudio_used = 0

to

[pcm0]
daudio_used = 1

Save your changes and do :

sudo fex2bin script.fex script.bin

After a reboot your done.

 

 

I do not know for what the Section [twi1] is good for, i hope nothing serious..

This connections have to be made:

 

5V > Pin 2

Gnd > Pin6

BCK > Pin 27

LRCK > Pin 28

Data > Pin37

 

(according to the Picture "giachi" has posted on the diyaudio Forum http://www.diyaudio.com/forums/pc-based/285427-i2s-connection-orange-dac.html#post4587580

see below)

 

The second Picture is only for orientation :) on an Orangepi PC, the red Wire is 5V ! Be aware that the Header is rotated by 180°on the One!

 

That´s all .

 

Regards

post-578-0-59118400-1456768124_thumb.png

post-578-0-99013800-1456768163_thumb.png

Link to comment
Share on other sites

Armbian & Khadas are rewarding contributors

Thank you for the tutorial! A few questions/suggestions:

  • Would be great if you could upload the picture and add it to your to post ("My Media") [x] done
  • Please also adjust the post title so that it reads "[Tutorial] I2S on Orange Pi H3" instead [x] done
  • This tutorial should work with all the other H3 variants also (please keep in mind that on the One the GPIO header is rotated by 180°)
  • tw1 is used for SPI IIRC
  • Unfortunately Pin 37 is in conflict with 1-Wire as soon as the modules are loaded (look in /etc/modules) so if you want to use both I2S and 1-Wire you have to adjust the GPIO pin used for 1-Wire in the fex file
  • Now the question from an audio NOOB: How to proceed to use the I2S DAC instead? Which steps have then to be taken in Armbian to achieve this?

Thx again!

Link to comment
Share on other sites

  • Now the question from an audio NOOB: How to proceed to use the I2S DAC instead? Which steps have then to be taken in Armbian to achieve this?

 I do not know if i understand this question the right way. After you have connected the DAC there are three soundcards

aplay -l

will show us this:

root@orangepipc:~# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: audiocodec [audiocodec], device 0: SUNXI-CODEC sndcodec-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: snddaudio [snddaudio], device 0: SUNXI-TDM0 snddaudio-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: sndhdmi [sndhdmi], device 0: SUNXI-HDMIAUDIO sndhdmi-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0

In this case it is possible to access the i2s card with hw:1 or better  hw:snddaudio in your audio applications. (Be aware , that you can see this three cards even when only the Modules are loaded,[pcm0]

daudio_used = 1 is changed in the fex File and there is no Card connected)

 

Regards

Link to comment
Share on other sites

Hello, But I already bought the dac, the problem is solved with pin cables (12-27 BCK, 35-28 LRCK and 40-37 DOUT). My big problem is to load the driver into the kernel.

 

Thanks a lot

Link to comment
Share on other sites

will the i2s functionality make it into the "legacy kernel" download / update. if not how does one obtain and use this kernel?

 

Or is it best to wait till such time as the vanilla kernel is available?

 

Im very new to the nuances of armbian and particularly the H3 chipset.

Link to comment
Share on other sites

My ES9024 DAC arrived earlier and I have been happily listening to music with it for the past several days. I can confirm that the instructions are correct and that the DAC works very well. The biggest challenge was soldering on female pin headers onto the wires (need small tip) and editing /boot/script.bin because I am a H3 noob (bin2fex/fex2bin).

 

An easier option, albeit of lower sound quality (16-bit 48k), is a cm108 USB Sound DAC:

 

   http://www.banggood.com/USB-Virtual-7_1-Channel-Audio-Sound-Card-Adapter-p-938086.html

 

It is plug-and-play on Armbian 5.05 and shows up as the third audio device (assuming you didn't edit script.bin for i2s):

 

   sudo aplay -l

   sudo speaker-test -twav -c2 -Dhw:2

Link to comment
Share on other sites

Thank you for the tutorial.

I bought a cheap PCM5102 board (7 euro shipment included!)

http://www.aliexpress.com/item/PCM5102-DAC-Decoder-I2S-Player-Assembled-Board-32Bit-384K-Beyond-ES9023-PCM1794-compatible-Raspberry-Pi/32678406932.html

 

I can now use my orange pi as a synthesizer (zynaddsubfx) without any glitches! (external midi keyboard!)

Even LMMS now works and sounds like a breeze.

 

The standard setup of "jackd" did not work. I start jackd manually, and afterwards qjackctl.

Link to comment
Share on other sites

In case someone would like to try music-stuff : I had no luck using the standard orangepiplus2e sound.

I had good results with a 80cents(!) usbsoundcard, but really excellent results using the PCM5102 board.

 

 

get "jackd" to work (jack is like an electronic patch board) : this is what worked for me (it  took me some time to figure this out )

jackd -d alsa -dhw:1 -P (do not launch as root, but as the default armbian user) (hw:1 = card 1 -- this might be different for you)

 

install qjackctl

(connect readable clients  to writable clients)

 

 

orangepi@orangepiplus2e:~$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: audiocodec [audiocodec], device 0: SUNXI-CODEC sndcodec-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: snddaudio [snddaudio], device 0: SUNXI-TDM0 snddaudio-0 []
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 2: sndhdmi [sndhdmi], device 0: SUNXI-HDMIAUDIO sndhdmi-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
 

orangepi@orangepiplus2e:/etc$ more asound.conf
pcm.!default {
    type hw
    card 1
}

ctl.!default {
    type hw
    card 1
}
 

Link to comment
Share on other sites

I use a PCM4222 EVM.

 

From what I seen, the current driver (daudio), is working only with 16bits capture.

 

Though the driver itself reports via alsacap that it can work at any ramplerate 8000..192000 and at 16/24/32bits as shown in Card 1, ID `snddaudio', name `snddaudio'

login as: root
root@192.168.1.131's password:
 _   _                   ____  _   _   _
| \ | | __ _ _ __   ___ |  _ \(_) | \ | | ___  ___
|  \| |/ _` | '_ \ / _ \| |_) | | |  \| |/ _ \/ _ \
| |\  | (_| | | | | (_) |  __/| | | |\  |  __/ (_) |
|_| \_|\__,_|_| |_|\___/|_|   |_| |_| \_|\___|\___/


Welcome to ARMBIAN Debian GNU/Linux 8 (jessie) 3.4.112-sun8i
System load:   0.18             Up time:       3 min
Memory usage:  9 % of 494Mb     IP:            192.168.1.131
CPU temp:      39°C
Usage of /:    11% of 15G

Last login: Fri Oct 14 17:25:47 2016 from 192.168.1.6
root@nanopineo:~# alsacap/alsacap
*** Scanning for playback devices ***
Card 0, ID `audiocodec', name `audiocodec'
  Device 0, ID `SUNXI-CODEC sndcodec-0', name `', 1 subdevices (1 available)
    1..2 channels, sampling rate 8000..192000 Hz
    Sample formats: S16_LE, S24_LE, S32_LE, S20_3LE
      Subdevice 0, name `subdevice #0'
Card 1, ID `snddaudio', name `snddaudio'
  Device 0, ID `SUNXI-TDM0 snddaudio-0', name `', 1 subdevices (1 available)
    1..2 channels, sampling rate 8000..192000 Hz
    Sample formats: S16_LE, S24_LE, S32_LE, S20_3LE
      Subdevice 0, name `subdevice #0'
Card 2, ID `sndhdmi', name `sndhdmi'
  Device 0, ID `SUNXI-HDMIAUDIO sndhdmi-0', name `', 1 subdevices (1 available)
    1..8 channels, sampling rate 8000..192000 Hz
    Sample formats: S16_LE, S24_LE, S32_LE, S20_3LE
      Subdevice 0, name `subdevice #0'
root@nanopineo:~#

There is an easy test to verify that the H3 PCM/I2S driver has a serious flaw/bug though.

 

The PCM/I2S port as it is now setup in script.bin (working only in legacy.. still pending in vanilla..)

is configuring the PCM/I2S port as master, thus it does not rely for any timing/control signal from the peripheral/codec/adc.

That is good for our testing since no additional external hardware/codec/adc is required and everyone can do the test. Anyone that has any H3 board with a PCM/I2S enabled port.

 

I do have setup the card1 as default

root@nanopineo:~# cat /etc/asound.conf
pcm.!default {
    type hw
    card 1
}

ctl.!default {
    type hw
    card 1
}

So, at first, do a 20sec capture

root@nanopineo:~# arecord -t wav -c 2 -f S24_LE -r 48000 -d 20 testrec.wav
Recording WAVE 'testrec.wav' : Signed 24 bit Little Endian, Rate 48000 Hz, Stereo
root@nanopineo:~#

You will notice, if you got a clock/timer on the other side of the screen, that this command it actually records for 40 sec!! not 20 as requested!!

So, if you play the wav file you expect it to last for 40 sec..

 

Then do play the recorded file

root@nanopineo:~# aplay testrec.wav
Playing WAVE 'testrec.wav' : Signed 24 bit Little Endian, Rate 48000 Hz, Stereo
root@nanopineo:~#

If you see the actual time passed, it will be 20 sec played, but the inital recording lasted for 40 sec..         (gotcha)

 

In any samplerate you try, either 8K or 96K or 192K it will give the same results if you do a capture with more than 16bits resolution, eg S24_LE or S32_LE.

 

Capturing with 16bits resolution eg with S16_LE everything is just fine.

 

 

Obviously the H3 PCM/I2S driver has a problem with capture in anything higher than 16bits resolution and needs to be rectified.

 

 

Christos

 

 

 

P.S.

Even if you do not rely on the -d <seconds> parameter, but you do it manualy by starting and stopping with ctrl-C and measuring the elapsed time yourself, you will notice the same thing, the recorded file lasts always half the time you recorded for, when having more than 16bits eg S24_LE.

Link to comment
Share on other sites

First of all thank you for this tutorial. It basically did work with an ES9023 DAC. I do get sound but the volume is very low compared with the same board connected to an Rasberry Zero. Is there anything I can do to increase the volume ?

Link to comment
Share on other sites

I found the problem myself. It looks like that that mpd is sending 24bit audio data by default over the i2s interface. Fore some reason either the kernel module or the ES9023 DAC does not correctly handle this data which is leading to the low volume on the output. If you force mpd to either generate 16bit or 32bit audio data everything is working correctly. You can do that in the mpd.conf file in the audio_output section. Here is the one I am using right now, which is forcing 32 bit 2 channel output.

 

audio_output {

        type            "alsa"
        name            "My ALSA Device"
        device          "hw:1,0" 
        format          "*:32:2"
}
Link to comment
Share on other sites

This would work but you will have to connect several pins either to GND or 3.3V please see: http://blogimg.goo.ne.jp/user_image/70/5e/60fd0f0bbd1c93ac131f3604608bfbdb.png

 

It would be easier to this one http://www.ebay.com/itm/PCM5102-DAC-Decoder-I2S-Player-Board-32Bit-384K-Beyond-ES9023-PCM1794-/142125650366?hash=item21175951be:g:b5sAAOSwLF1X48tC it has the same chip and you only need to connect the I2S related pins 5V and GND.

 

Or this one (I am using it right now) http://www.ebay.com/itm/Audiophonics-DAC-Sabre-ES9023-I2S-vers-Analogique-24bit-192KHZ-ll-/301441579838?hash=item462f517b3e:g:YccAAOSwD0lUj2EL

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines