iTranslated by AI
Sound Field Correction with Raspberry Pi Part 1: Overview and Preparation
Part 2 (Measurement and Correction Results): https://zenn.dev/kymok/articles/627e72a0869d52
HiFiBerry DSP Edition: https://zenn.dev/kymok/articles/790b66454b765d
1. Introduction
What is this?
Audio quality is affected not only by speakers and amplifiers but also by the shape and sound absorption of the room. The purpose of this article is to correct the influence of the room on sound quality through the power of measurement and signal processing[1]. If you are running an AirPlay server with a Raspberry Pi and a DAC, you can easily try out acoustic room correction by adding a measurement microphone costing about 10,000 yen.
If you are purchasing a new DAC, it is better to buy one developed with room correction in mind, so please read the following section on how to choose a DAC. In that case, the methods are well-established, so you may not need to read this article in detail, though it might still be useful for understanding the measurement and correction process.
How to choose a DAC
If you already have a DAC: You can use it as is. This will be explained in this article.
If you are buying a new DAC: Based on my research, the following two products are easy to use from a Raspberry Pi. These perform correction processing via DSP, which reduces the load on the main unit. For the DAC2 Pro and DSP Add-On Board, please refer to the supplement: https://zenn.dev/kymok/articles/790b66454b765d.
Note that even when using these DACs, you can apply correction following the procedures in this article without using the DSP. However, the only advantage is being able to use long impulse responses (several seconds), so it is generally better to simply utilize the DSP.
What is happening?
When sound is played from a speaker, the sound that reaches your ears is affected by the characteristics of the speakers and the room[2]. By comparing the "sound that was supposed to be played" with the "measured sound," these influences can be estimated collectively. By calculating the inverse and applying correction, sound faithful to the original source should reach your ears. Since the correction processing is performed inside the Raspberry Pi, there is no need to change wiring or fiddle with knobs.
Assumed Environment
- Raspberry Pi (Raspberry Pi OS Lite) and any DAC[3]
- AirPlay (Shairport Sync)[4]
- Users who don't insist on things like High-Res or bit-perfect audio[5]
- An environment where the listening and speaker positions are mostly fixed. For example, a work desk.
- A Mac running Room Equalisation Wizard
2. Hardware Preparation
DAC and Raspberry Pi Zero setup. It is tied to a speaker stand with cable ties.
Measurement Microphone
In this article, we use the miniDSP UMIK-1[6]. It costs about 10,000 yen if bought from the official site, and in my case, it arrived from Hong Kong in about three days. Once it arrives, don't forget to download the calibration file.
Content of the calibration file (Excerpt)
The content is a list of sensitivities per frequency and is just a text file. It lists the serial number, sensitivity per frequency, etc.
"Sens Factor =3.9443dB, AGain =18dB, SERNO: XXXXXXX"
10.054 -3.1347
10.179 -2.9856
[...]
437.648 -0.2670
443.096 -0.2634
448.612 -0.2595
[...]
Other Requirements
- Measurement PC: Prepare a Mac if measuring via AirPlay. Any PC is fine if you don't mind the trouble of changing the wiring (wiring changes are not covered in this article).
- Playback Device: Raspberry Pi (confirmed to work with Zero WH in this article).
- DAC: Any suitable DAC (Allo MiniBoss is used in this article).
- Speakers and Amplifier: Choose something appropriate (active speakers with built-in amps are convenient. Genelec 1029A is used in this article).
- Microphone Stand: You could fix the included mini-tripod to the back of a chair with duct tape, but since you'll be measuring multiple times, having a proper stand is convenient. A camera tripod supporting UNC 3/8 (large screw) is also fine.
About Setting Up Audio Equipment
Powering on: For audio equipment, turn on the power starting from the side furthest from the speakers. Also, keep the volume at minimum when turning on or connecting devices for safety.
Speaker Placement: It is convenient for correction if the room's influence on sound is equal on both sides, so try to make the layout as symmetrical as possible relative to the whole room (if it's extremely unbalanced, you can correct the left and right sides separately). That said, unless you live a life centered entirely around speakers, just paying some attention to things mentioned in articles like "How to place speakers" for absolute beginners should be sufficient.
3. Preparing the Raspberry Pi
Installing the OS
Omitted. I used Raspberry OS Lite in this article.
Connecting the DAC
Please refer to your DAC's documentation. For most major ones, you just need to add a single line of dtoverlay to /boot/config.txt.
Example for Allo MiniBoss
For example, in the case of the Allo MiniBoss used in this article, add the following to /boot/config.txt:
dtoverlay=allo-boss-dac-pcm512x-audio
Downloading Correction Files
Download the correction files for testing to your Raspberry Pi. Please execute the following in an appropriate directory. From here on, I will proceed assuming this was executed in /home/USERNAME/.
git clone --depth 1 https://github.com/kymok/test_impulse_responses
mkdir -p impulse_responses
cp test_impulse_responses/test_ir/work/IR_delay_effect_44.wav ./impulse_responses/
cp test_impulse_responses/test_ir/work/IR_unit_44.wav ./impulse_responses/
rm -rf test_impulse_responses/
Installing Shairport Sync
Build and install Shairport Sync on Raspberry Pi OS Lite. It doesn't take much time even on a Raspberry Pi Zero, taking only a few minutes at most. To enable the features necessary for room correction and its configuration, you need to slightly modify the steps from the official documentation.
Preparation
First, complete the steps in the Simple Installation Instructions up to the Build and Install section.
Installing Required Packages
Install the necessary packages. libsndfile1-dev and libglib2.0-dev are the additional ones.
apt-get install build-essential git xmltoman autoconf automake \
libtool libpopt-dev libconfig-dev libasound2-dev avahi-daemon \
libavahi-client-dev libssl-dev libsoxr-dev \
libsndfile1-dev libglib2.0-dev
Building and Installing
Build and install. The arguments --with-convolution and --with-dbus-interface for ./configure are the additional ones.
$ git clone https://github.com/mikebrady/shairport-sync.git
$ cd shairport-sync
$ autoreconf -fi
$ ./configure --sysconfdir=/etc --with-alsa --with-soxr --with-avahi --with-ssl=openssl --with-systemd --with-convolution --with-dbus-interface
$ make
$ sudo make install
To enable the necessary features, add the following settings to /etc/shairport-sync.conf.
general =
{
name = "miniboss";
volume_range_hardware_priority = "yes";
[...]
};
alsa =
{
disable_standby_mode = "always";
output_rate = 44100;
[...]
};
dsp =
{
convolution = "yes";
convolution_ir_file = "/home/USERNAME/impulse_responses/IR_unit_44.wav";
convolution_gain = -10.0;
convolution_max_length = 44100;
}
Enabling the Service
systemctl enable shairport-sync
systemctl start shairport-sync
4. Confirmation of Installation
Checking AirPlay Support
Success if you can see the new AirPlay device from a nearby Apple product. Let's try playing music while gradually increasing the volume from the minimum.
Checking the Correction Function (when not using DSP)
Load the correction file you downloaded earlier into Shairport Sync[7]. The Shairport Sync compiled in this article allows changing settings via D-Bus while music is playing. Other command examples can be found on Shairport Sync's GitHub.
First, check if the correction function is enabled. It's OK if true is returned.
$ dbus-send --print-reply --system --dest=org.gnome.ShairportSync /org/gnome/ShairportSync org.freedesktop.DBus.Properties.Get string:org.gnome.ShairportSync string:Convolution
method return time=1614224073.834660 sender=:1.188 -> destination=:1.189 serial=17 reply_serial=2
variant boolean true
Next, check the filename of the currently set impulse response.
$ dbus-send --print-reply --system --dest=org.gnome.ShairportSync /org/gnome/ShairportSync org.freedesktop.DBus.Properties.Get string:org.gnome.ShairportSync string:ConvolutionImpulseResponseFile
method return time=1614224723.672836 sender=:1.188 -> destination=:1.190 serial=24 reply_serial=2
variant string "/home/USERNAME/impulse_responses/IR_unit_44.wav"
Set the test impulse response. It's a success if the sound starts echoing like in a cave.
dbus-send --print-reply --system --dest=org.gnome.ShairportSync /org/gnome/ShairportSync org.freedesktop.DBus.Properties.Set string:org.gnome.ShairportSync string:ConvolutionImpulseResponseFile variant:string:"/home/USERNAME/impulse_responses/IR_delay_effect_44.wav"
Restore it to the original state.
dbus-send --print-reply --system --dest=org.gnome.ShairportSync /org/gnome/ShairportSync org.freedesktop.DBus.Properties.Set string:org.gnome.ShairportSync string:ConvolutionImpulseResponseFile variant:string:"/home/USERNAME/impulse_responses/IR_unit_44.wav"
Conclusion
In this article, I roughly explained the overview of acoustic room correction and the preparation for Raspberry Pi. Since it became long, I will leave the measurement and correction results to the next article.
Part 2 → https://zenn.dev/kymok/articles/627e72a0869d52
-
Strictly speaking, the room and speakers are viewed as a single unit, and their combined effects are corrected at a specific listening position ↩︎
-
For example, reflections from walls, sound absorption, standing waves, etc. ↩︎
-
You might manage with the onboard audio jack, but it is not recommended for sound quality reasons ↩︎
-
It is possible to do the same thing with something other than Shairport Sync as long as you can perform impulse response convolution, but that will not be covered here ↩︎
-
For such users, since they likely have an ample budget, I think they would be happier buying commercial software that makes advanced processing easy. ↩︎
-
If you already have an analog measurement microphone, you can use it, but it's a bit more troublesome. I won't explain it here, so please refer to the REW documentation for details ↩︎
-
The content is a wav of an impulse response. You will hear a brief click when played. Since it's at the very beginning of the file, it may not play correctly in software that fades in the start of a file. ↩︎
Discussion