targa
Posts: 13
Joined: Tue Nov 07, 2017 10:00 am

Re: STICKY: The I2S sound thread.

Mon Feb 05, 2018 1:41 pm

From the link you gave it seems to me that you also need the simple driver, so the snd_soc_bcm2835_i2s and the snd_soc_simple. It doesn't seem to have any configuration input (eg. i2c), so you need to make your Pi compatible to your device just as I did. (see before , P 32+)

JoeCraig
Posts: 8
Joined: Sat Feb 17, 2018 4:24 am

Re: STICKY: The I2S sound thread.

Sat Feb 17, 2018 5:11 am

... First post here. Apologies if it's not in the right area, but this thread seemed appropriate.

I'm working on a DSP board for the rPi, using the ADAU1701 DSP from Analog Devices. The goal is to use the RPi's I2S stream to get audio into the DSP. The crux of the problem is (of course) the MCK. I was hoping to use the pi to generate MCK for the 1701, thinking it would be synchronous with the I2S clocks and data. The 1701 can take an MCK of 64*Fs, so I generate a clock of 3.072 MHz for Fs = 48 MHz, using pigpio "minimal_clk".

The first issue is that the generated MCK does not appear to be exactly 3.072 MHz (maybe this isn't possible?) I measure the MCK to be about 3.09 MHz. Does anyone know if the exact frequency of 3.072 MHz can be achieved? Of course integer divisions of the rPi clock won't be good enough, but with fraction division and ?MASH? this might be possible.

The second issue is that the generated MCK does not appear to be synchronous with the I2S clocks. I'm using the device tree overlay for "hifiberry-dac" (and it's been tested with pHAT DAC to ensure correct I2S streaming). The hope was that MCK would be synchronous with the I2S BCK and LRCK, where each LRCK (48 kHz) transition would contain exactly 64 MCK cycles. When I scope up the generated MCK and I2S clocks, it is apparent they are not synchronized and drift from each other.

Perhaps the architecture of running the DSP from an rPi generated MCK can not be made to work and I need to use a DSP with sample rate converter or (*gasp*) use a simple DAC to convert the the pi audio into analog and redigitize with the 1701. Another thought was to run the 1701 from an independent crystal oscillator, and have it initiate I2S transfer from the pi, generating the BCK and LRCK, and the rPi would be an I2S slave instead of master, but I don't know if this can be done, either.

HiassofT
Posts: 104
Joined: Fri Jun 30, 2017 10:07 pm

Re: STICKY: The I2S sound thread.

Sun Feb 18, 2018 1:13 am

I'd recommend using a oscillator to drive MCLK and use the codec in master mode - this should work just fine.

bcm2835 doesn't support MCLK output and using a fractional divider or MASH as a clock source for the codec isn't a good idea - best thing you could do is to generate a clock that's derived by an integer divider from the 19.2MHz oscillator on the RPi.

so long,

Hias

JoeCraig
Posts: 8
Joined: Sat Feb 17, 2018 4:24 am

Re: STICKY: The I2S sound thread.

Sun Feb 18, 2018 4:43 pm

Thanks, Hias.

Unfortunately, the 1701 can only accept MCK inputs of 64, 256, 384, and 512 times Fs. To use the rPi oscillator at 19.2 MHz, for 48 kHz Fs, would need to divide by 400.

JoeCraig
Posts: 8
Joined: Sat Feb 17, 2018 4:24 am

Re: STICKY: The I2S sound thread.

Mon Feb 19, 2018 4:09 pm

Is it possible for the pi to be an i2s slave? My setup is using shairport for airplay streaming, and the HiFiBerry overlay to output i2s audio. This works for the pie controlling i2s, but can the pi be i2s slave and output data when BCK and LRCK are driven from another source, such as ADAU1701?

Any guides for setting up the pi in i2s slave mode?

HiassofT
Posts: 104
Joined: Fri Jun 30, 2017 10:07 pm

Re: STICKY: The I2S sound thread.

Mon Feb 19, 2018 10:03 pm

Yes, RPi works fine in slave mode - quite a lot of soundcards use such a setup.

Configuring RPi as I2S slave is easy, with simple-audio-card you just point the bitclock-master and frameclock-master properties to the codec.

