User avatar
flatmax
Posts: 336
Joined: Thu May 26, 2016 10:36 pm

Re: I2S Success (at last) !

Thu Aug 25, 2016 12:08 pm

Can you repost what you got working with no hiss ? Perhaps I can take a look.
I am not sure that moving away form simple card to a dedicated driver is necessary if your codec driver doesn't require it.

Matt
Check the Ultra 2 sound card - use our shop instead of Amazon Europe (Amazon USA is live).
Sound card for the Raspberry Pi with inbuilt microphone : www.audioinjector.net
Audio Inector Octo multitrack GPIO sound card

User avatar
Maash
Posts: 31
Joined: Tue Aug 23, 2016 10:18 am

Re: I2S Success (at last) !

Fri Aug 26, 2016 6:22 am

It's just a emulator board for NXP TFA9890 outputting I2S and mimiking a mic. It was configured with pc, so RPi only tries to listen to I2S data.

My simple card is same as posted here many times, but it contains the extra line for the bclk_ratio setting was added to asoc_simple_card_dai_init. And loader i'm using is also the same as posted here, but clocks are fully slave mode in rpi side. Main thing was that I had to configure the NXP chip to sample in 44.1khz instead of 48 as it's outputting 44.1 by default and I couldn't configure it othervise.
More like a comfyman...

jeremynz
Posts: 20
Joined: Fri Sep 05, 2014 12:20 am

Re: I2S Success (at last) !

Fri Aug 26, 2016 6:55 am

Thanks for your excellent guide audio-badger.

I have a question I'm hoping someone can help me with.

How can I modify the drivers to work with a device that has only a single (mono) 16-bit audio channel in each direction?

User avatar
audio-badger
Posts: 15
Joined: Wed Jun 15, 2016 9:44 am

Re: I2S Success (at last) !

Mon Sep 12, 2016 12:13 pm

How can I modify the drivers to work with a device that has only a single (mono) 16-bit audio channel in each direction?
I2S by nature is a 2 channel interface (per data line) since the frame consists of L followed by R. So I'm not sure if a mono I2S driver makes sense.

However, I needed a mono input sound card to work with my app, so I used the ALSA plugs (effectively wiring from physical sound car to a virtual one) to make an abstraction of my stereo input sound card but just presented one channel. You can do this by modifying .asoundrc.
There's an example in my write up (in this thread) for input and plenty of other useful posts which can be used as reference such as:
viewtopic.php?f=29&t=33431

User avatar
flatmax
Posts: 336
Joined: Thu May 26, 2016 10:36 pm

Re: I2S Success (at last) !

Tue Sep 13, 2016 11:45 am

If you want to restrict the number of channels in your machine driver it is something like so :
static const struct snd_soc_pcm_stream my_params {
.channels_min = 1,
.channels_max = 1,
};

static struct snd_soc_dai_link my_dai[] = {
... SNIP ...
.params=&my_params;
};

You can also specify other parameters in the snd_soc_pcm_stream, see here for more info :
http://lxr.free-electrons.com/source/in ... soc.h#L732

Matt
Check the Ultra 2 sound card - use our shop instead of Amazon Europe (Amazon USA is live).
Sound card for the Raspberry Pi with inbuilt microphone : www.audioinjector.net
Audio Inector Octo multitrack GPIO sound card

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

Re: I2S Success (at last) !

Mon Sep 19, 2016 1:37 pm

I have a Pi3 with myloader.c etc all working OK into both I2S inputs and outputs, as record and playback

On playback I have both the PWM output as card0 and PCM as card1

My question is more Alsa related: how does the boot sequence allocate the order of sound cards? as I also have another PI2 with a similar installation, however, card0 is PCM(I2S) and card1 is PWM (jacksocket) .

PS: I am aware of how to use aliasies, I was just generally interested on how the above works.

User avatar
audio-badger
Posts: 15
Joined: Wed Jun 15, 2016 9:44 am

