FreeBSD for hi-fi audio: real-time processing, equalizer, MPD and FFmpeg

FreeBSD for hi-fi audio: real-time processing, equalizer, MPD and FFmpeg

A full information to configuring FreeBSD as an audiophile audio server: establishing system and audio subsystem parameters, real-time operation, bit-perfect sign processing, and the very best strategies for enabling and parameterising the system graphic equalizer (equalizer) and high-quality audio equalization with FFmpeg filters. Linux customers can even discover helpful data, particularly in the context of configuring and personalising the MPD participant and filters.

 

→ tłumaczenie: polski

 

With a love of music, I have had a passion curiosity in digital audio processing options for over 20 years. I have used Linux and its underlying instruments in the function of decoder, participant and transport for exterior digital-to-analog converters (hereafter: DACs). Until I grew to become significantly excited about FreeBSD.

 

FreeBSD, bitperfect, realtime, equalizer

 

FreeBSD as a part of a hi-fi audiophile audio system

What, in my opinion, makes FreeBSD superior to Linux is the power to exactly observe the parameters of the audio gadget together with the system kernel parameters and modify them. We are, of course, solely speaking concerning the processing of the audio by the motive force at the working system degree (i.e. by OSS/sound(4) in FreeBSD and ALSA in Linux) and configuring the system in such a means that the info is processed solely at the {hardware} degree of the listening gadget in bit-perfect mode, i.e.: no resampling, routing or channel mixing on the best way to the exterior DAC gadget or sound card. Therefore, I naturally omit the use and configuration of further audio layers in the type of a Jack server, PulseAudio or the unlucky PipeWire from RedHat. Of course, there may be nonetheless the query of a software program sign decoder, however about that later in the article.

An further benefit of utilizing FreeBSD is the truth that it offers higher assist for real-time working system (hereafter: RTOS) and real-time packages. Better doesn’t imply excellent, however Linux is a lot additional behind in this respect. It is solely since 2024, after nemal 20 years, that Real-Time Linux (PREEMPT_RT) has turn into an equal a part of the kernel and its essential software program line.

 

What is a real-time system and why is it so vital in audio processing

An RTOS is a specialised working system designed to deal with time-critical duties with precision and reliability. Unlike general-purpose working methods, a real-time system is designed to reply to occasions and course of knowledge throughout the strictest, smallest potential timeframe.

A key characteristic of RTOS methods is their predictable operation, which signifies that essential duties are assured to be accomplished inside a set time. It is usually mistakenly assumed that real-time methods run quicker. In actuality, nonetheless, it is not about velocity, however about reliability and predictability. It is exactly these traits that make RTOS relevant in areas the place time is of the essence, equivalent to: industrial automation methods, aerospace tools, medical units or exactly in the sphere of sound processing.

Running the audio server and participant in real-time system mode provides us the attention and confidence of superior processing high quality. So if we’re trying to construct an audiophile system with out compromise, FreeBSD can be an glorious selection. In the context of our resolution, we are speaking a couple of system working as a transport or stereo participant. We usually are not speaking about studio purposes, the place mixing channels or, for instance, interfacing with a MIDI interface, places a completely different goal to utilizing an RTOS.

 

Audio high quality in FreeBSD and Linux – a comparability

The many hours of listening checks I carried out confirmed that FreeBSD and Linux methods configured in bit-perfect mode present the identical degree of audio gadget efficiency. However, what speaks in favour of FreeBSD is the exact management of all parameters of the {hardware} dealing with course of at the working system degree and the power to alter them, giving us an virtually final degree of oversight and information.

ALSA – the Linux sound dealing with system – principally adjusts all parameters routinely, so it is questionable whether or not the bit-perfect mode enabled by the interface (or slightly protocol) hw:0,0 is what we count on. In FreeBSD, it is not simply concerning the intuitive dev.pcm.%d.bitperfect parameter in the sound(4) driver configuration, but additionally about the remainder of the configuration prospects and full transparency.

 

FreeBSD, Linux, audio comparison

 

Audio {hardware} assist in FreeBSD and Linux