See for example this recently added overlay: https://github.com/raspberrypi/linux/bl ... verlay.dts

so long,

Hias

JoeCraig
Posts: 8
Joined: Sat Feb 17, 2018 4:24 am

Re: STICKY: The I2S sound thread.

Thu Feb 22, 2018 5:48 pm

Ok! This is great. I've setup the I2S bus to be clocked from the DSP, and the pi needs to slave data to those clocks.

I'm learning about overlays and took the "SuperAudioBoard" overlay, compiled it, and called it in /boot/config.txt

It appears to be working...

001682.750: brfs: File read: /mfs/sd/overlays/superaudioboard.dtbo
001694.740: Loaded overlay 'superaudioboard'

However, no data is showing up on the DIN line (LRCLK = 48 kHz, BCLK = 3.072 MHz). I think I need to learn more about creating overlays to set this up. Are there tutorials on using "simple-audio-card" and modifying it for i2s slave?

HiassofT
Posts: 104
Joined: Fri Jun 30, 2017 10:07 pm

Re: STICKY: The I2S sound thread.

Fri Feb 23, 2018 12:32 pm

When using RPi in I2S slave mode (i.e. codec is clock master) the most important thing is that you correctly reference and configure your codec in the devicetree. When you did that you just have to add the bitclock-master and frame-master properties like in the superaudioboard overlay.

For details about simple-audio-card (or the newer audio-graph-card) and codec devicetree configuration please read through the devicetree bindings documentation in the kernel https://github.com/raspberrypi/linux/tr ... ings/sound

The binding docs usually have examples and you can find more examples how to use simple-card and overlays in this thread, in the Devicetree sub-forum and in the kernel overlays directory.

so long,

Hias

mjubes
Posts: 36
Joined: Thu Oct 01, 2015 8:17 am

Re: STICKY: The I2S sound thread.

Fri Feb 23, 2018 3:55 pm

I2S and 4.14

Having moved to 4.14 and using the standard HiassofT's "dual.dtbo" overlay (with the dai-tdm-slot-width=<32> configuration added) I noticed the actual I2S output from the hardware is only 2*24 bits (in a 2*32 bit frame) with padding, even though the actual input and settings are for a full 2*32 bit frame and data (this using alsa API functions)

Previously (with kernel 4.9) I have been using the standard Paul Creaser's "my_loader module" (i.e. no overlay) which have been giving a full 32 bit output using the same software.

Any ideas what can be happening?

HiassofT
Posts: 104
Joined: Fri Jun 30, 2017 10:07 pm

Re: STICKY: The I2S sound thread.

Fri Feb 23, 2018 6:00 pm

Note that the generic spdif drivers used in the dual overlay only support 16 and 24 bit mode - you can check eg with aplay -v, if you play 32bit data plughw will automatically convert that to S24_LE.

If you want 32bit output you need to use a codec driver that actually supports S32_LE mode, then the RPi will transmit 32 real bits.

so long,

Hias

JoeCraig
Posts: 8
Joined: Sat Feb 17, 2018 4:24 am

Re: STICKY: The I2S sound thread.

Sat Feb 24, 2018 9:53 pm

Hi Hias, I appreciate your help here. I'm having issues making an overlay though. I can't seem to configure it to get any i2s data on the output (line is just low, while BCLK and LRCLK are toggling, and audio is playing on the pi). Do I have to define more for the adau1701 codec? There is an ADAU1701 binding available, but I think this is just for i2c.

https://github.com/raspberrypi/linux/bl ... au1701.txt

Any help on this overlay would be greatly appreciated. thanks!

Code: Select all

// Definitions for adau1701board
/dts-v1/;
/plugin/;

/ {
        compatible = "brcm,bcm2708";

        [email protected] {
                target = <&sound>;
                __overlay__ {
                        compatible = "simple-audio-card";
                        i2s-controller = <&i2s>;
                        status = "okay";

                        simple-audio-card,name = "adau1701board";

                        simple-audio-card,format = "i2s";

                        simple-audio-card,bitclock-master = <&adau1701_sound>;
                        simple-audio-card,frame-master = <&adau1701_sound>;

                        simple-audio-card,cpu {
                                sound-dai = <&i2s>;
                                dai-tdm-slot-num = <2>;
                                dai-tdm-slot-width = <32>;
                        };

                        adau1701_sound: simple-audio-card,codec {
                                system-clock-frequency = <3072000>;
                        };
                };
        };

        [email protected] {
                target = <&i2s>;
                __overlay__ {
                        status = "okay";
                };
        };
};