Re: I2S Success (at last) !

Fri Oct 07, 2016 10:49 am

If you want to restrict the number of channels in your machine driver it is something like so :
static const struct snd_soc_pcm_stream my_params {
.channels_min = 1,
.channels_max = 1,
};

static struct snd_soc_dai_link my_dai[] = {
... SNIP ...
.params=&my_params;
};

You can also specify other parameters in the snd_soc_pcm_stream, see here for more info :
http://lxr.free-electrons.com/source/in ... soc.h#L732
^^^This .... is a better solution than my virtual ALSA sound card to map a stereo device to a mono one I think..

User avatar
flatmax
Posts: 336
Joined: Thu May 26, 2016 10:36 pm

Re: I2S Success (at last) !

Thu Oct 13, 2016 6:46 am

Hey all,

I was wondering if anyone could give me feedback on my campaign for a new surround sound I2S hat for the raspberry Pi ?
I would really like to make sure I am putting something up there people would be interested in before I start the campaign.

https://www.kickstarter.com/projects/12 ... n=e465b540

thanks
Matt
Check the Ultra 2 sound card - use our shop instead of Amazon Europe (Amazon USA is live).
Sound card for the Raspberry Pi with inbuilt microphone : www.audioinjector.net
Audio Inector Octo multitrack GPIO sound card

blownelco
Posts: 10
Joined: Wed Nov 11, 2015 9:52 pm

Re: I2S Success (at last) !

Thu Oct 20, 2016 12:48 pm

Hello,
i 've got a I2S microphone working, also a PCM5100A DAC is working.
i have modified .asoundrc to have a softvol control.

below .asoundrc

pcm.dmic_hw {
type hw
card 2
channels 2
format S32_LE
}
pcm.dmic_mm {
type mmap_emul
slave.pcm dmic_hw
}
pcm.!default {
type hw
slave.pcm dmic_mm
control {
name "Boost Capture Volume"
card 2
}
min_dB -2.2250738585072014E-308
max_dB 50.0
}

volume control works in alsamixer but only for microphone, i can't regulate the dac volume.
aplay and arecord shows both card 2

Anyone a clue what i'm doing wrong?

thx

blownelco
Posts: 10
Joined: Wed Nov 11, 2015 9:52 pm

Re: I2S Success (at last) !

Mon Nov 28, 2016 12:45 pm

Answering my own question: writing a goodasound.conf makes the difference.


I have a new question:

Recording and playing sound is now ok, but when start recording and stopping recording there is a little plop into the speakers.

The reason for that is the clock to the dac is changed/stopped for a moment when starting stopping recording.

i have added the | SND_SOC_DAIFMT_CONT to my_loader.c but this doesn't change a thing.

Anyone with the same problem or a solution?


thanks

User avatar
Maash
Posts: 31
Joined: Tue Aug 23, 2016 10:18 am

Re: I2S Success (at last) !

Mon Feb 06, 2017 3:00 pm

Has anyone had any success with I2S microphone and using amixer? The .asoundrc that I got from this thread works OK in record and playback, but if I try to use amixer I get following error:
"ALSA lib dlmisc.c:252:(snd1_dlobj_cache_get) Cannot open shared library /usr/lib/arm-linux-gnueabihf/alsa-lib/libasound_module_ctl_asym.so"

pcm.!default {
type asym
playback.pcm {
type hw
card 0
device 0
}
capture.pcm {
type plug
slave.pcm "monocard"
}
}
The type asym isn't supported or is there some way of defining the asoundrc so that this isn't a problem?
More like a comfyman...

User avatar
Maash
Posts: 31
Joined: Tue Aug 23, 2016 10:18 am

Re: I2S Success (at last) !

Fri Feb 10, 2017 9:45 am

Ok, to reply myself I had to separate the playback from recording.

pcm.monocard {
type plug
slave.pcm "plughw:1,0"
slave.channels 2
slave.rate 16000
}

