Jump to content


Photo

[Tutorial] I2S on Orange Pi H3


65 replies to this topic

#1 Da Alchemist

Da Alchemist

    Advanced Member

  • Senior Members
  • PipPipPip
  • 82 posts

Posted 29 February 2016 - 03:19 PM

tkaiser has built a new Kernel with i2s Modules. With this Kernel and some cheap DAC  e.g. (http://www.ebay.de/i...TwAAOSw~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....ml#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

Attached Images

  • 223509vaz3a31aad76f32v.png
  • ES9023OPI.png

  • tkaiser and lanefu like this

#2 tkaiser

tkaiser

    Advanced Member

  • Moderators
  • 2886 posts

Posted 29 February 2016 - 03:40 PM

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!


Please don't send personal messages! Use the forum so others can participate and benefit!

 

Before you report any problem please be aware that crappy SD cards and insufficient power supply are reason N° 1 why things are failing. Try to rule this out first please, check 'getting started' recommendations and check/provide 'sudo armbianmonitor -u' output first!

 

Did you check out custom google powered forum search already (before opening new threads or asking questions)?


#3 Da Alchemist

Da Alchemist

    Advanced Member

  • Senior Members
  • PipPipPip
  • 82 posts

Posted 29 February 2016 - 07:23 PM

  • 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


  • tkaiser likes this

#4 Lemonlemon

Lemonlemon

    Newbie

  • Senior Members
  • Pip
  • 4 posts

Posted 28 March 2016 - 12:39 PM

Hi, does the H3 have MCLK output?

#5 Da Alchemist

Da Alchemist

    Advanced Member

  • Senior Members
  • PipPipPip
  • 82 posts

Posted 29 March 2016 - 07:13 PM

I can not answer this question exactly, but i would say no. In the Fex File PA18 (Pin28) is named MCLK.

 

Regards



#6 Lemonlemon

Lemonlemon

    Newbie

  • Senior Members
  • Pip
  • 4 posts

Posted 30 March 2016 - 05:35 PM

Thanks!

#7 pep01

pep01

    Newbie

  • Senior Members
  • Pip
  • 2 posts

Posted 03 April 2016 - 05:59 PM

Hello

 

Can you may include support for PCM1522 driver in the upcoming release. This is for connect this dac:

 

http://www.dx.com/es...03#.VwFLUHqIphE

 

Thanks for your work



#8 Da Alchemist

Da Alchemist

    Advanced Member

  • Senior Members
  • PipPipPip
  • 82 posts

Posted 03 April 2016 - 08:48 PM

You can not use this DAC because the OPI PC is not Pin Compatible with the RPI.

 

Regards



#9 Eng-Shien Wu

Eng-Shien Wu

    Member

  • Senior Members
  • PipPip
  • 20 posts

Posted 04 April 2016 - 07:27 AM

BTW, here is an alternative source for the ES9024 DAC:
http://www.banggood....-p-1012053.html

 

I guess I will be back to this thread in two weeks when mine arrives. 



#10 pep01

pep01

    Newbie

  • Senior Members
  • Pip
  • 2 posts

Posted 04 April 2016 - 05:33 PM

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



#11 Gravelrash

Gravelrash

    Advanced Member

  • Senior Members
  • PipPipPip
  • 79 posts

Posted 04 April 2016 - 06:20 PM

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.


Inveterate Fiddler and keyboard Mangler

Veni, Vidi, fregit


#12 tkaiser

tkaiser

    Advanced Member

  • Moderators
  • 2886 posts

Posted 04 April 2016 - 07:16 PM

will the i2s functionality make it into the "legacy kernel" download / update.

 

Already there starting with 5.05: https://github.com/i.../H3_mini_faq.md

 

With mainline/vanilla this should be no problem at all (after adjusting .dts file to use the aforementioned pins for I2S)


  • Gravelrash likes this

Please don't send personal messages! Use the forum so others can participate and benefit!

 

Before you report any problem please be aware that crappy SD cards and insufficient power supply are reason N° 1 why things are failing. Try to rule this out first please, check 'getting started' recommendations and check/provide 'sudo armbianmonitor -u' output first!

 

Did you check out custom google powered forum search already (before opening new threads or asking questions)?


#13 Gravelrash

Gravelrash

    Advanced Member

  • Senior Members
  • PipPipPip
  • 79 posts

Posted 04 April 2016 - 07:41 PM

tkaiser thankyou


Inveterate Fiddler and keyboard Mangler

Veni, Vidi, fregit


#14 Eng-Shien Wu

Eng-Shien Wu

    Member

  • Senior Members
  • PipPip
  • 20 posts

Posted 18 April 2016 - 08:00 AM

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....r-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



#15 Zammy

Zammy

    Member

  • Senior Members
  • PipPip
  • 15 posts

Posted 26 June 2016 - 11:17 PM

Thanks Da Achemist, works perfectly with PCM5102 which has higher bitrate 32bit 384K vs 24bit 192K of ES9023.  


Spoiler

#16 Ford Prefect

Ford Prefect

    Advanced Member

  • Senior Members
  • PipPipPip
  • 68 posts

Posted 28 June 2016 - 05:00 PM

And even cheaper :D

http://www.ebay.com/...sd=272248053601

But there seems to be a clock signal missing.

http://www.ti.com/li...ink/pcm5100.pdf

see page 26 may be that's the use for the jumper ?



#17 Da Alchemist

Da Alchemist

    Advanced Member

  • Senior Members
  • PipPipPip
  • 82 posts

Posted 28 June 2016 - 09:00 PM

There is nothing missing, you can use this card the way it comes. MCLK signal is not connected on the ES9023 Board

 

Regards



#18 snowbody

snowbody

    Newbie

  • Senior Members
  • Pip
  • 9 posts

Posted 11 July 2016 - 01:31 PM

Thank you for the tutorial.

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

http://www.aliexpres...2678406932.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.



#19 Ford Prefect

Ford Prefect

    Advanced Member

  • Senior Members
  • PipPipPip
  • 68 posts

Posted 11 July 2016 - 08:49 PM

Thanks for your feedback.

Your use of the PI and this card as a synthesiser is very clever.

I'm not a musician but it opens the possibility to generate low cost/high quality test signals for various electronic devices.



#20 snowbody

snowbody

    Newbie

  • Senior Members
  • Pip
  • 9 posts

Posted 14 July 2016 - 08:45 PM

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
}
 



