Zynthian dac adac light ready for codec development

There may be something wrong with my ADC casuing the noise. I won’t worry about that just yet.

I tried combining the two devices (inputs and outputs) to a single virtual device using asound multi plugin but the required library is not found in zynthian.

It looks like we may need to write a driver. The simple-audio-card driver seems to have a limitation that you cannot combine codecs into a single device. Skeleton code might look something like this:

#include <linux/module.h>
#include <sound/soc.h>

static struct snd_soc_dai_link multi_i2s_dai_links[] = {
    {
        .name = "Output 1",
        .stream_name = "Playback 1",
        .cpu_dai_name = "cpu_dai_out_1",
        .codec_dai_name = "codec_dai_out_1",
        .platform_name = "bcm2712-i2s",
        .codec_name = "spdif-dit",
        .dai_fmt = SND_SOC_DAIFMT_I2S,
    },
    {
        .name = "Input 1",
        .stream_name = "Capture 1",
        .cpu_dai_name = "cpu_dai_in_1",
        .codec_dai_name = "codec_dai_in_1",
        .platform_name = "bcm2835-i2s",
        .codec_name = "spdif-dir",
        .dai_fmt = SND_SOC_DAIFMT_I2S,
    },
    // Add more DAIs as needed
};

static struct snd_soc_card multi_i2s_card = {
    .name = "ZynDACADCx8",
    .dai_link = multi_i2s_dai_links,
    .num_links = ARRAY_SIZE(multi_i2s_dai_links),
};

static int multi_i2s_probe(struct platform_device *pdev) {
    multi_i2s_card.dev = &pdev->dev;
    return devm_snd_soc_register_card(&pdev->dev, &multi_i2s_card);
}

static struct platform_driver multi_i2s_driver = {
    .driver = {
        .name = "zyndacadsx8",
        .owner = THIS_MODULE,
    },
    .probe = multi_i2s_probe,
};

module_platform_driver(multi_i2s_driver);
MODULE_LICENSE("GPL");

That is very rough, partially created by chatgpt and no real quality control. It may be wildly inaccurate!

I was worried that we will need to do a little bit more than just overlay. If we need to develop our own codec where can I found more information what is the process of compiling it and registering for overlay to see it ?

Yay! I have written a codec driver that provides duplex audio… and it works!!! I took the spdif_dit codec and modified to provide duplex operation, so it creates both two inputs and two outputs for each I2S port. I have put the code in a repo within my GitHub account.

Please let me know if it works. I can’t test audio input at the momement due to a suspected faulty board. (I need to solder the other board up…)

2 Likes

This is great !!! Testing it now.

:pleading_face:

Nothing in my postal box today

@riban what is the easiest way to get zynthian linux environment ready to compile. I am missing kernel header files and probably few other bits and peaces. I am searching the net to see how to get them all installed but maybe you can quickly tell me what is the minimum.

Shame - I’ve sent you tracking number - did you check ?

Sorry - I noticed some issues just before I was called away and due to our age-old-enemy, git… was twarted from pushing the fixes.

Check the README. I think it is all there now.

[EDIT] WAIT! I have broken it… I will update soon…

Hm, kernel headers are not enough:

(venv) root@zynthian:~/zynaudio# apt-get install raspberrypi-kernel-headers
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
raspberrypi-kernel-headers
0 upgraded, 1 newly installed, 0 to remove and 14 not upgraded.
Need to get 0 B/10.2 MB of archives.
After this operation, 64.8 MB of additional disk space will be used.
Selecting previously unselected package raspberrypi-kernel-headers.
(Reading database ... 179624 files and directories currently installed.)
Preparing to unpack .../raspberrypi-kernel-headers_1%3a1.20230405-1_arm64.deb ...
Unpacking raspberrypi-kernel-headers (1:1.20230405-1) ...
Setting up raspberrypi-kernel-headers (1:1.20230405-1) ...
(venv) root@zynthian:~/zynaudio# make
make -C /lib/modules/6.6.47-v8-16k+/build M=/root/zynaudio modules
make[1]: *** /lib/modules/6.6.47-v8-16k+/build: No such file or directory. Stop.
make: *** [Makefile:4: all] Error 2
(venv) root@zynthian:~/zynaudio#

