mardi 20 novembre 2018

Normalize a bunch of audio files to the same loudness

I had a bunch of audio files in a directory, each recorded live with different devices, and it proved very ear-painful to ear same in a row because of the difference of loudness.

For this purpose you can find a number of tool working with ID3 tags, but after testing with vlc, mplayer, and the pogo mp3 player it did not produce a measurable change. So I converted everything to wav, normalized the wav files, then converted back to mp3.

delete funny chars and spaces in file names

detox music_dir

converting files to wav is just a matter of

for f in $(ls); do ffmpeg -i $f $(basename $f .mp3).wav; done

normalizing files with the normalize-audio program, from the debian package of the same name.

normalize-audio *

converting back to mp3

for f in $(ls); do ffmpeg -b:a 192k -acodec libmp3lame -i $f $(basename $f .wav).mp3; done

dimanche 2 septembre 2018

Test if your microphone input is working from the command line on Linux

arecord -vv /dev/null

That's it. Now clap your hand and observe the ascii vumeter.

mercredi 25 juillet 2018

Inspecting an Atari ST hard disk image with Unix / Linux tools

GNU libparted has Atari partition table support since two years ago. For this you will need the disktype and parted programs. Any good Unix should have those (I use Debian GNU/Linux)

Let us try this with a disk image I used for my Ultrasatan device, for example st_mint
Unzip the disk image
 Inspect the diskimage with the disktype program, an excellent disk analysis tool.
disktype st_mint-0.7.img

--- st_mint-0.7.img
Regular file, size 600 MiB (629145600 bytes)
ATARI ST partition map
Partition 1: 128.0 MiB (134201344 bytes, 262112 sectors from 4, bootable)
  Type "BGM" (Big GEMDOS)
  FAT16 file system (hints score 3 of 5, ATARI ST bootable)
    Unusual sector size 4096 bytes
    Volume size 127.9 MiB (134119424 bytes, 16372 clusters of 8 KiB)
Partition 2: 384.0 MiB (402666496 bytes, 786458 sectors from 262116)
  Type "MIX" (Unknown)

Notice the two partitions, first one is of type BGM, the second one is a Minix partition.

Print the partition table parted (this will output some warnings if running as non-root)
parted st_mint-0.7.img print
Partition Table: atari
Disk Flags: 

Number  Start  End    Size   Type     File system  Flags
 1      2048B  134MB  134MB  primary               boot
 2      134MB  537MB  403MB  primary

 Print the partition table with the begin and end of each partition being printed in bytes we will need this to create the loopback devices
parted  st_mint-0.7.img -- unit b print
Partition Table: atari
Disk Flags: 

Number  Start       End         Size        Type     File system  Flags
 1      2048B       134203391B  134201344B  primary               boot
 2      134203392B  536869887B  402666496B  primary

 Now using the beginning and end of each partition in bytes from the line above, create the /dev/loop devices corresponding to each partition:
sudo losetup --find --offset 2048 --sizelimit 134201344 --verbose st_mint-0.7.img

This should give a loopback device
losetup --all
/dev/loop3: []: (/home/manu/Téléchargements/st_mint-0.7.img), offset 2048, sizelimit 134201344
Now let us do a file check on the partition
sudo fsck.vfat /dev/loop3 
fsck.fat 4.1 (2017-01-24)
/dev/loop3: 217 files, 966/16372 clusters
and mount it
sudo mount /dev/loop3 /mnt

looks an Atari ST system inside
ls /mnt
file /mnt/APPS/QED/QED.APP 
/mnt/APPS/QED/QED.APP: Atari ST M68K contiguous executable (txt=189972, dat=16234, bss=103214, sym=0)

when your work is finished, unmount the partition and detach the loop device from the disk image
sudo umount /mnt
sudo losetup --detach /dev/loop3 

vendredi 20 juillet 2018

Generating a visual history of a git repo

If you haven't met it yet the gource programm really rocks: it generates a OpenGL rendered graph of all the commits of a git project.

You can see the video on real time just by calling the command gource in your git repo, or generate a video of it by piping to ffmpeg

This is the command line I used to generate my own video:

gource --hide filenames --hide files --title "the history of pmc" -s 0.1 --highlight-users -1280x720 -o - | ffmpeg -y -r 60 -f image2pipe -vcodec ppm -i - -vcodec libx264 -preset ultrafast -pix_fmt yuv420p -crf 1 -threads 0 -bf 0 gource.mp4

lundi 26 juin 2017

Java DOM from XML is not namespace aware by default

Something which costed me a couple of headaches using getElementsByTagNameNS with a DocumentBuilderFactory from the java.xml.parsers package.

You find in the class properties:

    private boolean namespaceAware = false;

and I thought XML namespaces where the bread and butter of XML ...

So when building a DOM from an XML document you need to change the defaults of the factory like:

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = factory.newDocumentBuilder();

vendredi 23 juin 2017

Shell looping vs xargs

For a very long time I was using the following construct to execute a command on foo, bar, and baz (all typed into an interactive shell prompt)

for F in foo bar baz; do command $F ; done

Now I finally got the -n option of xargs (or --max-args if you're using GNU) which limits to number of parameters to pass to the next command. So i can replace the previous command with:

echo foo bar baz | xargs -n 1 command

Here the -n option tells xargs to give at max one parameter to proceed, and create a new command with the next parameter.

As a bonus, instead of constructing an array of numbers with

seq 1 10

don't forget bash and zsh brace expansion


vendredi 16 juin 2017

Tomcat7 not starting after Jessie->Stretch ugrade

I was wondering why the tomcat7 debian package would not start after the upgrade.

systemctl status tomcat7 output would look quite OK

systemctl status tomcat7
● tomcat7.service - LSB: Start Tomcat.
   Loaded: loaded (/etc/init.d/tomcat7; generated; vendor preset: enabled)
   Active: active (exited) since Fri 2017-06-16 10:10:34 CEST; 29min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 536 ExecStart=/etc/init.d/tomcat7 start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/tomcat7.service

Jun 16 10:10:34 new-ada systemd[1]: Starting LSB: Start Tomcat....
Jun 16 10:10:34 new-ada systemd[1]: Started LSB: Start Tomcat..
Jun 16 10:10:34 new-ada tomcat7[536]: Starting Tomcat servlet engine: tomcat7start-stop-dae…tory)
Jun 16 10:10:34 new-ada tomcat7[536]:  (already running).
Hint: Some lines were ellipsized, use -l to show in full.

But not java process was created

pgrep -lf java
echo $?

so something was obviously wrong.

But the devil is in the details, can you see this truncated line ?

Jun 16 10:10:34 new-ada tomcat7[536]: Starting Tomcat servlet engine: tomcat7start-stop-dae…tory)

If you run it in full with systemctl status -l tomcat7 it expends to

Jun 16 10:10:34 new-ada tomcat7[536]: Starting Tomcat servlet engine: tomcat7start-stop-daemon: unable to stat /usr/lib/jvm/java-7-openjdk-amd64//bin/java (No such file or directory)

Now I get it, the upgrade removed the openjdk-7-jre-headless package.Time to switch to openjdk8 ! The package openjdk-8-jre-headless was already installed, so I justed needed to set JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/ in /etc/default/tomcat7

Note for the future:

  • Why was this package removed ?
  • Should I configure the systemctl status to show ellipsized lined by default ?