#21 dony71

dony71

    Advanced Member

  • Senior Members
  • PipPipPip
  • 69 posts

Posted 14 July 2016 - 11:08 PM

May I know what's max PCM rate supported in kernel?

Does it support 384K like in Odroid C1/C2 ?

(https://github.com/h...ound/pcm.h#L115)



#22 zador.blood.stained

zador.blood.stained

    Advanced Member

  • Moderators
  • 1886 posts

Posted 15 July 2016 - 11:05 AM

May I know what's max PCM rate supported in kernel?

Does it support 384K like in Odroid C1/C2 ?

(https://github.com/h...ound/pcm.h#L115)

According to H3 datasheet maximum I2S/PCM sample rate supported by hardware is 192KHz


Spoiler

#23 Christos

Christos

    Advanced Member

  • Senior Members
  • PipPipPip
  • 198 posts

Posted 11 October 2016 - 05:28 AM

Was anyone successful in capture?

 

 

Edit/P.S.

Ok, it works, after a reboot.


__________________________________________________________________________________________________________________

Samsung S5P6818             AllWinner H3                      AllWinner H5       Broadcom BCM2837    AllWinner A64

.  FriendlyArm NanoPi M3    .  FriendlyArm NanoPi NEO v1.1    .  OrangePi PC2    .  RaspberryPi 3    . NanoPi A64

.  Samsung Artik710         .  OrangePi ONE                   .                  .                   .

.                           .  OrangePi PC Plus               .                  .                   .

.                           .  OrangePi PC Plus2E             .                  .                   .


#24 Da Alchemist

Da Alchemist

    Advanced Member

  • Senior Members
  • PipPipPip
  • 82 posts

Posted 14 October 2016 - 02:28 PM

what did you use AS I2S capture device?

#25 Christos

Christos

    Advanced Member

  • Senior Members
  • PipPipPip
  • 198 posts

Posted 14 October 2016 - 03:44 PM

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.


__________________________________________________________________________________________________________________

Samsung S5P6818             AllWinner H3                      AllWinner H5       Broadcom BCM2837    AllWinner A64

.  FriendlyArm NanoPi M3    .  FriendlyArm NanoPi NEO v1.1    .  OrangePi PC2    .  RaspberryPi 3    . NanoPi A64

.  Samsung Artik710         .  OrangePi ONE                   .                  .                   .

.                           .  OrangePi PC Plus               .                  .                   .

.                           .  OrangePi PC Plus2E             .                  .                   .


#26 dony71

dony71

    Advanced Member

  • Senior Members
  • PipPipPip
  • 69 posts

Posted 27 October 2016 - 07:13 PM

can you try to change "sample_resolution = 24" in script.bin

see below in details under [pcm0]

https://github.com/i...anapim2plus.fex



#27 thk4711

thk4711

    Newbie

  • Senior Members
  • Pip
  • 4 posts

Posted 01 November 2016 - 10:56 AM

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 ?



#28 thk4711

thk4711

    Newbie

  • Senior Members
  • Pip
  • 4 posts

Posted 02 November 2016 - 09:26 AM

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"
}


#29 msev

msev

    Advanced Member

  • Senior Members
  • PipPipPip
  • 76 posts

Posted 28 November 2016 - 08:12 AM

Would such a DAC work too ->  http://www.ebay.com/...5gAAOSwPCVX4l6L? Since it uses the same chip but looks a bit different.



#30 thk4711

thk4711

    Newbie

  • Senior Members
  • Pip
  • 4 posts

Posted 28 November 2016 - 11:00 AM

This would work but you will have to connect several pins either to GND or 3.3V please see: http://blogimg.goo.n...604608bfbdb.png

 

It would be easier to this one http://www.ebay.com/...5sAAOSwLF1X48tC 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/...ccAAOSwD0lUj2EL