Go Back   Home > Forums > >

PC Based Computer music servers, crossovers, and equalization

2-in, 8-out DSP platform using the Raspberry Pi + HATs
2-in, 8-out DSP platform using the Raspberry Pi + HATs
Please consider donating to help us continue to serve you.

Ads on/off / Custom Title / More PMs / More album space / Advanced printing & mass image saving
Reply
 
Thread Tools
Old 24th February 2019, 09:11 PM   #1
CharlieLaub is offline CharlieLaub  United States
diyAudio Member
 
Join Date: Mar 2007
Location: Michigan
Default 2-in, 8-out DSP platform using the Raspberry Pi + HATs

I like to do DSP processing under Linux on small, inexpensive, low-powered computers. The prototypical example of this is the Raspberry Pi, now available in version 3B+. The Pi has enough computing power for multichannel IIR filter processing. The challenge has been getting high quality audio in and out of the Pi. Until now I have been using USB audio devices such as pro audio interfaces, however, I recently discovered some new (to me) products that let you do this via HATs.

Raspberry Pi:
I am using the Pi 3B+. A great deal at $35.

Audio Input:
I discovered that HiFiBerry recently released a HAT that combines a DAC and an ADC. Seems to have good specs:
Datasheet DAC+ ADC | HiFiBerry
I don't have one in hand yet, but HiFiBerry has a solid reputation. The HAT uses the GPIO header to communicate with the Pi. Audio is up to 24/192k. Scroll down the page at the link above to the SPECIFICATIONS section to see all the details. A high quality ADC on a Raspberry Pi HAT is new to me, so I am very excited about this product.

Audio Output:
Another product I recently discovered is an HDMI audio extractor HAT. I have seen it sold by Audiophonics, by Suptronics, and by a company called WINGONEER. Not sure who developed the product first, but I will link to the Suptronics page:
Raspberry Pi Expansion Board
This HAT uses an EP91A6SX HDMI processing chip to extract audio (Linear PCM only) from the HDMI output of the Pi. It then feeds this to one of four ESS ES9023 DAC chips onboard. On-board audio connection consist of four 1/8" stereo jacks. I bought and measured the audio from this board and it's not bad at all. See attached 1kHz spectrum and THD+N measurement. It does take some programming effort to get this working with the Pi but afterwards I was able to render eight channels of 24-bit, 192kHz audio through this board. I will explain how below.

Power is delivered to the Pi via the HDMI audio extractor HAT. It requires a 5V supply at a minimum of 4A.

The HDMI audio extractor HAT does not use the GPIO pins and can actually be used as a standalone unit if you wanted to extract audio from a DVD or Blue Ray player. This means the GPIO pins can be used by another HAT, in this case that HAT is the HiFiBerry DAC+ADC HAT. Together we have a 24/192 stereo input and 8 channel output connected to and running through a Raspberry Pi that can do DSP processing via LADSPA using ecasound, Gstreamer, or even natively under ALSA (if you dare!).

What's the Catch?
The HDMI extractor HAT only produces 2 channels of audio out of the box. In order to get all 8 channels working up to 24/192 you need to change several lines in one source code module for the kernel and the recompile it. I believe the OS must be Raspbian so that the HiFiBerry HAT will work properly. There are instructions on how to build the kernel here:
Kernel building - Raspberry Pi Documentation
This was my first time attempting this, and I feared this would take days to finish. To my surprise on a Pi 3B+ it only took about 1.5 hours. Nice!

I will put together instructions on how to make the necessary edits and post those separately.

Finally, I would like to thank forum member jrubins for help with building the kernel and implementing these changes!
Attached Images
File Type: png X6000 Pi HAT THDN measurement.png (67.4 KB, 2015 views)
__________________
Visit my Audio Web Page <<--CLICK TO LEARN MORE-->> Get my LADSPA plugins
  Reply With Quote