ctl.monocard {
type hw
card 1
device 0
}

pcm.!default {
type hw
card 0
}

ctl.!default {
type hw
card 0
}

pcm.secondary {
type plug
capture.pcm {
type plug
slave.pcm "monocard"
}
}

ctl.secondary {
type plug
capture.pcm {
type plug
slave.pcm "monocard"
}
}
More like a comfyman...

balu_rpi
Posts: 1
Joined: Tue Feb 14, 2017 2:30 pm

Re: I2S Success (at last) !

Tue Feb 14, 2017 2:39 pm

Hi all,
I followed exactly what audio_badger has suggested in
viewtopic.php?f=44&t=91237&start=50

I am able to see the wclk on oscilloscope when trying to play some .wav ( aplay -D hw:1,0 test.wav) and the frequency is exactly 44.1KHz, i.e., same as of the test.wav file. But, I am unable to see the bitclk on the oscilloscope.All I get is some noise kinda signal.

BTW the dmesg log is below (insmod 'ed asc-simple-card.ko and loader.ko)



pi@raspberrypi:~/rpi-i2s-stereo/loader $ dmesg
[ 114.555312] request module load 'bcm2708-dmaengine': 0
[ 114.560840] BCLK ratio set to 64!
[ 114.566889] asoc-simple-card asoc-simple-card.0: snd-soc-dummy-dai <-> 3f203000.i2s mapping ok
[ 114.567580] register platform device 'asoc-simple-card': 0
[ 114.568384] Error: Driver 'asoc-simple-card' is already registered, aborting...
[ 114.573200] Hello World :)


Could someone help in resolving this? :?:

User avatar
Maash
Posts: 31
Joined: Tue Aug 23, 2016 10:18 am

Re: I2S Success (at last) !

Wed Jun 07, 2017 12:02 pm

Has anyone recently compiled the simple_card against latest kernels? I decided to update the rpi and now I cannot compile the driver.

"struct snd_soc_card has no member named rtd"

I googled this a bit and there was few indications form '15 that this could have been a bug in kernel. However that's quite old. So any ideas regarding this?
More like a comfyman...

Orbital6
Posts: 140
Joined: Sat Aug 08, 2015 6:32 pm

Re: I2S Success (at last) !

Wed Jun 07, 2017 12:07 pm

Maash wrote:Has anyone recently compiled the simple_card against latest kernels? I decided to update the rpi and now I cannot compile the driver.

"struct snd_soc_card has no member named rtd"

I googled this a bit and there was few indications form '15 that this could have been a bug in kernel. However that's quite old. So any ideas regarding this?
I had the same issue. I don't think i figured out how to get around it.

User avatar
Maash
Posts: 31
Joined: Tue Aug 23, 2016 10:18 am

Re: I2S Success (at last) !

Wed Jun 07, 2017 12:47 pm

There seems to be new version of simple_card.c in the kernel. i'll see if it "fits right in". It would definitely suck if I have to roll back to december release just to get I2S recording working :/.
More like a comfyman...

Orbital6
Posts: 140
Joined: Sat Aug 08, 2015 6:32 pm

Re: I2S Success (at last) !

Wed Jun 07, 2017 12:50 pm

Maash wrote:There seems to be new version of simple_card.c in the kernel. i'll see if it "fits right in". It would definitely suck if I have to roll back to december release just to get I2S recording working :/.
Please let me know if you get it working!

User avatar
Maash
Posts: 31
Joined: Tue Aug 23, 2016 10:18 am

Re: I2S Success (at last) !

Wed Jun 07, 2017 1:29 pm

After lot of updating stuff, I managed to build the simple_driver.c, however it cannot be mounted. All functions seem to be unknown symbols in the dmesg.

Perhaps someone with more knowledge of alsa could look at this, but I think I'll go back to old version :/.
More like a comfyman...

omeiko
Posts: 1
Joined: Tue Jun 27, 2017 6:41 pm