HiassofT
Posts: 104
Joined: Fri Jun 30, 2017 10:07 pm

Re: STICKY: The I2S sound thread.

Sun Feb 25, 2018 12:44 pm

You also have to add the adau1701 codec to devicetree so that the module is loaded and you can reference the codec in the simple-card fragment.

Of course you also have to connect the I2C lines and use the correct I2C address in the fragment - plus maybe add the reset, pll, ... gpio properties so that they match your hardware setup.

so long,

Hias

JoeCraig
Posts: 8
Joined: Sat Feb 17, 2018 4:24 am

Re: STICKY: The I2S sound thread.

Sun Feb 25, 2018 6:29 pm

Ok. So, I think I've figured out how to add the adau1701 codec and reference it from the fragment. Here's the *.dts, but I'm still not getting any output on the I2S data out line when audio is playing off the pi.

I don't have the I2C lines connected from the DSP to the pi, but the DSP is configured properly to accept I2S data, and is generating the BCKL and LRCLK continuously.

Code: Select all

// Definitions for adau1701board
/dts-v1/;
/plugin/;

/ {
        compatible = "brcm,bcm2708";

        [email protected] {
                target = <&sound>;
                __overlay__ {
                        compatible = "simple-audio-card";
                        i2s-controller = <&i2s>;
                        status = "okay";

                        simple-audio-card,name = "adau1701board";

                        simple-audio-card,format = "i2s";

                        simple-audio-card,bitclock-master = <&adau1701_sound>;
                        simple-audio-card,frame-master = <&adau1701_sound>;

                        simple-audio-card,cpu {
                                sound-dai = <&i2s>;
                                dai-tdm-slot-num = <2>;
                                dai-tdm-slot-width = <32>;
                        };

                        adau1701_sound: simple-audio-card,codec {
                                sound-dai = <&adauDSP>;
                                compatible = "adi,adau1701";
                                system-clock-frequency = <3072000>;
                        };
                };
        };

        [email protected] {
                target = <&i2s>;
                __overlay__ {
                        status = "okay";
                };
        };

        [email protected] {
                target = <&i2c1>;
                __overlay__ {
                        #address-cells = <1>;
                        #size-cells = <0>;
                        status = "okay";

                        adauDSP:  [email protected] {
                                #sound-dai-cells = <0>;
                                compatible = "adi,adau1701";
                                reg = <0x34>;
                                status = "okay";
                        };
                };
        };
};


I don't see any problems through the vcdbg log msg...

Code: Select all