Old 24th February 2019, 10:36 PM   #2
Jerms is offline Jerms  United Kingdom
diyAudio Member
 
Join Date: Jun 2015
Location: High Wycombe, Bucks, UK.
I was just thinking jrubins could help with that.... Then I finished reading the post.

Maybe it's time to ask Mr Raspbian to default to 8 channels on HDMI audio? Pi capabilities are far from the 1 core @ 700MHz and 256MB RAM of the original Model 2B.
  Reply With Quote
Old 25th February 2019, 04:58 PM   #3
CharlieLaub is offline CharlieLaub  United States
diyAudio Member
 
Join Date: Mar 2007
Location: Michigan
FOLLOW THESE STEPS TO MAKE THE NECESSARY CHANGES TO HDMI AUDIO AND REBUILD THE KERNEL.

Step 1: Make sure you have the necessary tools and the kernel sources installed on your machine
cd to your home directory, then run the following commands to install some build tools
Code:
sudo apt update
sudo apt install build-essential libncurses-dev bison flex libssl-dev libelf-dev git bc
Now, while still in your home directory, get the kernel sources.
This takes a little while. When completed you will have a new directory called "linux" in your home directory.

Step 2: Create a helpful script file for editing the edit_bcm2835-pcm.c file:
cd into the linux directory.
Create a new file in the kernel directory and open it for editing using nano:
Code:
nano edit_bcm2835-pcm.sh
Paste the following text into the nano editor:
Code:
#!/bin/bash

#this script must be run as root or with sudo or will exit here:
if [ "$EUID" -ne 0 ]
  then echo "Please run as root or using sudo"
  exit
fi