Re: I2S Success (at last) !

Tue Jun 27, 2017 8:09 pm

I’m building an rpi3 ADC around PCM4222 in master mode and have managed to get 88.2kHz recording working with the procedures described here. However the 44.1kHz recording plays still too slow because I can’t get the PCM4222 128fs bclk rate working. 88.2kHz uses 64fs.

I have insmod'd these in my_loader.c and simple-card.c:

Code: Select all

.daifmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM,

Code: Select all

ret = snd_soc_dai_set_bclk_ratio(cpu, 128);
I have read and tried everything I can think of but whatever I try for the ratio, nothing changes. Has anyone had any success changing bclk rates in new kernel versions? I’m running Jessie 4.9.33-v7+ ?

User avatar
audio-badger
Posts: 15
Joined: Wed Jun 15, 2016 9:44 am

Re: I2S Success (at last) !

Wed Jun 28, 2017 11:56 am

Posted as a datapoint for those having issues..

For a project I'm doing at the moment where I need the RPI to act as an audio source/sink I tried a freshly installed/updated version:

Code: Select all

Linux rpi_smp_test 4.9.28-v7+ #998 SMP Mon May 15 16:55:39 BST 2017 armv7l GNU/Linux
and following my original instructions seems to still work fine and I had the RPI working as I2S slave and I2S master fine at 48k and 16k for both play and record. I did have some issues with another RPI recently (not sure of kernel version) where I couldn't get BCLK to output at all but that may have been a HW issue.

I did find that I only needed to do :

Code: Select all

sudo insmod loader
as the *snd_soc_simple_card* module seems to get loaded automatically.

I think there have been some changes recently though compared to when I last played with this stuff. For example, I'm not sure the BCLK/LRCLK ratio mod is being set in asoc-simple-card.c as I don't see it in dmesg:

Code: Select all

[ 4125.696324] request module load 'bcm2708-dmaengine': 0
[ 4125.696604] register platform device 'asoc-simple-card': 0
[ 4125.696614] Hello World :)
[ 4125.704630] asoc-simple-card asoc-simple-card.0: snd-soc-dummy-dai <-> 3f203000.i2s mapping ok
I had to specify 32b recording to get 64 bclks per lr clk:

Code: Select all

 arecord -F plughw:1,0 -r 48000 -f S32_LE -c 2 capture.wav
So it looks like it's trying to be clever about setting the BCLK ratio based on the format (not always helpful)..

HiassofT
Posts: 220
Joined: Fri Jun 30, 2017 10:07 pm
Location: Salzburg, Austria
Contact: Website

Re: I2S Success (at last) !

Sat Jul 01, 2017 11:55 am

audio-badger wrote:I had to specify 32b recording to get 64 bclks per lr clk:

So it looks like it's trying to be clever about setting the BCLK ratio based on the format (not always helpful)..
Yes, that's the default unless the machine driver sets a fixed ratio.

Have a look at this PR, it might add what you are looking for (setting bclk ratio via DT): https://github.com/raspberrypi/linux/pull/1982

If this PR fixes your issues please post feedback on GitHub. Would be great if we could get this PR into the RPi kernel, it'll also add support for DSP and justified modes.

so long,

Hias

bibigonda
Posts: 5
Joined: Sat Jul 08, 2017 12:02 am

Re: I2S Success (at last) !

Sat Jul 08, 2017 12:21 am

audio-badger wrote: I think there have been some changes recently though compared to when I last played with this stuff. For example, I'm not sure the BCLK/LRCLK ratio mod is being set in asoc-simple-card.c as I don't see it in dmesg:
The module /lib/modules/4.9.36+/kernel/sound/soc/generic//snd-soc-simple-card.ko is loaded and is used instead of your simple-card module. Thus you can copy your simple-card.ko into this path, overwriting the original module, and it will work.