It have to be mentioned, nonetheless, that there’s one essential distinction between FreeBSD and Linux. While in Linux, even in bit-perfect mode (hw:0,0) nearly each built-in sound card or USB DAC works accurately, the identical can’t be mentioned for FreeBSD. It occurs that the enabled parameter dev.pcm.%d.bitperfect=1 implies issues. For instance, certainly one of these is the failure to correctly recognise the PCM format descriptors supported by the gadget (very true for XMOS communication chips). Any forcing of the parameter, together with by dev.pcm.%d.play.vchanformat=s16le:2.0 doesn’t have the specified impact. This was the case with the Presonus Audiobox iOne sequence units I examined. The bit-perfect mode ought to be switched off, in which case a mounted resampling of every knowledge supply at 48 okHz is routinely enabled. However, below Linux management, the items work positive.

In addition, out of persistent obligation, yet one more downside ought to be talked about, particularly for {hardware} configurations utilizing USB DAC units – random, as soon as in a dozen minutes interference, audible clicks throughout playback. Although there may be no rule right here – in one {hardware} specification the whole lot can be OK, in one other not so a lot. This is a topic for a separate article, but when the issue has appeared, regardless of prolonged makes an attempt with completely different delay parameters, buffers, debugging PCM units and finding out the mutual interference of particular person parts, I have so far not discovered a resolution.

Fortunately, in most circumstances it is potential to configure the audio gadget as anticipated in FreeBSD. Quite merely, most parameters are chosen by the system out of the field.

 

FreeBSD and audio subsystem configuration

Let’s transfer on to configuring the parameters of FreeBSD and its audio subsystem. The settings are for the newest model, FreeBSD 14.2, which from 2024 brings many new options to the audio stack after a number of years of stagnation, and in keeping with the FreeBSD Foundation, work will proceed.

The function of audio server and participant is carried out by the MPD (Music Player Daemon – named as mpd in Linux and musicpd(1) in FreeBSD). The MPD server interfaces are ncmpcpp(1) and mpc (musicpc(1) in FreeBSD).

Listening system specification:

  • Computer: Lenovo ThinkCentre M600 Tiny Thin Client N3010 2×1.04GHz 4GB 16GB SSD
  • Storage: Seagate Expansion SSD 2TB USB
  • DAC: Cambridge Audio DacMagic Plus (new capacitor path: Panasonic FM, ELNA for Audio; Tomanek energy provide)
  • USB cable: WireWorld ULTRAVIOLET 8
  • Headphone amplifier: Forum608 IV Dual Mono (Klasa A)
  • RCA Interconnect: Audioquest Goldengate 0,6m
  • Headphones: Beyerdynamic 990 Pro 250 Ohm, 990 Edition 600 Ohm

Most listened albums:

  • Iron Maiden – Fear Of The Dark
  • McIntosh Audiophile Test Reference
  • Alan Parson Project – Stereotomy
  • The WHO – Quadrophenia
  • Depeche Mode – Violator
  • HD Audiophile Speaker Set-Up (192-24)
  • TOOL – Lateralus

 

FreeBSD configuration recordsdata

Essentially, the primary and most vital a part of the FreeBSD system configuration is primarily based on three configuration recordsdata: /boot/loader.conf, /and many others/sysctl.conf, /and many others/rc.conf. Below are gadgets which can be related in the context of bit-perfect audio and system operation in the RTOS function.

 

/boot/loader.conf

sysctlinfo_load="YES" 
mac_priority_load="YES" 
#trace.pcm.5.eq=1 
  • Adding the sysctlinfo(4) module, which is chargeable for prolonged course of communication with particular person kernel sysctl states and MIB tree parts. Not required, however the interface is utilized by some purposes, e.g. mixertui(8).
  • The mac_priority(4) module establishes permission scheduling guidelines so that privileged customers can use the rtprio(1) device to run processes with real-time precedence.
  • This parameter is chargeable for enabling the graphic equalizer (equalizer) for the dev.pcm.5 gadget (in the specification given above, that is the USB DAC gadget). We omit it from the bit-perfect configuration, as mentioned additional in the part Graphic Equalizer in FreeBSD..

 

/and many others/sysctl.conf

kern.timecounter.alloweddeviation=0 
hw.usb.uaudio.buffer_ms=2 
hw.snd.latency=0 
dev.pcm.5.play.vchans=0 
dev.pcm.5.bitperfect=1 
hw.snd.default_unit=5 
#hw.snd.vpc_0db=80 
#dev.pcm.5.eq_preamp=-5 
  • Quite an vital parameter indicating an improve in the precision of the software program clocks used to synchronise course of wake-up, minimising the variety of instances the processor is compelled to carry out a comparatively costly operation to enter and exit idle states. For a deeper understanding of course of wake-up latency and the influence of system clock frequency on this latency, I suggest Paul Herman’s article, the place the benchmark supply code is accessible in addition to the take a look at outcomes. To visualise the impact of the kern.timecounter.alloweddeviation parameter on latency, beneath are the outcomes of the take a look at on my system:
# ./wakeup_latency
0.007341
0.014410
0.037370
0.037336
0.037375
0.037345
0.037356
...
# sysctl kern.timecounter.alloweddeviation=0
kern.timecounter.alloweddeviation: 5 -> 0

# ./wakeup_latency
0.000061
0.000095
0.000077
0.000093
0.000096
0.000090
0.000062
...
  • Driver parameter snd_uaudio(4) for USB audio units (the system masses the module when it detects a appropriate gadget). Defines the info vary laid out in ms reported for processing. Shorter instances, imply decrease knowledge latency, nevertheless it is price experimenting with the parameter.
  • The knowledge switch latency, except the software program (e.g. the participant) for some motive modifications this worth to a extra beneficial one.
  • Number of digital playback/recording channels. We solely care about playback from one supply, so disable digital channels. In addition, this selection is required to allow bit-perfect mode.
  • Enabling bit-perfect mode, whereas disabling digital channels, ends in bypassing system DSP, frequency shifting / resampling, equalizer equalization, and many others.). The pure PCM knowledge stream is routed on to the audio finish gadget.
  • In the {hardware} specification proven above, the audio gadget is a USB DAC, seen in the system as dev.pcm.5 – we set this as the default.
  • Relative quantity degree parameter for the audio driver, which defaults to 45. Negligible in bit-perfect mode, however vital in the configuration of the system graphic equaliser (equalizer), negligible in configuration and bit-perfect mode.
  • Similar to the above, a relative quantity degree parameter, however right here in relation to the operation of the system graphic equaliser (default +0.0db), negligible in bit-perfect mode. For extra on the that means of the parameters dev.pcm.%d.eq_preamp and hw.snd.vpc_0db, see Graphic equalizer in FreeBSD.

 

/and many others/rc.conf

musicpd_enable="YES" 
  • In our configuration, we use the Music Player Daemon (MPD) server as the participant – we flip it on throughout system startup in regular mode. In the remainder of the configuration, we begin musicpd(1) with real-time precedence.

 

FreeBSD instructions to assist examine the standing of drivers, kernel parameters (sysctl) and the audio subsystem

Using the next command, we can show a checklist of loaded kernel modules and make sure that the parts we have added to it are current:

# kldstat

The outcome ought to be near the next:

Id Refs Address                Size Name
 1   43 0xffffffff80200000  1f3c6c0 kernel
 2    1 0xffffffff8213d000     3368 sysctlbyname_improved.ko
 3    1 0xffffffff82142000     77d8 cryptodev.ko
 4    1 0xffffffff8214a000     5b18 sysctlinfo.ko
 5    1 0xffffffff82150000     3c48 mac_priority.ko
 6    1 0xffffffff82154000   5da658 zfs.ko
 7    1 0xffffffff83020000     3390 acpi_wmi.ko
 8    1 0xffffffff83024000     4250 ichsmb.ko
 9    1 0xffffffff83029000     2178 smbus.ko
10    1 0xffffffff8302c000     e5b0 snd_uaudio.ko
11    1 0xffffffff8303b000     2a68 mac_ntpd.ko
12    1 0xffffffff8303e000     3560 fdescfs.ko
13    1 0xffffffff83042000    1aec0 ext2fs.ko

 

The following command will point out the audio units put in on the pc:

# cat /dev/sndstat

Example of a checklist of audio units detected by the system:

Installed units:
pcm0: <Realtek ALC233 (Analog 2.0+HP/2.0)> (play/rec)
pcm1: <Realtek ALC233 (Analog)> (play/rec)
pcm2: <Intel Braswell (HDMI/DP 8ch)> (play)
pcm3: <Intel Braswell (HDMI/DP 8ch)> (play)
pcm4: <Intel Braswell (HDMI/DP 8ch)> (play)
pcm5: <Cambridge Audio Cambridge Audio USB Audio 2.0> (play) default
No units put in from userspace.

 

The kernel parameter hw.snd.verbose defaults to 0. By setting it increased, we improve the quantity of accessible data obtained via the ioctl interface:

# sysctl hw.snd.verbose=4
# cat /dev/sndstat

 

The subsequent command shows extra particulars concerning the audio units (solely the gadget of curiosity is proven in the itemizing):

...
pcm5:  on uaudio0 (1p:0v/0r:0v) default
        snddev flags=0x3e7<SIMPLEX,AUTOVCHAN,SOFTPCMVOL,BUSY,MPSAFE,REGISTERED,BITPERFECT,VPC>
        [dsp5.play.0]: spd 44100, fmt 0x00201000, flags 0x2000012c, 0x00000001, pid 1059 (musicpd)
                interrupts 45405, underruns 0, feed 45404, prepared 8192
                [b:5648/2824/2|bs:8192/2048/4]
                channel flags=0x2000012c<RUNNING,TRIGGERED,SLEEPING,BUSY,BITPERFECT>
                {userland} -> feeder_root(0x00201000) -> {{hardware}}
...

 

The standing of the communication interface of a particular USB gadget is invoked with the command usbconfig(8) (in this case, the bodily deal with ugen0.3 corresponds to the dev.pcm.5 represented in the system):

# usbconfig -d ugen0.3 dump_device_desc

 

Detailed interface knowledge of the USB gadget of curiosity:

ugen0.3:  at usbus0, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=ON (2mA)

  bLength = 0x0012
  bDescriptorType = 0x0001
  bcdUSB = 0x0200
  bDeviceClass = 0x00ef  <Miscellaneous gadget>
  bDeviceSubClass = 0x0002
  bDeviceProtocol = 0x0001
  bMaxPacketSize0 = 0x0040
  idVendor = 0x22e8
  idProduct = 0xdac2
  bcdDevice = 0x0326
  iManufacturer = 0x0001  <Cambridge Audio >
  iProduct = 0x0002  <Cambridge Audio USB Audio 2.0>
  iSerialNumber = 0x0003  <0000>
  bNumConfigurations = 0x0002

 

Parameters of the sysctl interface connecting the sound(4) driver to the PCM driver of the audio gadget:

# sysctl hw.snd

The outcome ought to be just like the next:

hw.snd.maxautovchans: 16
hw.snd.default_unit: 5
hw.snd.default_auto: 0
hw.snd.verbose: 0
hw.snd.vpc_mixer_bypass: 0
0hw.snd.feeder_rate_quality: 1
hw.snd.feeder_rate_round: 25
hw.snd.feeder_rate_max: 2016000
hw.snd.feeder_rate_min: 1
hw.snd.feeder_rate_polyphase_max: 183040
hw.snd.feeder_rate_presets: 100:8:0.85 100:36:0.92 100:164:0.97
hw.snd.feeder_eq_exact_rate: 0
hw.snd.feeder_eq_presets: PEQ:16000,0.2500,62,0.2500:-9,9,1.0:44100,48000,88200,96000,176400,192000
hw.snd.basename_clone: 1
hw.snd.compat_linux_mmap: 0
hw.snd.syncdelay: -1
hw.snd.usefrags: 0
hw.snd.vpc_reset: 0
hw.snd.vpc_0db: 45
hw.snd.vpc_autoreset: 1
hw.snd.timeout: 5
hw.snd.latency_profile: 1
hw.snd.latency: 0
hw.snd.report_soft_matrix: 1
hw.snd.report_soft_formats: 1

 

Status and driver knowledge of the chosen audio gadget:

# sysctl dev.pcm.5

The following itemizing assures us, amongst different issues, that bit-perfect mode is undoubtedly enabled (the proper parameters for this mode: dev.pcm.%d.bitperfect=1, dev.pcm.%d.play.vchans=0) and at the moment processing 44098 MHz knowledge:

dev.pcm.5.feedback_rate: 44098
dev.pcm.5.mode: 3
dev.pcm.5.bitperfect: 1
dev.pcm.5.buffersize: 0
dev.pcm.5.play.vchans: 0
dev.pcm.5.hwvol_mixer: vol
dev.pcm.5.hwvol_step: 5
dev.pcm.5.%iommu:
dev.pcm.5.%father or mother: uaudio0
dev.pcm.5.%pnpinfo:
dev.pcm.5.%location:
dev.pcm.5.%driver: pcm
dev.pcm.5.%desc: Cambridge Audio Cambridge Audio USB Audio 2.0

 

Running the MPD music participant in FreeBSD real-time mode

In the FreeBSD and audio subsystem configuration part, we ready the system to run as a real-time system, that’s, we loaded the mac_priority(4) module and minimised course of processing delays utilizing the kern.timecounter.alloweddeviation parameter. Starting the server and MPD (Music Player Daemon) in the system’s real-time scheduler is achieved utilizing the rtprio(1) command. Before doing so, nonetheless, we should disable the musicpd(1) service that’s began throughout system start-up:

# service musicpd cease
# rtprio 0 musicpd /usr/native/and many others/musicpd.conf

In FreeBSD, the best real-time precedence is 0. Priorities are numbered from 0 to RTP_PRIO_MAX (often 31), the place a decrease worth signifies a increased precedence.

To confirm that the MPD server is working in actual time and with the proper precedence, we browse with ps the checklist of processes, narrowing the response outcome to the musicpd(1) course of:

# ps -o rtprio -axl | grep [m]usicpd

The response of the ps command ought to appear to be this:

actual:0 137 1146 1 0 -52 0 415080 214420 choose I<s - 0:06.55 musicpd /usr/native/and many others/musicpd.conf

Another approach to examine the proper launch of musicpd(1) in actual time utilizing the prime(1) command:

# prime -p `pgrep -d "," musicpd`
final pid:  1162;  load averages:  0.03,  0.07,  0.04              up 0+12:05:50  21:38:34
50 processes:  2 working, 46 sleeping, 2 ready
CPU: 50.0% consumer,  0.0% good, 50.0% system,  0.0% interrupt,  0.0% idle
Mem: 497M Active, 64M Inact, 998M Wired, 49M Buf, 2267M Free
ARC: 85M Total, 27M MFU, 55M MRU, 514K Header, 1935K Other
     66M Compressed, 153M Uncompressed, 2.32:1 Ratio
Swap: 2048M Total, 2048M Free

  PID USERNAME    THR PRI NICE   SIZE    RES STATE    C   TIME    WCPU COMMAND
 1146 mpd           8 -52   r0   605M   227M choose   0   0:12   0.00% musicpd

 

 

Additional instructions in FreeBSD to assist with debugging and troubleshooting the USB audio gadget

 

# sysctl hw.usb.debug=1
# tail -f /var/log/messages
...
Jan 21 21:55:44 freebsd kernel: usbd_pipe_enter: enter
Jan 21 21:55:44 freebsd kernel: usbd_transfer_done: err=USB_ERR_NORMAL_COMPLETION
Jan 21 21:55:44 freebsd kernel: usbd_callback_wrapper_sub: xfer=0xfffffe007c950278 endpoint=0xfffff800038ad968 sts=0 alen=2816, slen=2816, afrm=64, nfrm=64
Jan 21 21:55:44 freebsd kernel: usbd_pipe_start: begin
Jan 21 21:55:44 freebsd kernel: usbd_transfer_submit: xfer=0xfffffe007c950278, endpoint=0xfffff800038ad968, nframes=64, dir=write
Jan 21 21:55:44 freebsd kernel: usb_dump_endpoint: endpoint=0xfffff800038ad968 edesc=0xfffff800056d6491 isoc_next=11268 toggle_next=0 bEndpointAddress=0x01
Jan 21 21:55:44 freebsd kernel: usb_dump_queue: endpoint=0xfffff800038ad968 xfer:
Jan 21 21:55:44 freebsd kernel: usbd_pipe_enter: enter
Jan 21 21:55:44 freebsd kernel: usbd_transfer_done: err=USB_ERR_NORMAL_COMPLETION
Jan 21 21:55:44 freebsd kernel: usbd_callback_wrapper_sub: xfer=0xfffffe007c950148 endpoint=0xfffff800038ad968 sts=0 alen=2824, slen=2824, afrm=64, nfrm=64
Jan 21 21:55:44 freebsd kernel: usbd_pipe_start: begin
Jan 21 21:55:44 freebsd kernel: usbd_transfer_submit: xfer=0xfffffe007c950148, endpoint=0xfffff800038ad968, nframes=64, dir=write
Jan 21 21:55:44 freebsd kernel: usb_dump_endpoint: endpoint=0xfffff800038ad968 edesc=0xfffff800056d6491 isoc_next=11332 toggle_next=0 bEndpointAddress=0x01
Jan 21 21:55:44 freebsd kernel: usb_dump_queue: endpoint=0xfffff800038ad968 xfer:
...
# sysctl hw.usb.uaudio.debug=1
# tail -f /var/log/messages
...
Jan 21 21:53:43 freebsd kernel: uaudio_chan_play_sync_callback: Value = 0x00058330
Jan 21 21:53:43 freebsd kernel: uaudio_chan_play_sync_callback: Comparing 44099 Hz :: 44100 Hz
Jan 21 21:53:44 freebsd kernel: uaudio_chan_play_sync_callback: Value = 0x00058330
Jan 21 21:53:44 freebsd kernel: uaudio_chan_play_sync_callback: Comparing 44099 Hz :: 44100 Hz
Jan 21 21:53:45 freebsd kernel: uaudio_chan_play_sync_callback: Value = 0x00058330
Jan 21 21:53:45 freebsd kernel: uaudio_chan_play_sync_callback: Comparing 44099 Hz :: 44100 Hz
Jan 21 21:53:46 freebsd kernel: uaudio_chan_play_sync_callback: Value = 0x00058330
Jan 21 21:53:46 freebsd kernel: uaudio_chan_play_sync_callback: Comparing 44099 Hz :: 44100 Hz
Jan 21 21:53:47 freebsd kernel: uaudio_chan_play_sync_callback: Value = 0x00058330
Jan 21 21:53:47 freebsd kernel: uaudio_chan_play_sync_callback: Comparing 44099 Hz :: 44100 Hz
Jan 21 21:53:48 freebsd kernel: uaudio_chan_play_sync_callback: Value = 0x00058330
Jan 21 21:53:48 freebsd kernel: uaudio_chan_play_sync_callback: Comparing 44099 Hz :: 44100 Hz
...

 

Graphic equalizer in FreeBSD

A easy, software-based graphic equalizer (equalizer) has been carried out in the FreeBSD system’s sound driver (sound(4)), which permits real-time adjustment of bass and treble. The default kernel compilation assumes adjustment for frequencies: 62 Hz and 16 okHz, we can change these by compiling the kernel with different parameters. To allow the equaliser, set the trace.pcm.%d.eq parameter in the /boot/loader.conf file (a system reload is required):

#/boot/loader.conf
...
trace.pcm.5.eq=1

Enabling the equalizer with trace.pcm.%d.eq will make further controls for bass and treble seem in the mixer purposes. We can parameterise these with the visible utility mixertui(1) or with the system utility mixer(1), for instance:

mixer -f /dev/mixer5 vol=0.75 pcm=0.75 bass=0.82 treble=0.76

In response, receiving the set values and their standing:

vol.quantity: 0.75:0.75 -> 0.75:0.75
pcm.quantity: 0.75:0.75 -> 0.75:0.75
bass.quantity: 0.82:0.82 -> 0.82:0.82
treble.quantity: 0.76:0.76 -> 0.76:0.76
pcm5:mixer:  on uaudio0 (play)
    vol       = 0.75:0.75     pbk
    bass      = 0.82:0.82     pbk
    treble    = 0.76:0.76     pbk
    pcm       = 0.75:0.75     pbk

 

FreeBSD, equalizer, mixer, mixertui

 

Switching on and working the graphic equaliser parameters clearly entails interference with the audio sign. Therefore, when the equalizer is switched on, bitperfect mode will routinely be switched off by the audio driver:

# sysctl dev.pcm.5 | grep bitperfect

Result:

dev.pcm.5.bitperfect: 0

Audio equalization has the potential to introduce some distortion or danger of audio degradation, particularly if utilized in extra. To forestall this, two parameters can be found in the FreeBSD sound driver: hw.snd.vpc_0db and dev.pcm.%d.eq_preamp (not but described in the official documentation). Both parameters set the relative quantity degree to “zero” for the sound driver and equalizer respectively. In basic, they provide extra room for the equalisation calculation to run with out distortion:

  • hw.snd.vpc_0db – is enabled by default with a worth of 45. Increasing this parameter (i.e. decreasing the amount degree) provides a bigger vary for the frequencies processed after correction.
  • dev.pcm.%d.eq_preamp – defaults to 0, with a vary of -9 dB to +9 dB. For instance, setting the extent to -5 will first attenuate your entire audio stream to -5 dB (minus +max dB), and additional amplification is a course of relative to this level (0 dB). This will lead to a decrease quantity from the listener’s perspective, however as above, offers a better alternative to compensate for any artefacts ensuing from processing frequencies over-amplified by equalization.

The parameters are finest used interchangeably and are laid out in the /and many others/sysctl.conf file, however will also be entered at runtime.

Examples:

# sysctl hw.snd.vpc_0db=80
hw.snd.vpc_0db: 45 -> 80
# sysctl dev.pcm.5.eq_preamp=-5
dev.pcm.5.eq_preamp: +0.0dB -> -5.0dB

 

High-quality equalizer – FFmpeg filters

The use of an audio equalizer in a hi-fi audio system, is a topic that raises completely different opinions amongst audiophiles. On the one hand, we have the purist strategy, in which the sound ought to be reproduced as naturally as potential and with none modifications. On the opposite hand, the sensible strategy suggests utilizing a graphic equalizer and adjusting the sound to one’s preferences, the acoustic situations of the room or compensating for imperfections in the audio tools.
We can even compromise, i.e. use the equalizer in moderation, making an attempt to discover the golden imply between pure sound and adjusting the sound to our wants. A appropriate graphic equalizer can enhance listening high quality with out introducing vital distortion.

Such are the wonderful superior filters of the libavfilter library of the FFmpeg undertaking. We can simply implement them in the MPD participant, the place FFmpeg additionally performs the function of sign decoder. The MPD accessible in the FreeBSD ports repository has libavfilter libraries inbuilt. In Debian 12, the MPD must be up to date from the backports repository.

Of course, utilizing an equalizer, we can’t discuss full bitperfect mode, however in our configuration, the bitperfect sign is handed in the info chain to the FFmpeg decoder and delivered to the DAC gadget or sound card by way of libavfilter. This sort of graphic equalizer is sonically a lot better than the system audio driver equalizer carried out in the sound(4) driver of FreeBSD and the alsaequal plugin in Linux..

Before implementing FFmpeg filters on FreeBSD and Linux, it is additionally price remembering to disable the system equalizer.

 

MPD configuration utilizing FFmpeg filters

Using FFmpeg and the libavfilter library in the function of the MPD participant’s graphic equalizer, we are most excited about the filters: bass, treble and anequalizer. In this manner, we will realise a high-quality software program equalizer not solely in FreeBSD, but additionally in Linux. Furthermore, in addition to their sonic qualities, FFmpeg filters can even be helpful in an MPD-based streaming system.

To allow the filter, we add a new part filter {} in the MPD configuration file musicpd.conf, which comprises the definition of the filter (or filters), and add a filter in the audio_output {} part. Furthermore, we ensure that the mixer_type and replay_gain_handler parameters have the proper parameters for bit-perfect mode. We depart the system configuration to the situation outlined in Configuring FreeBSD and the audio subsystem.

 

FFmpeg – bass and treble filters

Example of mixed bass and treble filters:

filter {
  plugin "ffmpeg"
  title "equalizer"
  graph "bass=f=62:t=h:w=120:g=10:n=1:r=f64, treble=f=16000:t=h:width=8000:g=2:n=1:r=f64"
}

audio_output {
  sort "oss"
  title "OSS"
  mixer_type "{hardware}"
  replay_gain_handler "none"
  filters "equalizer"
}

Description of filters:

  • bass – elevate the frequency of 62 Hz over a width of 120 Hz by 10 factors utilizing floating level precision working on 64 bit knowledge;
  • treble – elevate the 16 okHz frequency by 3 factors over a width of 8 okHz utilizing floating level precision working on 64 bit knowledge.

Very vital in each filters is the n parameter, which is chargeable for normalising the sign. In easiest phrases, it routinely lowers the sign amplitude (loudness) in actual time, giving a wider vary of calculations avoiding distortion and artefacts.

.
Visualisation of the frequency response primarily based on the above filters:

FFmpeg

 

FFmpeg – filter anequalizer

One extra filter of the FFmpeg library is price noting, particularly anequalizer. It’s a multi-channel parametric equalizer primarily based on analog Chebyshev and Butterworth filters (advised for audio purposes resulting from a much less distorted sign in the cross band). The coefficients of the anequalizer filter are calculable in phrases of middle frequency, peak achieve, bandwidth and bandwidth achieve.

The definition of the traits proven above with bass and treble filters constructed with anequalizer for MPD, would appear to be this:

filter c0 f=16000 w=8000 g=2 t=0

As you may see, with the anequalizer filter we can construct virtually any graphic equalizer traits. With one caveat – this lacks the choice to normalize the processed sign, excluding distortions ensuing from its processing by the filter. And these could be heard at achieve degree 3 of the g parameter. The parameters of the sound driver, equivalent to hw.snd.vpc_0db, usually are not relevant right here, as a result of the amplitude of the sign can be diminished by the motive force solely after the filtering course of. The solely resolution, is to use a software program quantity mixer in MPD. With a worth of 40%, distortion is not audible, even with a worth of g=10, though that is not one of the simplest ways to get the perfect sound.

We set the software program quantity mixer in MPD utilizing the mixer_type parameter, as beneath:

mixer_type "software program"

 

Designing the traits of the anequalizer filter

The waveform of the traits of the anequalizer filter and its parameters could be designed and visualized utilizing the Intona fima’s DSP editor.

The equal of the next filter definition:

graph "anequalizer=c0 f=62 w=120 g=10 t=0|c1 f=62 w=120 g=10 t=0|c0 f=16000 w=8000 g=2 t=0|c1 f=16000 w=8000 g=2 t=0"

can be in the DSP utility:

peq 62Hz q0.51 10dB
peq 16kHz q2 3dB

The q parameter (Q issue) relative to the w given in the definition is decided from the relation:

I encourage you to design a graphic equalizer that fits your personal preferences.

 

In the article, I lined subjects equivalent to how you can configure the FreeBSD system and its audio subsystem for the very best audio high quality, mentioned a number of facets of the method structure together with the FreeBSD system’s real-time scheduler, bit-perfect sign mode, and how you can allow the system equalizer and configure it accurately for audio processing high quality. Finally, I offered the implementation of a high-quality graphic equalizer in the MPD participant utilizing FFmpeg filters (I additionally suggest this chapter to Linux customers). The ultimate stage of the audio observe and the standard of the ensuing sound already will depend on the {hardware} specs: music card, DAC, headphones, amplifier, audio system, and many others. So, you would say that that is the place the audio journey begins once more 😉

HI-FI News

by way of Hacker News https://ift.tt/MVqvwny

February 6, 2025 at 09:48AM