#opens the bcm2835-pcm.c file for editing using nano
nano ./drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c
Save the file and exit the editor (CTRL-x, y, return to accept the filename).
Change the file so that it may be executed:
Code:
chmod +x edit_bcm2835-pcm.sh
Step 3: create a helpful script file for building the kernel
(this automates the steps outlined at the raspbian.org link in post#1)
Create a new file in the linux directory and open it for editing using nano:
Code:
nano build_kernel.sh
Paste the following text into the nano editor:
Code:
#!/bin/bash
#this script will build the kernel from the source in ~/kernel
#see for more info:
#  Kernel building - Raspberry Pi Documentation

#this script must be run as root or with sudo or will exit here:
if [ "$EUID" -ne 0 ]
  then echo "Please run as root or using sudo"
  exit
fi

#setup:
KERNEL=kernel7
make bcm2709_defconfig

#these commands build the kernel:
make -j4 zImage modules dtbs
make modules_install
cp arch/arm/boot/dts/*.dtb /boot/
cp arch/arm/boot/dts/overlays/*.dtb* /boot/overlays/
cp arch/arm/boot/dts/overlays/README /boot/overlays/
cp arch/arm/boot/zImage /boot/$KERNEL.img
Save the file and exit the editor (CTRL-x, y, return to accept the filename).
Change the file so that it may be executed:
Code:
chmod +x build_kernel.sh

Step 4: Edit the bcm2835-pcm.c file and make the necessary changes:
While in the linux directory, run the script file:
Code:
sudo ./edit_bcm2835-pcm.sh
Near the top of the file, lines 28-43, there is a section starting with (line 28):
Code:
static const struct snd_pcm_hardware snd_bcm2835_playback_spdif_hw = {
Replace the existing code with this new code:
Code:
static const struct snd_pcm_hardware snd_bcm2835_playback_spdif_hw = {
        .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
        SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
        .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_3LE,
        .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_44100 |
        SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000,
        .rate_min = 44100,
        .rate_max = 192000,
        .channels_min = 2,
        .channels_max = 8,
        .buffer_bytes_max = 256 * 1024,
        .period_bytes_min = 1 * 1024,
        .period_bytes_max = 256 * 1024,
        .periods_min = 1,
        .periods_max = 256,
};
The code shown above reflects changes made to the following fields:
formats
rates
rate_max
channels_max
buffer_bytes_max
period_bytes_max
periods_max

After double checking the changes, save the file and exit the editor (CTRL-x, y, return to accept the filename).

Step 5: Build the kernel
Before building the kernel, check which kernel you have now:
Code:
uname -a
Make a mental note of the version.
While in the linux directory, run the script file to build the kernel:
Code:
sudo build_kernel.sh
Building the kernel took about 1.5 hours on a Pi 3B+ with the cpu governor set to performance, but can take several hours on older Pi versions.
When the build process is done you should see the command prompt again, with the last statement something like DEPMOD and the new kernel version number.
Reboot the machine to load the new kernel.

DOUBLE CHECKING AND TROUBLESHOOTING:
Check which kernel you have now:
Code:
uname -a
This should be a newer version than you had previously. If not it's possible that the old kernel file is still on the machine and the Pi is still booting from it. Check that the new kernel was just built:
Code:
ls -l /boot/kernel7.img
The date should reflect the last build. If there is another file called "kernel.bin" you can rename it to "kernel.bin.old" and then edit the config.txt file to tell the Pi to use the kernel7 file when booting.
Open the config.txt file using an editor (here I use nano):
Code:
sudo nano /boot/config.txt
Add these lines at the end of the file:
Code:
#specify which kernel image to load
kernel=kernel7.img
Save the file and exit the editor (CTRL-x, y, return to accept the filename).
You will need to reboot to load up the kernel again.
Check that ALSA sees the bcm2835 audio system by running aplay:
Code:
aplay -l
The output should look like this:
Code:
**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
  Subdevices: 7/7
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
If you do not see the sound card called ALSA, add these lines to your config.txt file as described above, and then reboot:
Code:
# Enable audio (loads snd_bcm2835)
dtparam=audio=on
__________________
Visit my Audio Web Page <<--CLICK TO LEARN MORE-->> Get my LADSPA plugins

Last edited by Pano; 5th March 2019 at 05:04 PM. Reason: directory name changes
  Reply With Quote
Old 3rd March 2019, 10:34 PM   #4
korakinos is offline korakinos
diyAudio Member
 
Join Date: Mar 2019
Wow, this is very promising! I just started a project with a Raspberry Pi and an audio extractor (a separate device, not a HAT, as I couldn't and still cannot find them anywhere to buy), and naively expected 8-channel audio to "just work"

Following your thorough build instructions (thanks, CharlieLaub!) I arrive at the same output of "aplay -l" in the end, listing in total 8 output subdevices, as I understand it. So far, so good.

But from here I don't know how to continue, and I would very much appreciate any help or pointers.

Am I right in thinking that I need to configure ALSA? What would a very basic asound.conf (or .asoundrc) for all eight channels look like? I saw jrubinstein's config[0], which does a lot of filtering which I don't need, and some posts on stackexchange[1] with configurations for addressing 8 channels separately (which is what I need) using a USB sound card. I have tried to put together my own asound.conf based on those, but without success so far. (Needless to say, I'm not really familiar with configuring ALSA.)

Should something like
Code:
aplay -D "hw:0,0" /usr/share/sounds/alsa/Noise.wav
work right away? Also with "0,1"..."0,6" and "1,0" instead of "0,0", to address the other channels? That's how it should work in my mind, but it doesn't.
(Only "0,0" produces sound, the other "0,X" give the error "aplay: main:788: audio open error: No such file or directory"; "1,0" gives the error "ALSA lib pcm_hw.c:1713:(_snd_pcm_hw_open) Invalid value for card".)


[0] raspiDSP/alsa configuration asoundrc-experimental2.cpp at master * jrubinstein/raspiDSP * GitHub

[1] audio - 8 independants mono channel on 7.1 sound card, but possibility to play sound on 8 channels simultaneously - Unix & Linux Stack Exchange
  Reply With Quote
Old 4th March 2019, 01:02 AM   #5
CharlieLaub is offline CharlieLaub  United States
diyAudio Member
 
Join Date: Mar 2007
Location: Michigan
@korakinos:

You do not need to configure anything in ALSA... let me clear up some of your confusion first... looking at the output from aplay -l I posted:
Code:
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
  Subdevices: 7/7
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
CARD "0" is the audio system built into the bcm2835 SOC itself. There are two devices:
The first one "device 0: bcm2835 ALSA [bcm2835 ALSA]" is analog audio I think. Not sure why it has 7 subdevices (not 8 as you claim) listed. This is hw:0,0
The second device is "device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]" and it is this CARD/DEVICE that refers to the audio sent to the HDMI port on the Pi, that will then be extracted by the X6000 HAT. This is hw:0,1

The number of channels is not shown by aplay. Instead you should look in /proc/asound/card0/pcm1p/sub0 for a codec or stream# file or similar info. But we know that it has 8 channels.

Your next question is "how to I send audio to the 8 output channels". You can try to play an 8 channel wave file using mplayer. You can install a program like ecasound that does routing, meaning it can route or map input channels to output channels, the inputs coming from a file or from a live input. Or you can try to play audio from a player that will let you send the N channels to the HDMI (hw:0,1) output. VLC probably can do it, but it not alone in that regard.

If you can't get it working, post here again and I will try to give you more specific help.
__________________
Visit my Audio Web Page <<--CLICK TO LEARN MORE-->> Get my LADSPA plugins

Last edited by CharlieLaub; 4th March 2019 at 01:04 AM.
  Reply With Quote
Old 4th March 2019, 08:51 AM   #6
korakinos is offline korakinos
diyAudio Member
 
Join Date: Mar 2019
This is very kind of you, thank you. You are right, I was (and am) confused and inexperienced in this, so I appreciate a lot that you took the time to explain.
Quote:
The number of channels is not shown by aplay. Instead you should look in /proc/asound/card0/pcm1p/sub0 for a codec or stream# file or similar info. But we know that it has 8 channels.
I can find no such file and no mention of eight channels in any of the other files in the folder. But it all worked out in the end anyway, so that's probably not important.

Playing few multichannel files[0] from VLC with one of the HDMI devices selected (there is "Direct hardware device without any conversions", "Hardware device with all software conversions"; and also "Direct sample mixing device", but that one didn't produce sound at all)), did not work, they all came out mixed down to stereo.

In the end, I want to access the eight channels from Pure Data, which can use ALSA, OSS, Jack or portaudio as a backend, that's why I thought configuring ALSA was the way to go. Now I tried Jack instead, selecting the HDMI device from Qjackctl and starting the daemon from there and success! 8 channels of audio addressable from Pure data with the Jack backend selected. Very happy, thanks again!.


[0] https://www2.iis.fraunhofer.de/AAC/C...ion441-16b.wav
http://www-mmsp.ece.mcgill.ca/Docume...Channel_ID.wav
https://github.com/sfiera/flac-test-...urround71.flac
  Reply With Quote
Old 4th March 2019, 09:13 AM   #7
phofman is offline phofman  Czech Republic
diyAudio Member
 
Join Date: Apr 2005
Location: Pilsen
IMO there is no need to complicate your setup with jackd between puredata and alsa-lib/alsa driver. Jack has a fixed samplerate, another binary to start, configure etc.

If the soundcard has 8 output channels, you can use them all directly in alsa. This tutorial Pure Data shows puredata supports multichannel soundcards, should be simple to use just like stereo sound devices.

Create an 8-channel wav (e.g. using sox, you may already have some) and play it with aplay like this:

Code:
aplay -v -D plughw:0,X -c 8 --dump-hw-params your.wav
For various X (0, 1, ...)

Please post output of aplay (incl. the verbose debug of what the plug plugin does + the hw params) when the command works.
  Reply With Quote
Old 4th March 2019, 01:21 PM   #8
CharlieLaub is offline CharlieLaub  United States
diyAudio Member
 
Join Date: Mar 2007
Location: Michigan
Here is a simple test you can try. I just did this over SSH on my machine, but did not "listen" for audio output.

Run speaker-test
Code:
pi@raspberrypi:~ $ speaker-test -Dhw:0,1 -c 8

speaker-test 1.1.3

Playback device is hw:0,1
Stream parameters are 48000Hz, S16_LE, 8 channels
Using 16 octaves of pink noise
Rate set to 48000Hz (requested 48000Hz)
Buffer size range from 64 to 16384
Period size range from 64 to 16384
Using max buffer size 16384
Periods = 4
was set period_size = 4096
was set buffer_size = 16384
 0 - Front Left
 4 - Center
 1 - Front Right
 7 - Side Right
 3 - Rear Right
et cetera...
The output on my machine is shown above. Control-C to stop.

While speaker-test is running, look at the file hw_params that corresponds to that card, device, and subdevice:
Code:
pi@raspberrypi:~ $ cat /proc/asound/card0/pcm1p/sub0/hw_params
access: RW_INTERLEAVED
format: S16_LE
subformat: STD
channels: 8
rate: 48000 (48000/1)
period_size: 4096
buffer_size: 16384
The output on my machine is shown above. You can use two terminal windows to do this, with one running speaker test and the other running the cat command while speaker-test is running.

This shows speaker-test using 8 channels for output. You can also try to use other rates and audio formats with speaker test (see the man page). You can also listen for audio output.

Finally, you wanted to do some playback over all 8 channels but did not really say what you wanted to do exactly. Did you want to play surround sound audio (e.g. 7.1 channels) or upmix, implement a multichannel crossover, or something else?
__________________
Visit my Audio Web Page <<--CLICK TO LEARN MORE-->> Get my LADSPA plugins
  Reply With Quote
Old 4th March 2019, 03:14 PM   #9
skyunlimited is offline skyunlimited  Germany
diyAudio Member
 
Join Date: Aug 2009
I am using this kernel modification for a few years now with Brutefir as room correction/crossover. My Amp is an old Onkyo 7.1 AVR with HDMI. The cost for the used AVR was less then the cost of the mentioned Audio Card .

For me every output above S16_LE is not working.
  Reply With Quote
Old 4th March 2019, 04:56 PM   #10
phofman is offline phofman  Czech Republic
diyAudio Member
 
Join Date: Apr 2005
Location: Pilsen
Quote:
Originally Posted by skyunlimited View Post
For me every output above S16_LE is not working.
And does that output device support larger samples than 16 bits?
  Reply With Quote

Reply


2-in, 8-out DSP platform using the Raspberry Pi + HATsHide this!Advertise here!
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ES9018K2M, ES9028Q2M, 9038Q2M DSD/I2S DAC HATs for Raspberry Pi iancanada PC Based 925 Today 02:15 PM
Odroid, BBB, Raspberry Pi or MarsBoard, which platform to use for building a DYI SBT Eeerni Digital Line Level 8 12th October 2019 08:53 AM
Interest survey: Cow Town Audio Fest - Calgary, 2019 (cowboy hats optional) tomchr Clubs & Events 14 22nd October 2018 02:11 AM
Hats off to Mr Pass, encouragement to new members Russellc Pass Labs 10 17th May 2015 09:23 AM
Hats make better bass? xstephanx Subwoofers 11 9th February 2005 11:59 AM


New To Site? Need Help?

All times are GMT. The time now is 10:18 PM.


Search Engine Optimisation provided by DragonByte SEO (Pro) - vBulletin Mods & Addons Copyright © 2020 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 14.29%
vBulletin Optimisation provided by vB Optimise (Pro) - vBulletin Mods & Addons Copyright © 2020 DragonByte Technologies Ltd.
Copyright ©1999-2020 diyAudio
Wiki