Do you get proper volume out of your mics? I've got Knowles SPH0645 and its volume is incredibly low - could be only barely heard with full amplification. My guess is that the codec for some reason interprets its data as 32-bit audio frames, while it sends 24-bit frames according to datasheet. Is there any place to debug/dump this data received?

User avatar
Maash
Posts: 31
Joined: Tue Aug 23, 2016 10:18 am

Re: I2S Success (at last) !

Thu Aug 17, 2017 7:37 am

BTW: Has anyone used this with Portaudio? I have weird problem that for some reason the portaudio doesn't receive any data, but it doesn't complain either. arecord with default device works just fine (arecord -f S16_LE -r 1600 test.wav) as does rec.

There's also thread about this without much activity: viewtopic.php?f=38&t=63402
More like a comfyman...

User avatar
Maash
Posts: 31
Joined: Tue Aug 23, 2016 10:18 am

Re: I2S Success (at last) !

Fri Aug 18, 2017 8:09 am

audio-badger wrote:
Wed Jun 28, 2017 11:56 am
Posted as a datapoint for those having issues..
Hmmm...

I took the latest image (2017-07-05-raspbian-jessie) and tried this, but same problem with the missing symbols persist. Kernel seems to be 4.9.35-v7+.

I took the kernel sources according to these instructions: https://github.com/notro/rpi-source/wiki

How did you build the module? Did you use the old loader linked here?

My dmesg just dumps:
[ 3247.157934] simple_card: loading out-of-tree module taints kernel.
[ 3247.158128] simple_card: Unknown symbol asoc_simple_card_parse_dai (err 0)
[ 3247.158163] simple_card: Unknown symbol snd_soc_of_parse_tdm_slot (err 0)
[ 3247.158224] simple_card: Unknown symbol snd_soc_jack_free_gpios (err 0)
[ 3247.158251] simple_card: Unknown symbol asoc_simple_card_parse_card_name (err 0)
[ 3247.158273] simple_card: Unknown symbol snd_soc_jack_add_gpios (err 0)
[ 3247.158294] simple_card: Unknown symbol snd_soc_card_jack_new (err 0)
[ 3247.158315] simple_card: Unknown symbol snd_soc_of_parse_audio_routing (err 0)
[ 3247.158336] simple_card: Unknown symbol snd_soc_dai_set_sysclk (err 0)
[ 3247.158376] simple_card: Unknown symbol asoc_simple_card_parse_daifmt (err 0)
[ 3247.158396] simple_card: Unknown symbol asoc_simple_card_parse_clk (err 0)
[ 3247.158417] simple_card: Unknown symbol asoc_simple_card_init_dai (err 0)
[ 3247.158439] simple_card: Unknown symbol snd_soc_dai_set_bclk_ratio (err 0)
[ 3247.158466] simple_card: Unknown symbol asoc_simple_card_set_dailink_name (err 0)
[ 3247.158528] simple_card: Unknown symbol snd_soc_pm_ops (err 0)
[ 3247.158549] simple_card: Unknown symbol asoc_simple_card_clean_reference (err 0)
[ 3247.158574] simple_card: Unknown symbol asoc_simple_card_canonicalize_cpu (err 0)
[ 3247.158603] simple_card: Unknown symbol snd_soc_of_parse_audio_simple_widgets (err 0)
[ 3247.158624] simple_card: Unknown symbol asoc_simple_card_canonicalize_dailink (err 0)
[ 3247.158656] simple_card: Unknown symbol devm_snd_soc_register_card (err 0)
More like a comfyman...

User avatar
Maash
Posts: 31
Joined: Tue Aug 23, 2016 10:18 am

Re: I2S Success (at last) !

Mon Aug 21, 2017 11:42 am

Ok, just to continue my monolog now the build worked. I had to use different kernel base, build it, use it and use simple-card.c from that as a base. Now I used the official rpi 4.9.y kernel branch from raspberrypi foundation as base instead of that python script mentioned before.
More like a comfyman...

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