001693.691: dtdebug: Opened overlay file 'overlays/adau1701board.dtbo'
001695.651: brfs: File read: /mfs/sd/overlays/adau1701board.dtbo
001706.377: Loaded overlay 'adau1701board'
001706.438: dtdebug: Found fragment 0 (offset 36)
001714.202: dtdebug: merge_fragment(/soc/sound,/[email protected]/__overlay__)
001714.231: dtdebug:   +prop(compatible)
001714.646: dtdebug:   +prop(i2s-controller)
001715.305: dtdebug:   +prop(status)
001715.715: dtdebug:   +prop(simple-audio-card,name)
001716.384: dtdebug:   +prop(simple-audio-card,format)
001717.068: dtdebug:   +prop(simple-audio-card,bitclock-master)
001717.771: dtdebug:   +prop(simple-audio-card,frame-master)
001721.589: dtdebug: merge_fragment(/soc/sound/simple-audio-card,cpu,/[email protected]/__overlay__/simple-audio-card,cpu)
001721.621: dtdebug:   +prop(sound-dai)
001722.299: dtdebug:   +prop(dai-tdm-slot-num)
001722.985: dtdebug:   +prop(dai-tdm-slot-width)
001723.695: dtdebug: merge_fragment() end
001726.921: dtdebug: merge_fragment(/soc/sound/simple-audio-card,codec,/[email protected]/__overlay__/simple-audio-card,codec)
001726.952: dtdebug:   +prop(sound-dai)
001727.638: dtdebug:   +prop(compatible)
001728.077: dtdebug:   +prop(system-clock-frequency)
001728.786: dtdebug:   +prop(linux,phandle)
001729.508: dtdebug:   +prop(phandle)
001730.006: dtdebug: merge_fragment() end
001730.042: dtdebug: merge_fragment() end
001730.168: dtdebug: Found fragment 1 (offset 440)
001732.938: dtdebug: merge_fragment(/soc/[email protected],/[email protected]/__overlay__)
001732.965: dtdebug:   +prop(status)
001733.799: dtdebug: merge_fragment() end
001733.856: dtdebug: Found fragment 2 (offset 516)
001738.988: dtdebug: merge_fragment(/soc/[email protected],/[email protected]/__overlay__)
001739.016: dtdebug:   +prop(#address-cells)
001739.678: dtdebug:   +prop(#size-cells)
001740.346: dtdebug:   +prop(status)
001743.583: dtdebug: merge_fragment(/soc/[email protected]/[email protected],/[email protected]/__overlay__/[email protected])
001743.609: dtdebug:   +prop(#sound-dai-cells)
001744.302: dtdebug:   +prop(compatible)
001744.941: dtdebug:   +prop(reg)
001745.603: dtdebug:   +prop(status)
001746.298: dtdebug:   +prop(linux,phandle)
001747.229: dtdebug:   +prop(phandle)

HiassofT
Posts: 104
Joined: Fri Jun 30, 2017 10:07 pm

Re: STICKY: The I2S sound thread.

Mon Feb 26, 2018 1:32 pm

From a quick glance the DT overlay looks OK to me.

But, as I wrote before, setup ADAU1701 to be controlled via I2C, hook up the I2C lines and allow the driver to control ADAU1701 via I2C like the driver expects it.

so long,

Hias

JoeCraig
Posts: 8
Joined: Sat Feb 17, 2018 4:24 am

Re: STICKY: The I2S sound thread.

Mon Feb 26, 2018 4:21 pm

Ok. I hooked up the i2c lines, but am having issues seeing the device. I posted the issue in this thread...

viewtopic.php?f=28&t=206443

Any idea why I can see the USBi, but not the 1701?

mjubes
Posts: 36
Joined: Thu Oct 01, 2015 8:17 am

Re: STICKY: The I2S sound thread.

Mon Feb 26, 2018 4:34 pm

dt overlay and dmix issue

I am using Hias's basic overlay with the snd_soc_spdif_rx (and tx) built in 4.14 drivers, nothing else.
I am also using the alsa API in "C" for the tests.

When I do a playback open (snd_pcm_open) with "plughw:0,0" as the card name, and 48000 as speed, I can get alsa to open OK with 32,24 and 16 bits (though the hardware driver outputs only to 24 bits as mentioned in an earlier post)

However, when I try an open using "dmix" as the card name, 32 an 24 bit opens will fail, only opens with 16 bits will succeed. Seemingly "dmix" is limited to 16 bit operation?

Playing with "/etc/asound.conf" seems to have little effect (I am sure I am doing something wrong) as I have tried a number of variations, here is one for example, but in all cases only 16 bit opens seem to work. Any ideas?

PS thanks all very much for your help!

Code: Select all

 pcm. !default { 
     type plug  
     slave.pcm "dmixer" 
}  
pcm.dmixer { 
     type dmix 
     ipc_key 1024
     slave {   
        pcm "plughw:0,0" 
        rate 48000 
        channels 2 
        format S32_LE 
     }
     rate 48000
     format S32_LE  
}  

HiassofT
Posts: 104
Joined: Fri Jun 30, 2017 10:07 pm

Re: STICKY: The I2S sound thread.

Tue Feb 27, 2018 9:36 am

mjubes wrote:
Mon Feb 26, 2018 4:34 pm
When I do a playback open (snd_pcm_open) with "plughw:0,0" as the card name, and 48000 as speed, I can get alsa to open OK with 32,24 and 16 bits (though the hardware driver outputs only to 24 bits as mentioned in an earlier post)

However, when I try an open using "dmix" as the card name, 32 an 24 bit opens will fail, only opens with 16 bits will succeed. Seemingly "dmix" is limited to 16 bit operation?

Playing with "/etc/asound.conf" seems to have little effect (I am sure I am doing something wrong) as I have tried a number of variations, here is one for example, but in all cases only 16 bit opens seem to work. Any ideas?
The dmix plugin defaults to 48kHz and 16bit. You can change that in the dmix slave configuration, which has to point to a hw device (plughw like you had in your .asoundrc is not allowed).

If you want to play audio files with different samplerates / formats that what dmix is configured to you have to put a plug device before that.

Try eg with this .asoundrc, that will use S24_LE and 96kHz at the I2S level:

Code: Select all

pcm.!default {
        type asym
        playback.pcm {
                type plug
                slave.pcm "mydmixer"
        }
}

pcm.mydmixer {
        type dmix
        ipc_key 1234
        slave {
                pcm "hw:0,0"
                format S24_LE
                rate 96000
        }
}
BTW: use "aplay -v somefile.wav" to see the alsa plugin chain used. When you play a 44.1kHz 16-bit file using the .asoundrc above you'll see that the plug device first converts it to 96kHz 24 bit, then runs through dmix (at 96kHz 24bit) and is sent to the hardware device (also at 96kHz 16bit)

The output will look like this (unimportant stuff snipped):

Code: Select all

[email protected]:~ $ aplay -v audiotest/440hz-44100-stereo.wav
Playing WAVE 'audiotest/440hz-44100-stereo.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
Plug PCM: Rate conversion PCM (96000, sformat=S24_LE)
Its setup is:
  format       : S16_LE
  rate         : 44100
Slave: Direct Stream Mixing PCM
Its setup is:
  format       : S24_LE
  rate         : 96000
Hardware PCM card 0 'Dual' device 0 subdevice 0
Its setup is:
  format       : S24_LE
  rate         : 96000
so long,

Hias

HiassofT
Posts: 104
Joined: Fri Jun 30, 2017 10:07 pm

Re: STICKY: The I2S sound thread.

Tue Feb 27, 2018 10:00 am

JoeCraig wrote:
Mon Feb 26, 2018 4:21 pm
Ok. I hooked up the i2c lines, but am having issues seeing the device. I posted the issue in this thread...

viewtopic.php?f=28&t=206443

Any idea why I can see the USBi, but not the 1701?
I2C address 0x34 seems to be correct.

I2C uses 7bit address followed by a bit to select read or write mode. In Linux only the 7bit address (0-127) is used, whereas in the ADAU datasheet the address plus r/w bit are combined into a full byte with r/w at the LSB. Therefore you have 2 "addresses" in the ADAU datasheet for each ADDR configuration - write (0x68) at 2 times the linux address (0x34) and read at 2 times plus 1 (0x69). Yes, the nice thing about standards is that there are so many of them :-)

It could well be that probing via I2C detect "upsets" the ADAU - i2cdetect even warns about that.

If you suspect an issue with I2C communication you could try the i2c-bcm2708 driver instead of the default i2c-bcm2835 driver (by using the i2c1-bcm2708 overlay). i2c-bcm2708 has a module option to enable combined transfers (see modinfo i2c-bcm2708), maybe this'll help.

so long,

Hias

michthom
Posts: 12
Joined: Sun Jul 01, 2012 10:46 am

Re: STICKY: The I2S sound thread.

Tue Feb 27, 2018 8:40 pm

I've just posted on the end of the Device Tree Q&A thread viewtopic.php?f=44&t=99784&p=1278971#p1278971 as that threw down the gauntlet for a combined I2S capture and playback overlay. It may get moved to its own thread but I'm crossposting here (naughty?) to see if any I2S guru is willing to correct my mistakes and help me get the softvol/mixer/mic boost working and convert from stereo (single channel) to mono (balanced output) from the MEMS microphone?
Cheers
Mike

altosack
Posts: 19
Joined: Wed Feb 24, 2016 12:48 am

Re: STICKY: The I2S sound thread.

Fri Mar 16, 2018 5:33 am

I have an I2S amp HAT (Adafruit speaker bonnet) on a Pi Zero W, headless; when I play anything (speaker-test, aplay, omxplayer, mpg123), I get an initial pop, so I know I have power, the correct device, driver, etc., but then there is no output with any of them. Any ideas ? As far as I know, it's not muted, but also nothing happens when I push 'M' in alsamixer.

EDIT: SOLVED: My power supply was inadequate.

bricolodu13
Posts: 32
Joined: Tue Aug 07, 2012 2:05 pm

Re: STICKY: The I2S sound thread.

Thu Apr 12, 2018 4:15 pm

Hello,

I'm new to all this, sorry !

I have spent a couple of hours reading and trying to build a module for my dac without success.
I use a TDA1543A (right justified, Japanese format)

here is my .dts

Code: Select all

// Definitions for TDA1543A-SoundCard
/dts-v1/;
/plugin/;

/ {
    compatible = "brcm,bcm2708";

    [email protected] {
        target = <&sound>;
        __overlay__ {
            compatible = "simple-audio-card";
            simple-audio-card,name = "TDA1543A-SoundCard";
            simple-audio-card,format = "right_j";
            status="okay";
            simple-audio-card,cpu {
                    sound-dai = <&right_j>;
            };
            simple-audio-card,codec {
                    sound-dai = <&codec_out>;
            };
        };
    };
   [email protected] {
        target = <&right_j>;
        __overlay__ {
                    status="okay";
        };
    };                
};
Note that I have also tried :

Code: Select all

                    sound-dai = <&i2s>;
...
   [email protected] {
        target = <&i2s>;
In both cases I got some warnings although it compiled

Code: Select all

Warning (unit_address_vs_reg): Node /[email protected] has a unit name, but no reg property
Warning (unit_address_vs_reg): Node /[email protected] has a unit name, but no reg property
Then, I have done

Code: Select all

dtc [email protected] -I dts -O dtb -o TDA1543A-SoundCard.dtbo TDA1543A-SoundCard.dts
sudo cp TDA1543A-SoundCard.dtbo /boot/overlays
I have edited /boot/config.txt
I have tried both dtparam=i2s=on commented and not commented
and I have added at the end :

Code: Select all

dtoverlay=TDA1543A-SoundCard,alsaname=TDA1543A
I finally made a reboot
I never get any soundcard
aplay-l

Code: Select all

aplay: device_ list 270: no soundcard found...
I would really appreciate some help,
Thank you
Jean

HiassofT
Posts: 104
Joined: Fri Jun 30, 2017 10:07 pm

Re: STICKY: The I2S sound thread.

Thu Apr 12, 2018 4:51 pm

Use the overlay I posted earlier today here: viewtopic.php?f=44&t=168808#p1301109

If the DAC is 16-bit only right justified then playing 24bit audio won't work, but 16bit audio should be fine (you can force 16bit mode with .asoundrc if you want/need).

Unless you set tdm-slot-width in the overlay left/right justified will be identical as each 16bit sample will be transferred using 16 bclks.

so long,

Hias

bricolodu13
Posts: 32
Joined: Tue Aug 07, 2012 2:05 pm

Re: STICKY: The I2S sound thread.

Thu Apr 12, 2018 4:56 pm

Thank you Hias,

Sorry I missed it!

Now, I get the board listed with your code, however I didn't tested it yet with the TDA1543A.
I don't understand though why you make reference to spdif as my dac is japanese format right justified.

I have changed your code from left justifed to right justified, by the way.

Best regards,

HiassofT
Posts: 104
Joined: Fri Jun 30, 2017 10:07 pm

Re: STICKY: The I2S sound thread.

Thu Apr 12, 2018 5:03 pm

You can ignore the "spdif" name, despite their name the spdif receiver/transmitter codecs are just very generic drivers that don't do anything except allowing 16-24bit audio. They can be used for all ADCs/DACs that don't require any special configuration via I2C, SPI or GPIO pins.

The important thing in your case is that you set the DAI format correctly (to "right_j").

so long,

Hias
Last edited by HiassofT on Thu Apr 12, 2018 5:11 pm, edited 1 time in total.

bricolodu13
Posts: 32
Joined: Tue Aug 07, 2012 2:05 pm

Re: STICKY: The I2S sound thread.

Thu Apr 12, 2018 5:08 pm

Thank you !

Return to “Interfacing (DSI, CSI, I2C, etc.)”

Who is online

Users browsing this forum: No registered users and 15 guests