I have updated the README and Makefile so it should now work.

Try make clean before make to see if that sorts out your build issue.

[Edit] Here is a zip with the two required files.
zynaudio8x.zip (2.8 KB)

Put zynaudio8x.dtbo in /boot/firmware/overlays/.
Put spdif_duplex.ko in /lib/modules/6.6.51+rpt-rpi-2712/kernel/drivers/.

yes, right now.
It should be in the post office. I will be able to try to catch it tomorrow morning.
:+1:

@riban, make clean does not resolve the issue. Even make clean throw the same error.

(venv) root@zynthian:~/zynaudio/zynaudiox8# make clean
make -C /lib/modules/6.6.47-v8-16k+/build M=/root/zynaudio/zynaudiox8 clean
make[1]: *** /lib/modules/6.6.47-v8-16k+/build: No such file or directory. Stop.
make: *** [Makefile:8: clean] Error 2
(venv) root@zynthian:~/zynaudio/zynaudiox8#

I hope that I don’t need to clone the whole kernel. :frowning:

This will not work. Oram kernel is still older than what you have:

(venv) root@zynthian:/lib/modules# ls -la
total 36
drwxr-xr-x   9 root root 4096 Nov 25 18:29 .
drwxr-xr-x 100 root root 4096 Nov 25 17:48 ..
drwxr-xr-x   2 root root 4096 Nov 25 18:30 6.1.21-v8+
drwxr-xr-x   3 root root 4096 Jul  4 01:05 6.6.31+rpt-rpi-2712
drwxr-xr-x   3 root root 4096 Jul  4 01:05 6.6.31+rpt-rpi-v8
drwxr-xr-x   3 root root 4096 Sep  5 23:24 6.6.47+rpt-rpi-2712
drwxr-xr-x   3 root root 4096 Sep  5 23:24 6.6.47+rpt-rpi-v8
drwxr-xr-x   3 root root 4096 Sep 11 19:37 6.6.47-v8+
drwxr-xr-x   3 root root 4096 Sep 11 19:38 6.6.47-v8-16k+
(venv) root@zynthian:/lib/modules#

I had to at the end download the whole kernel to get link to build dirs.

I have compiled and installed the codec and complied and installed overlay.

In zynthian I have set the following:

driver:
dtoverlay=zynaudio8x
force_eeprom_read=0

Jackd Options
-P 70 -s -S -d alsa -d hw:zynaudio8x -r 48000 -p 128 -n 2 -i 2 -o 2 -X raw

Zynthian boots and audio out is working. If you add audio chain Input is sending loud white noise.

1 Like

Ah! Not good! That is what I hear. I thought it may have been my card. I’ll have a think about it tomorrow.

@riban , if you have not checked already, it would be worth checking source code of the codec that this guy made it working on older kernel. Our card should be the same as the one that he used. He managed to record using audacity with no problems.

https://kentaromitsuyasu.medium.com/creating-an-audio-input-output-board-for-raspberry-pi-jetson-nano-pcm5102a-pcm1808-e3e6f3ad0834

I believe the noise on the input is due to PCM1808 only supporting 24-bit audio. We have it configured for 32-bit and so there are 8 (most significant) bits of noise. This is validated by the low-level tone I can hear below the noise from the tone generator I am feeding into the input.

I tried changing dai-tdm-slot-width = <24> which should work but this throws an error when trying to load the driver: ASoC: error at snd_soc_dai_set_tdm_slot on 1f000a4000.i2s: -22.

My duplex driver is a simple wrapper. I need to dig deeper…

@riban, I can’t thank you enough for your persistence in creating a driver for this. I learned a lot through this process.

1 Like

Every day is a school day…

It looks like the simple-card driver is throwing an error before the codec driver even has a chance to set the TDM width. We may need a new card driver…

I can already see a new zynaudio8x.c appearing inside raspberry Linux kernel tree branch :slight_smile: