The officially official Devuan Forum!

You are not logged in.

#1 2025-04-03 02:32:05

igorzwx
Member
Registered: 2024-05-06
Posts: 228  

Patching on the fly with "stream editor" (fftrate ALSA plugin)

What is really cool about Arch Linux packaging is patching on the fly with sed.
_https://en.wikipedia.org/wiki/Sed
Ordinary patching techniques are also used, of course, in Arch PKGBUILDs, but
the advanced users tend to patch sources on the fly with sed (if possible).

[ArchWiki] Creating patches
Note: If you only need to change one or two lines, you might want to use sed instead.
_https://wiki.archlinux.org/title/Patching_packages

NOTE: This patching technique (sed) is also used in Debian packages (but rather seldom).
      Usually, it is done with quilt _https://wiki.debian.org/UsingQuilt

Petrov's fftrate ALSA plugin has already been patched for new GCC versions.

The package is available in Arch Linux AUR repository:

Package Details: libasound2-plugin-fftrate 1.6.3-1
_https://aur.archlinux.org/packages/libasound2-plugin-fftrate

The  PKGBUILD is a masterpiece. The source code is patched on the fly with sed.
What is more, the problem was fixed with a one-line Linux command:

 prepare() {
	cd "$srcdir/$pkgbase-$pkgver"
	find . -type f \( -name "*.cpp" -o -name "*.c" -o -name "*.h" \) -exec sed -i -e 's/min(/MIN(/g' -e 's/max(/MAX(/g' {} +
} 

_https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=libasound2-plugin-fftrate

NOTE: If you do not understand the magic command, try to ask explainshell.com:

_https://explainshell.com/explain?cmd=find+.+-type+f+%5C%28+-name+%22*.cpp%22+-o+-name+%22*.c%22+-o+-name+%22*.h%22+%5C%29+-exec+sed+-i+-e+%27s%2Fmin%28%2FMIN%28%2Fg%27+-e+%27s%2Fmax%28%2FMAX%28%2Fg%27+%7B%7D+%2B+

...

