The officially official Devuan Forum!

You are not logged in.

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

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

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

Board footer