-exec command {} +
       This variant of the -exec action runs the specified command on the selected files, but the command
       line is built by appending each selected file name at the end; the total number of invocations  of
       the command will be much less than the number of matched files.  The command line is built in much
       the same way that xargs builds its command lines.  Only one instance of `{}' is allowed within the
       command.  The command is executed in the starting directory.

It is simply replacing min( with MIN( and max( with MAX( in "*.cpp", "*.c", and "*.h" files.

TEST
mkdir petrov-fftrate
cd petrov-fftrate
git clone https://github.com/PetrovSE/fftrate.git
cd fftrate
$ grep -Ri "Max(" . | grep ".cpp"
./src/apps/pcm_info/Main.cpp:			nHelpLayer = max( nHelpLayer, 2 );
./src/apps/pcm_info/Main.cpp:				nHelpLayer = max( nHelpLayer, 2 );
./src/apps/pcm_info/Main.cpp:				nHelpLayer = max( nHelpLayer, 3 );
./src/apps/pcm_stretch/Main.cpp:			nHelpLayer = max( nHelpLayer, 2 );
./src/apps/pcm_stretch/Main.cpp:				nHelpLayer = max( nHelpLayer, 2 );
./src/apps/pcm_stretch/Main.cpp:				nHelpLayer = max( nHelpLayer, 3 );
./src/apps/pcm_mse/Main.cpp:			nHelpLayer = max( nHelpLayer, 2 );
./src/apps/pcm_mse/Main.cpp:				nHelpLayer = max( nHelpLayer, 2 );
./src/apps/pcm_mse/Main.cpp:				nHelpLayer = max( nHelpLayer, 3 );
./src/apps/pcm_mse/Main.cpp:			nBits = max( nBits, (WORD)mmsys_format_info( pFile->pFormat, 'b' ) );
./src/apps/pcm_conv/Main.cpp:			nHelpLayer = max( nHelpLayer, 2 );
./src/apps/pcm_conv/Main.cpp:				nHelpLayer = max( nHelpLayer, 2 );
./src/apps/pcm_conv/Main.cpp:				nHelpLayer = max( nHelpLayer, 3 ); 
$ find . -type f \( -name "*.cpp" \) -exec sed -e 's/max(/MAX(/g' {} + | grep "MAX("
			nHelpLayer = MAX( nHelpLayer, 2 );
				nHelpLayer = MAX( nHelpLayer, 2 );
				nHelpLayer = MAX( nHelpLayer, 3 );
			nHelpLayer = MAX( nHelpLayer, 2 );
				nHelpLayer = MAX( nHelpLayer, 2 );
				nHelpLayer = MAX( nHelpLayer, 3 );
			nHelpLayer = MAX( nHelpLayer, 2 );
				nHelpLayer = MAX( nHelpLayer, 2 );
				nHelpLayer = MAX( nHelpLayer, 3 );
			nBits = MAX( nBits, (WORD)mmsys_format_info( pFile->pFormat, 'b' ) );
			nHelpLayer = MAX( nHelpLayer, 2 );
				nHelpLayer = MAX( nHelpLayer, 2 );
				nHelpLayer = MAX( nHelpLayer, 3 ); 

To apply the magic patch on Devuan, you have to download the source code from git,
then open terminal in the source directory and execute the magic command:

$ cd fftrate

$ find . -type f \( -name "*.cpp" -o -name "*.c" -o -name "*.h" \) -exec sed -i -e 's/min(/MIN(/g' -e 's/max(/MAX(/g' {} + 

Then you can compile the fftrate plugin with gcc-12 (and, perhaps, newer versions of GCC).

It works without problems.

$ gcc --version
gcc (Debian 12.2.0-14) 12.2.0

$ uname -a
Linux devuan 6.1.0-32-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.129-1 (2025-03-06) x86_64 GNU/Linux

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Devuan
Description:	Devuan GNU/Linux 5 (daedalus)
Release:	5
Codename:	daedalus 
sudo apt install inxi
man inxi
$ inxi -b | grep Host -A1
  Host: devuan Kernel: 6.1.0-32-amd64 arch: x86_64 bits: 64 Desktop: MATE
    v: 1.26.0 Distro: Devuan GNU/Linux 5 (daedalus)

$ inxi -A
Audio:
  Device-1: Intel 7 Series/C216 Family High Definition Audio
    driver: oss_hdaudio
  Device-2: Griffin iMic type: USB driver: snd-usb-audio
  API: ALSA v: k6.1.0-32-amd64 status: kernel-api
  API: OSS v: N/A status: active
How to compile Petrov's fftrate ALSA plugin on Devuan 5 Daedalus

Install "build-essential", etc.

sudo apt update
sudo apt-get install build-essential git debhelper
sudo apt install libasound2-dev libasound2-plugins swh-plugins

Download the source code:

mkdir petrov-fftrate
cd petrov-fftrate
git clone https://github.com/PetrovSE/fftrate.git

Check the current "recommended compat" for debhelper:

$ man debhelper-compat-upgrade-checklist | grep "recommended mode"
       v13 This is the recommended mode of operation.

       
Change compat to "13":

$ nano ./fftrate/packets/debian/compat

$ cat ./fftrate/packets/debian/compat
13 

Open terminal in the source directory:

$ ls
fftrate

$ cd fftrate 

Apply the magic patch:

find . -type f \( -name "*.cpp" -o -name "*.c" -o -name "*.h" \) -exec sed -i -e 's/min(/MIN(/g' -e 's/max(/MAX(/g' {} + 

Now you can compile the fftrate plugin with gcc-12 (and, perhaps, newer versions of GCC).

$ cd  packets

$ ls -1
debian
etc
Makefile
mk_dpkg 

Build executables:

make -j1 

Make Debian packages:

./mk_dpkg 
$ cd ../

$ ls | grep .deb
alsa-config-utils_1.6.3_amd64.deb
libasound2-plugin-fftrate_1.6.3_amd64.deb
pcm-utils_1.6.3_amd64.deb 

Install the packages:

sudo dpkg -i alsa-config-utils_1.6.3_amd64.deb libasound2-plugin-fftrate_1.6.3_amd64.deb pcm-utils_1.6.3_amd64.deb

Dependencies:

libasound2 
libasound2-plugins 
swh-plugins

Notice that the Arch package depends on fftw library (make)
_https://aur.archlinux.org/packages/libasound2-plugin-fftrate

It should already be installed (automatic, as a dependency):

$ apt search libfftw3-dev
Sorting... Done
Full Text Search... Done
libfftw3-dev/stable,now 3.3.10-1 amd64 [installed,automatic]
  Library for computing Fast Fourier Transforms - development

libfftw3-double3/stable,now 3.3.10-1 amd64 [installed,automatic]
  Library for computing Fast Fourier Transforms - Double precision

libfftw3-long3/stable,now 3.3.10-1 amd64 [installed,automatic]
  Library for computing Fast Fourier Transforms - Long precision

libfftw3-quad3/stable,now 3.3.10-1 amd64 [installed,automatic]
  Library for computing Fast Fourier Transforms - Quad precision

libfftw3-single3/stable,now 3.3.10-1 amd64 [installed,automatic]
  Library for computing Fast Fourier Transforms - Single precision 

The user manual is here:
ALSA without PulseAudio and PipeWire
_https://dev1galaxy.org/viewtopic.php?id=6644

Last edited by igorzwx (2025-04-04 01:33:14)

Offline

#2 2025-07-19 23:15:35

igorzwx
Member
Registered: 2024-05-06
Posts: 228  

Re: Patching on the fly with "stream editor" (fftrate ALSA plugin)

Petrov's fftrate codec (if installed) can be set as default ALSA converter (resampler) in ALSA config:
defaults.pcm.rate_converter "fftrate" 

For example:

$ cat ~/.asoundrc
# ---------------------------------------------
#		Bluetooth Headphones
#		Configuration for default audio device
#----------------------------------------------

defaults.pcm.rate_converter "fftrate"

# Perform plug device
pcm.!default
{
	type	plug
	slave.pcm	"bluealsa"
	hint.description	"Default device"
}

Notice that the package "bluez-alsa-utils" does not provide any sort of "virtual sound card".
It means that you cannot configure a software mixer for bluealsa with arateconf
ALSA software mixer needs dmix, but it does not work with "virtual PCM devices" such as bluealsa

A BlueALSA PCM can only be opened by one process at a time. This can be inconvenient in many scenarios. For example, some audio applications keep the ALSA PCM device open, even when they are not actively streaming any audio, and so it is necessary to close each application before any other can use the device; desktop systems may like to emit system sounds while music is playing; etc.

ALSA provides a solution to this for hardware cards with the "dmix" plugin. That plugin allows multiple open connections, mixes the streams together, then sends the result as a single stream to the hardware device. Unfortunately dmix works as a front-end only with hardware (ie "hw" type) devices, and not with any other plugin types such as BlueALSA.

So it is not possible to configure BlueALSA as a backend device for dmix. We are forced to find an indirect method; that is, use a "hw" device that can forward the mixed stream on to a BlueALSA PCM. Fortunately, ALSA provides just such a device, the "Loopback" device, which is a kernel driver that implements a virtual sound card.

This wiki article describes one way that BlueALSA can be used with the ALSA Loopback device and the dmix plugin to achieve mixing of multiple audio streams into a single BlueALSA playback PCM.
_https://github-wiki-see.page/m/Arkq/bluez-alsa/wiki/Using-bluealsa-with-dmix

However, ALSA "Loopback" device (virtual sound card) can reduce sound quality.

See also:
_https://wiki.archlinux.org/title/Advanced_Linux_Sound_Architecture#High_quality_resampling
_https://wiki.archlinux.org/title/Bluetooth#ALSA
_https://manpages.debian.org/unstable/bluez-alsa-utils/bluealsa.8.en.html

bluealsa is a sort "virtual PCM device" (playback and capture)
_https://github.com/arkq/bluez-alsa

apt info bluez-alsa-utils
$ apt-file find /usr/bin/bluealsa
bluez-alsa-utils: /usr/bin/bluealsa       
bluez-alsa-utils: /usr/bin/bluealsa-aplay 

The default settings for bluealsa are enabled in ALSA config (if the package "bluez-alsa-utils" is installed):

$ cat /etc/alsa/conf.d/20-bluealsa.conf
# BlueALSA integration setup

# By default the predefined "bluealsa" PCM will use
# the most recently connected Bluetooth device.
defaults.bluealsa.device "00:00:00:00:00:00"
# Default to A2DP connection because that is what
# most people want to use - high quality audio.
defaults.bluealsa.profile "a2dp"
# By default allow BlueALSA to negotiate the "best"
# codec for each PCM.
defaults.bluealsa.codec "unchanged"
...
$ aplay -L | grep bluealsa
bluealsa 
alsamixer -D bluealsa

aplay -D bluealsa *.wav

BlueALSA also allows to capture audio from the connected Bluetooth device. To do so, one has to use the capture PCM device, e.g.:

arecord -D bluealsa -f s16_le -c 2 -r 48000 capture.wav 

_https://github.com/arkq/bluez-alsa

$ bluealsa-aplay -L
bluealsa:DEV=EC:66:D1:BF:02:05,PROFILE=a2dp,SRV=org.bluealsa
    Godess of Wisdom, trusted audio-headphones, playback
    A2DP (SBC): S16_LE 2 channels 48000 Hz

$ bluealsa-aplay -l
**** List of PLAYBACK Bluetooth Devices ****
hci0: EC:66:D1:BF:02:05 [Godess of Wisdom], trusted audio-headphones
  A2DP (SBC): S16_LE 2 channels 48000 Hz
**** List of CAPTURE Bluetooth Devices ****

Since the vast majority of Linux users are semi-deaf, semi-blind, and half-demented, Linux web browsers and media players usually have low quality resamlers with which they convert digital sound into a sort of digital crap. There are, however, few exceptions (e.g., Audacious).

If your bluetooth headphones supports only "S16_LE 2 channels 48000 Hz" audio format, you can take a wave or FLAC of CD format (or HiRes) and try to play it with a media player to see whether resampling is performed by the player or by ALSA (that is, by fftrate which is now the default).

$ file *.wav
test.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, stereo 44100 Hz

$ file *.flac
test.flac: FLAC audio bitstream data, 16 bit, stereo, 44.1 kHz, 9961896 samples

FFT is the fftrate codec (now the default ALSA converter/resampler)

$ aplay *.wav
[2492] D: bluealsa-pcm.c:1386: Getting BlueALSA PCM: PLAYBACK 00:00:00:00:00:00 a2dp
...
Playing WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
...
Input:  44100 Hz, 2 ch, 's16_le' (0x2): dummy = 0, period = 5512
Output: 48000 Hz, 2 ch, 's16_le' (0x2): dummy = 0, period = 6000
Rates:  44096 --> 48000 (J: 0,01%, T: FFT, W: Vorbis)
Ok.
...
$ audacious 2>&1
[5588] D: bluealsa-pcm.c:1386: Getting BlueALSA PCM: PLAYBACK 00:00:00:00:00:00 a2dp
...
Input:  44100 Hz, 2 ch, 's16_le' (0x2): dummy = 0, period = 2756
Output: 48000 Hz, 2 ch, 's16_le' (0x2): dummy = 0, period = 3000
Rates:  44096 --> 48000 (J: 0,01%, T: FFT, W: Vorbis)
Ok.
...
$ clapper 2>&1 *.flac
[6863] D: bluealsa-pcm.c:1386: Getting BlueALSA PCM: PLAYBACK 00:00:00:00:00:00 a2dp
...
Input:  44100 Hz, 2 ch, 's16_le' (0x2): dummy = 0, period = 441
Output: 48000 Hz, 2 ch, 's16_le' (0x2): dummy = 0, period = 480
Rates:  44100 --> 48000 (J: 0,00%, T: FFT, W: Vorbis)
Ok.
...
$ strawberry 2>&1 *.flac
[7285] D: bluealsa-pcm.c:1386: Getting BlueALSA PCM: PLAYBACK 00:00:00:00:00:00 a2dp
...
Input:  44100 Hz, 2 ch, 's16_le' (0x2): dummy = 0, period = 441
Output: 48000 Hz, 2 ch, 's16_le' (0x2): dummy = 0, period = 480
Rates:  44100 --> 48000 (J: 0,00%, T: FFT, W: Vorbis)
Ok.
...

dmix (with fftrate) makes the difference.

mpv on Devuan with ALSA software mixer (dmix) configured with Petrov's arateconf
(without pulseaudio and pipewire).
Soundcard iMic USB supports only 16bit 48kHz audio format.

pw.conf is a sort of pipewire config (it is not installed).

Bug#1038394: libpipewire
_https://groups.google.com/g/linux.debian.bugs.dist/c/JCDQBHGkxMY
_https://gitlab.archlinux.org/archlinux/packaging/packages/pipewire/-/issues/1

$ mpv 2>&1 *.mp4
 (+) Video --vid=1 (*) (h264 848x480 25.000fps)
 (+) Audio --aid=1 (*) (aac 2ch 44100Hz)
[W][33501.807636] pw.conf      | [          conf.c:  939 try_load_conf()] can't load config client.conf: No such file or directory
[E][33501.807661] pw.conf      | [          conf.c:  963 pw_conf_load_conf_for_context()] can't load default config client.conf: No such file or directory
Input:  44100 Hz, 2 ch, 's32_le' (0xa): dummy = 0, period = 1764
Output: 48000 Hz, 2 ch, 's16_le' (0x2): dummy = 0, period = 1920
Rates:  44100 --> 48000 (J: 0.00%, T: FFT, W: Vorbis)
Ok.

AO: [alsa] 44100Hz stereo 2ch float
VO: [gpu] 848x480 => 853x480 yuv420p
(Paused) AV: 00:00:17 / 00:10:49 (3%) A-V: -0.000 
$ celluloid 2>&1
[W][32816.655765] pw.conf      | [          conf.c:  939 try_load_conf()] can't load config client.conf: No such file or directory
[E][32816.655785] pw.conf      | [          conf.c:  963 pw_conf_load_conf_for_context()] can't load default config client.conf: No such file or directory
Input:  44100 Hz, 2 ch, 's32_le' (0xa): dummy = 0, period = 1764
Output: 48000 Hz, 2 ch, 's16_le' (0x2): dummy = 0, period = 1920
Rates:  44100 --> 48000 (J: 0.00%, T: FFT, W: Vorbis)
Ok. 
$ mediainfo *.mp4 | grep Audio -A9
Audio
ID                                       : 2
Format                                   : AAC LC
Format/Info                              : Advanced Audio Codec Low Complexity
Codec ID                                 : mp4a-40-2
Duration                                 : 10 min 49 s
Bit rate mode                            : Constant
Bit rate                                 : 128 kb/s
Channel(s)                               : 2 channels
Channel layout                           : L R
Sampling rate                            : 44.1 kHz
Frame rate                               : 43.066 FPS (1024 SPF)
Compression mode                         : Lossy
sudo apt install mediainfo

Last edited by igorzwx (2025-07-31 13:26:41)

Offline

#3 2025-07-20 01:59:07

ralph.ronnquist
Administrator
From: Battery Point, Tasmania, AUS
Registered: 2016-11-30
Posts: 1,462  

Re: Patching on the fly with "stream editor" (fftrate ALSA plugin)

Thanks @igorzwx.

Your technical prowess is quite impressive. Though I'd say your attitude and due respect for colleagues and present audience has significant room for improvement.

Online

#4 2025-07-20 03:49:03

igorzwx
Member
Registered: 2024-05-06
Posts: 228  

Re: Patching on the fly with "stream editor" (fftrate ALSA plugin)

off-topic

@ralph.ronnquist

Nobody is perfect. Though, it might be obvious that the so-called "technical prowess" is so impressive simply because Devuan wiki is abolished by Neo-Luddites and AI haters. That is why, perhaps, "elementary skills" may look like a sort of "prowess".

The credo of esoteric Neo-Luddism is rather simple: "Secular knowledge is useless". For example: "A wiki is useless" (and, perhaps, any secular books as well, because technical literature is often outdated, and all the truth is in the Holy Scriptures). Practical reason can easily be sacrificed in the name of ideology, strange beliefs or fears. Neo-Luddism, AI hate, and other sorts of ideological obsession might be seen as "natural symptoms" of cognitive decline and dementia.

bluealsa was tested on Linux Mint with systemd (without pulseaudio and pipewire).

On Devuan, one may need a SysVinit (init.d) script for BlueAlsa
_https://github.com/joe-skb7/bluealsa-sysvinit

mkdir sysVinit_bluealsa
cd sysVinit_bluealsa
 
git clone https://github.com/joe-skb7/bluealsa-sysvinit.git
$ ls
bluealsa-sysvinit
cd bluealsa-sysvinit
$ ls -1
bluealsa
README.md
$ cat bluealsa
#!/bin/sh

### BEGIN INIT INFO
# Provides:		bluealsa
# Default-Start:	2 3 4 5
# Default-Stop:		0 1 6
# Required-Start:	dbus $syslog $local_fs $remote_fs bluetooth
# Required-Stop:	dbus $syslog $local_fs $remote_fs
# Short-Description:	Bluealsa daemon
### END INIT INFO

. /lib/lsb/init-functions

NAME=bluealsa
DESC="Bluealsa daemon"
DAEMON=/usr/bin/$NAME
PIDFILE="/var/run/$NAME.pid"
COMMON_OPTS="--quiet --oknodo --pidfile $PIDFILE"
BA_OPTS="-p a2dp-source -p a2dp-sink"

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Read configuration variable file if it is present
[ -f /etc/default/bluez-alsa ] && . /etc/default/bluez-alsa

start() {
	log_daemon_msg "Starting $DESC" "$NAME"
	start-stop-daemon --start --background --make-pidfile $COMMON_OPTS \
			  --exec $DAEMON -- $BA_OPTS $OPTIONS
	log_end_msg $?
}

stop() {
	log_daemon_msg "Stopping $DESC" "$NAME"
	start-stop-daemon --stop $COMMON_OPTS --exec $DAEMON
	log_end_msg $?
}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart|force-reload)
		stop
		start
		;;
	status)
		status_of_proc -p $PIDFILE $DAEMON $NAME
		;;
	*)
		echo "Usage: $0 {start|stop|force-reload|restart|status}"
		exit 2
		;;
esac

3. Install and start sysvinit script:

# cp bluealsa /etc/init.d
# update-rc.d bluealsa defaults
# update-rc.d bluealsa enable
# service bluealsa start 

_https://github.com/joe-skb7/bluealsa-sysvinit

NOTE: To restart ALSA on Devuan with SysV-Init (default), one can use these commands:

$ sudo /etc/init.d/alsa-utils force-reload
Shutting down ALSA...done.
Setting up ALSA...done.

$ sudo service alsa-utils restart 
Shutting down ALSA...done.
Setting up ALSA...done.

$ sudo service alsa-utils force-reload
Shutting down ALSA...done.
Setting up ALSA...done.

Last edited by igorzwx (2025-07-24 00:01:01)

Offline

#5 2025-08-12 22:11:55

igorzwx
Member
Registered: 2024-05-06
Posts: 228  

Re: Patching on the fly with "stream editor" (fftrate ALSA plugin)

To change ALSA configs, one can use a simple toggle script (MATE Desktop):

#!/bin/bash

#  Description: Toggle script for MATE Desktop
#  FILE: /opt/scripts/toggle-alsa.sh

#  ALSA configs:
#  $HOME/.asoundrc-BT
#  $HOME/.asoundrc-HDA
#  Sound icon: /opt/scripts/sound.svg
#  Desktop Launcher: $HOME/.local/share/applications/toggle-alsa.desktop

TOGGLE=$HOME/.toggle

if [ ! -e $TOGGLE ]; then
    touch $TOGGLE    
    cp $HOME/.asoundrc-BT $HOME/.asoundrc 
	killall alsamixer -q
	mate-terminal -e 'alsamixer -D bluealsa' &   
    killall mate-notification-daemon -q
    notify-send "    BlueALSA Virtual PCM" --icon=/opt/scripts/sound.svg -t 2000
else
    rm $TOGGLE    
    cp $HOME/.asoundrc-HDA $HOME/.asoundrc 
	killall alsamixer -q
	mate-terminal -e 'alsamixer' &      
    killall mate-notification-daemon -q
    notify-send "    Intel HDA Codec (Motherboard)" --icon=/opt/scripts/sound.svg -t 2000
fi

Desktop Launcher:

$ cat $HOME/.local/share/applications/toggle-alsa.desktop
[Desktop Entry]
Version=1.0
Type=Application
Name=Toggle ALSA
Comment=
Icon=/opt/scripts/sound.svg
Keywords=audio;
Categories=AudioVideo;Mixer;Settings;HardwareSettings;
Exec=/opt/scripts/toggle-alsa.sh
StartupNotify=false
Terminal=false
NoDisplay=false

Last edited by igorzwx (2025-08-21 13:13:47)

Offline

#6 2025-08-12 22:53:02

greenjeans
Member
Registered: 2017-04-07
Posts: 1,113  
Website

Re: Patching on the fly with "stream editor" (fftrate ALSA plugin)

Since the vast majority of Linux users are semi-deaf, semi-blind, and half-demented,

Well some of them are obviously...

FYI: resampling either does nothing, or it ****'s your music up. Period.

All software processing tends to do the same, and the more you heap on, the worse it gets. Having a keyboard and a grasp of coding does not make a person an expert on sound. And bulls**t you read on the internet (and copy/paste on forums) is mostly just that, means nothing in the real world.

Simple rule-of-thumb: The less electronics and software between you and your music is directly proportional to the quality of your listening experience. The digital age is the worst thing that ever happened to the quality of music.


https://sourceforge.net/projects/vuu-do/ New Vuu-do isos uploaded August 2025!
Vuu-do GNU/Linux, minimal Devuan-based Openbox and Mate systems to build on. Also a max version for OB.
Devuan 5 mate-mini iso, pure Devuan, 100% no-vuu-do. wink Devuan 6 version also available for testing.
Please donate to support Devuan and init freedom! https://devuan.org/os/donate

Offline

#7 2025-08-12 23:21:58

igorzwx
Member
Registered: 2024-05-06
Posts: 228  

Re: Patching on the fly with "stream editor" (fftrate ALSA plugin)

The very fact that you are using ALSA is telling something about "the quality of your listening experience."
If you do not believe that you are semi-deaf, you can make a simple experiment.
Downsample a HiRes audio file 24bit 192KHz to 16bit 48kHz with Petrov's pcm_conv
_https://dev1galaxy.org/viewtopic.php?id=6644
Then check whether you hear the difference.

Last edited by igorzwx (2025-08-12 23:53:56)

Offline

#8 2025-08-13 01:38:45

greenjeans
Member
Registered: 2017-04-07
Posts: 1,113  
Website

Re: Patching on the fly with "stream editor" (fftrate ALSA plugin)

The very fact that you need to resort to a sort of strawman attack vis-a-vis of
accusing me (and half the entirety of the Linux user community) of having hearing loss,
basically signals that you don't have a leg to stand on, and must resort to logical
fallacies to try and support your argument. Even with "perfect hearing" no one perfectly
hears the alleged range of human hearing for 20-20k hz. That makes the subject itself
entirely subjective, any declarations of absolutes that this or that makes music "better",
are therefore nonsense, just as the idea that an individuals tastes in music are better or worser.

But still i'll humor you for the moment and your claims that my hearing (and half the Linux community),
is sub-par in some way (pretty presumptuous claim that).

My hearing though undoubtedly lessened in volume, is still quite accute after decades of
working in music. The legendary Tommy Ramone once said to me "I don't know how you made us
sound so good on that cheap PA system, but thank you!". That was during the South by Southwest
music festival in Austin one year, where I ran sound for 53 bands in 5 days.

I've installed sound systems in over 16,000 vehicles, boats, airplanes, homes, and businesses.
I have a rack of trophies for wins in audio competitions for sound quality. I was part of a team
that was IASCA grand national champions in sound for the 1001+ watts Pro class for several years
running. And not for nothing as they say, but I am a musician myself, and have put my time in
behind the PA as well as in front of it.

Everything you do electronically or via software, changes the music from what the artist intended
it to sound like, even small things like replaygain. I really dislike such attempts, Pulseaudio is
an excellent example of people flailing about with a keyboard and code and making things much worse.

I use alsa precisely because it doesn't do those things by default, it doesn't re-sample, and ffplay
doesn't either, allowing pass-through of the music somewhat less tampered with.

But people who have never heard pure analog, tend to think digital is somehow better, especially if they
do a ton of processing. But do yourself a favor, attend the symphony sometime, and actually listen to
what unprocessed real analog music sounds like, it will do you good. wink


https://sourceforge.net/projects/vuu-do/ New Vuu-do isos uploaded August 2025!
Vuu-do GNU/Linux, minimal Devuan-based Openbox and Mate systems to build on. Also a max version for OB.
Devuan 5 mate-mini iso, pure Devuan, 100% no-vuu-do. wink Devuan 6 version also available for testing.
Please donate to support Devuan and init freedom! https://devuan.org/os/donate

Offline

#9 2025-08-13 02:00:11

igorzwx
Member
Registered: 2024-05-06
Posts: 228  

Re: Patching on the fly with "stream editor" (fftrate ALSA plugin)

greenjeans wrote:

Even with "perfect hearing" no one perfectly hears the alleged range of human hearing for 20-20k hz.

It seems that you cannot understand the difference between frequency and sample rate (i.e., resolution), simply because both are measured in Hz. It might be a symptom of dementia.

Offline

#10 2025-08-13 03:24:16

golinux
Administrator
Registered: 2016-11-25
Posts: 3,523  

Re: Patching on the fly with "stream editor" (fftrate ALSA plugin)

And in you, igorzwx, a symptom of delusional arrogance on steroids. wink

Online

#11 2025-08-13 11:32:29

igorzwx
Member
Registered: 2024-05-06
Posts: 228  

Re: Patching on the fly with "stream editor" (fftrate ALSA plugin)

off-topic

golinux wrote:

a symptom of delusional arrogance on steroids

It is not so simple. Think of Trotskyist dialectics: arrogance is modesty, knowledge is ignorance, "war is peace, freedom is slavery, ignorance is strength" (Orwell, 1984).
_https://en.wikipedia.org/wiki/Homage_to_Catalonia
_https://en.prolewiki.org/wiki/Dialectics

Notice that the fftrate package provides:
the fftrate ALSA plugin,
pcm_conv (standalone FFT resampler/converter),
and pcm_mse, which is to measure the exactitude of resampling.
_https://dev1galaxy.org/viewtopic.php?id=6722

The method of measurement is very simple:
1. downsample a HiRes wave 32bit 192kHz to CD format (16bit 44100Hz)
2. upsample the result to 32bit 192kHz format,
3. measure the difference with the original wave.

So that, you can measure the exactitude of resampling, and you may try to hear the difference.

If you fail to hear the difference, you may try to think why Intel HDA codecs (motherboard) support 32bit (fixed) 192kHz audio format, and Apple's MacBooks support 32bit (float) 96kHz audio format.

Since "ignorance is strength", one may to try to explain to Apple's audio engineers that the CD format is more than enough. It may help to find out whether Apple's audio engineers are always very polite.

Last edited by igorzwx (2025-08-13 12:25:11)

Offline

#12 2025-08-13 16:09:42

greenjeans
Member
Registered: 2017-04-07
Posts: 1,113  
Website

Re: Patching on the fly with "stream editor" (fftrate ALSA plugin)

And in you, igorzwx, a symptom of delusional arrogance on steroids.

I'm starting to have a theory on this, hear me out: The real Igor died years ago, and some AI has taken over his personae. It would explain a lot. wink


https://sourceforge.net/projects/vuu-do/ New Vuu-do isos uploaded August 2025!
Vuu-do GNU/Linux, minimal Devuan-based Openbox and Mate systems to build on. Also a max version for OB.
Devuan 5 mate-mini iso, pure Devuan, 100% no-vuu-do. wink Devuan 6 version also available for testing.
Please donate to support Devuan and init freedom! https://devuan.org/os/donate

Offline

#13 2025-08-13 16:32:13

igorzwx
Member
Registered: 2024-05-06
Posts: 228  

Re: Patching on the fly with "stream editor" (fftrate ALSA plugin)

greenjeans wrote:

I'm starting to have a theory

It is the first symptom of "Vailala Madness". The next to come is "shaking and foaming from the mouth".

See: Schwimmer, E. (ed) (1976) F. E. Williams: The Vailala Madness and Other Essays. London: C. Hurst and Company;
and Worsley, P. (1968) The Trumpet Shall Sound, 2nd edition. London: Granada

Offline

#14 2025-08-13 19:27:26

greenjeans
Member
Registered: 2017-04-07
Posts: 1,113  
Website

Re: Patching on the fly with "stream editor" (fftrate ALSA plugin)

^^ I'm so sorry man, I had no idea. Are you seeing a doctor about it?


https://sourceforge.net/projects/vuu-do/ New Vuu-do isos uploaded August 2025!
Vuu-do GNU/Linux, minimal Devuan-based Openbox and Mate systems to build on. Also a max version for OB.
Devuan 5 mate-mini iso, pure Devuan, 100% no-vuu-do. wink Devuan 6 version also available for testing.
Please donate to support Devuan and init freedom! https://devuan.org/os/donate

Offline

#15 2025-08-13 20:30:21

igorzwx
Member
Registered: 2024-05-06
Posts: 228  

Re: Patching on the fly with "stream editor" (fftrate ALSA plugin)

It seems that you are missing the point (as usual). It is about your theory and your symptoms.

Do you still believe that frequency and sample rate are the same thing, because both are measured in Hz?

Last edited by igorzwx (2025-08-14 00:48:49)

Offline

#16 2025-08-13 23:49:29

greenjeans
Member
Registered: 2017-04-07
Posts: 1,113  
Website

Re: Patching on the fly with "stream editor" (fftrate ALSA plugin)

^^ *you're* wink


https://sourceforge.net/projects/vuu-do/ New Vuu-do isos uploaded August 2025!
Vuu-do GNU/Linux, minimal Devuan-based Openbox and Mate systems to build on. Also a max version for OB.
Devuan 5 mate-mini iso, pure Devuan, 100% no-vuu-do. wink Devuan 6 version also available for testing.
Please donate to support Devuan and init freedom! https://devuan.org/os/donate

Offline

#17 2025-08-14 02:29:22

igorzwx
Member
Registered: 2024-05-06
Posts: 228  

Re: Patching on the fly with "stream editor" (fftrate ALSA plugin)

greenjeans wrote:

Everything you do electronically or via software, changes the music from what the artist intended
it to sound like...
I use alsa precisely because it doesn't do those things by default, it doesn't re-sample...
But people who have never heard pure analog, tend to think digital is somehow better...

The problem is that resampling of digital audio is unavoidable simply because it is digital. Moreover, the semi-deaf artists tend to downsample their recordings to CD format with crappy resamplers. The mass production of "lossless digital crap" is a big business. It is about money. The naive, and the ignorant, and other slaves of "knowledge" seem to be victims of a global deception.

It seems that you believe that you are able to hear "pure (not re-sampled) digital audio". However, to become audible a digital audio file should be upsampled to infinite sample rate (that is, to analog). If you believe that frequency and sample rate are the same thing, you should not believe your ears when hearing "pure analog", because infinite frequency cannot be audible, and, therefore, "pure analog" cannot be better than "pure digital" (although, you seem to believe the opposite).

The genuine "pure analog" is better, of course. For the same reason, HiRes audio is better than that of CD format. The only problem is that ALSA users are not likely to hear the difference either because they are semi-deaf or because progressive dementia makes ALSA difficult to configure. To fix this problem, they created a theory that human beings cannot hear the difference between HiRes and CD format.

It is impossible to disable resampling in ALSA. You can only change the default resampler of ALSA. Since ALSA was designed for semi-deaf audiophiles, it does not permit "exclusive mode". ALSA seems to be unique in this sense. For example, OSS4 automatically enables "exclusive mode" for professional sound cards which have built-in hardware mixer. Otherwise, "exclusive mode" can be enabled in OSS4 config.

To state the obvious (which might be not so obvious for the demented), resampling is not a problem, if you do not hear the difference. Imagine you have a real-time codec, which is exact in an absolute sense. Make it default resampler/converter, and the problem is solved.

If you do not hear the difference, you may try to believe that the resampler is very exact. If you are a sort of unbeliever, you can measure the exactitude of resampling with Petrov's pcm_mse.
_https://dev1galaxy.org/viewtopic.php?id=6722
However, if you measure the exactitude of resampling, you may discover that you are semi-deaf.

Is it so difficult to compile fftrate? It should not be difficult, provided that you are not completely demented.

NOTE: Because of dementia, it might be difficult to understand how to configure the fftrate plugin. It is recommended to set the fftrate resampler to maximum sample rate supported by your sound card (or HDA codec), because it is likely to provide much better quality of resampling than the HW resampler of your sound card (or HDA codec). That is why, perhaps, there is a belief that the fftrate codec somehow improves the quality of audio files.

If you install the fftrate plugin and configure it correctly, you may have a chance to understand what ALSA really is.
If you are not completely deaf, you may notice the difference in sound quality.
If you are not completely demented, you may start to think what is so special about the fftrate plugin.

However, to achieve enlightenment, you have to think without attempting to create a theory, or other sort of mythology. Otherwise, it may result in "shaking and foaming from the mouth" (as it was described by Francis Williams and Peter Worsley).

Although there is a conspiracy theory that ALSA does not have a secret documentation, it might be a real challenge to understand how it works. The purpose of the fftrate ALSA plugin was to provide a sort of ersatz for "exclusive mode" which is not supported by ALSA.

NOTE: If you do not know what "exclusive mode" is, you may try it with foobar2000 on MacOS

brew install --cask foobar2000 
foobar2000 for Mac change log

2.24.6 released on 2025-07-06
...

2.5 released on 2023-04-26
...
Exclusive audio output support.

_https://www.foobar2000.org/changelog-mac

Notice, however, that Homebrew for MacOS is already infected with PulseAudio
_https://formulae.brew.sh/formula/pulseaudio
To prevent it from being installed, you have to add a secret esoteric command to your ~/.zshrc
One may find it in a "classified documentation":

export HOMEBREW_FORBIDDEN_FORMULAE="pulseaudio" 
export HOMEBREW_FORBIDDEN_CASKS="cask1 cask2"  # block installation of specific casks

export HOMEBREW_FORBIDDEN_FORMULAE="formula1 formula2"  # block installation of specific formulae

export HOMEBREW_FORBIDDEN_TAPS="username/repo"  # block installation from or adding specific taps

export HOMEBREW_ALLOWED_TAPS="homebrew/core"    # only allow install of packages from homebrew/core

Exclusive mode allows audio applications to take exclusive control of audio devices, bypassing the software mixer of sound system. It also implies that all sorts of software resampling and format conversion performed by the sound system are disabled. It means that audio formats, which are not supported by your sound card, cannot be played in "exclusive mode".

To find out which audio formats are supported by your Mac's built-in hardware DAC use the "Audio Midi Setup" app, which is located in the "Utilities" subfolder of your "Applications" folder.
_https://support.apple.com/en-gb/guide/audio-midi-setup/ams59f301fda/mac
You may need to convert your audio files to "96 kHz 32-bit Float" with Petrov's pcm_conv

However, it seems to be impossible to disable resampling in Foobar2000. The sound is always rather strange. Perhaps, Foobar2000 has a sort of pulseaudio inside, which downsamples everything to  44100Hz. One may presume that Foobar2000 is a very special player for those audiophiles who are not only demented but also deaf.

Perhaps, the only safe way is OSS4 with Audacious. When exclusive mode is enabled in the setting of its OSS4 plugin, Audacious does not play audio formats, which are not supported by sound card. Another option is "ossplay -R", but it can only play waves.

There is, of course, a secret esoteric theory of audio formats. Notice that Digital eXtreme Definition (DXD) usually implies an extreme resolution by time (sample rate 352.8 kHz), while 32-bit Float means an extreme resolution by amplitude.
_https://en.wikipedia.org/wiki/Digital_eXtreme_Definition
"What Is 32-Bit Float Audio, and Should You Record In It?"
_https://www.wired.com/story/32-bit-float-audio-explained/

Mac's built-in hardware DAC supports the following audio formats:
44.100 Hz 2 ch 32-bit Float
48.000 Hz 2 ch 32-bit Float
88.200 Hz 2 ch 32-bit Float
96.000 Hz 2 ch 32-bit Float

There is a reason why Apple's audio engineers chose "96 kHz 32-bit Float" as a sort of reference audio format.

One may try a sort of esoteric audio test:

1. Convert a DXD wave to Apple's reference audio format with Petrov's pcm_conv:

pcm_conv -f 96000 -b 32f -T fft -v DXD.wav 32bitFloat96kHz.wav

2. Set Mac's real-time codec (resampler/converter) to "96.000 Hz 2 ch 32-bit Float" audio format with the "Audio Midi Setup" app (which is located in the "Utilities" subfolder of "Applications" folder).
_https://support.apple.com/en-gb/guide/audio-midi-setup/ams59f301fda/mac

3. Play your 32bitFloat96kHz.wav on Mac with "Music" player (former iTunes).

If you are not completely deaf, you may notice something about audio quality.

If you need a reference DXD, try a sort of "2L Recordings".

NOTE: Such esoteric audio tests do not make any sense, if you do not trust your ears.

"God created man in his own image and likeness". Human ears and human eyes are divine instruments. It is not difficult to verify, if you trust your senses.

"Our senses are gifts from God". The slaves of cargo cult science can easily fool themselves simply because they do not trust their senses.

Feynman, Richard P. (June 1974). "Cargo Cult Science" (PDF). California Institute of Technology.
_http://calteches.library.caltech.edu/51/2/CargoCult.pdf
_https://ghostarchive.org/archive/20221009/http://calteches.library.caltech.edu/51/2/CargoCult.pdf
_https://paulsteinhardt.org/wp-content/uploads/2020/10/CargoCult.pdf

Feynman's emphasis on "to see if it worked" is an instruction to trust your senses, the gifts from God, which enable you to see and understand. This is the key point. Otherwise, Feynman's essay "Cargo Cult Science" is just another attempt to derive a true theory from a false assumption. If you refuse to trust your senses, you inevitably fall in the trap of Agrippa's trilemma (Agrippa the Skeptic)
_https://en.wikipedia.org/wiki/Agrippa_the_Skeptic
_https://en.wikipedia.org/wiki/M%C3%BCnchhausen_trilemma

NOTE: The idea that "If senses are not truthful, any knowledge cannot be justified" is a foundational concept in philosophy, particularly in epistemology, explored by thinkers like Plato and Descartes.
If ALSA is playing crap, do not trust your ears, and read Descartes.

Meditations on First Philosophy by Rene Descartes
_https://www.marxists.org/reference/archive/descartes/1639/meditations.htm

One may wonder what is the difference between Feynman's "method... for separating the ideas" and the method of trial and error invented in the Stone Age. It was a speech for those who know what he is speaking about. It was a commencement address for the initiated into the mystery of "physical intuition". It cannot be comprehended by the slaves of ALSA.

An assumption that an oscilloscope was not misused may not stand skepticism. If you do not know how to fool yourself with "scientific instruments", try to read Feynman's essay "Cargo Cult Science". One may try to believe that the mass production of "digital crap" is a sort of "fair trade".

If you do to trust your senses, you may notice that you are "missing something essential". For example, it may become obvious that "any purported justification of all knowledge must fail, because it must start from a position of no knowledge" _https://en.wikipedia.org/wiki/M%C3%BCnchhausen_trilemma
Such logical problems might be difficult to solve, but, in any case, the slaves of "knowledge" are not supposed to have their own knowledge, they have to conform to approved opinions and beliefs. They cannot possess own knowledge simply because they do not trust their senses and their ability to think. "A wiki is useless", if it is not approved.

Last edited by igorzwx (2025-08-26 12:07:19)

Offline

Board footer