Bonding Ethernet and Wireless interfaces for extra Speed & Reliability.

December 22, 2015

I recently moved home and now my home server needs to be situated in a different room than my router.  I tried running the server on wifi only but it was a bit frustrating despite using dual band router and dual band USB interface.  Speed is still nothing like gigabit ethernet and sometimes there were problems remounting nfs shares on resuming my desktop from sleep.  Next I tried a TP-Link Gigabit Powerline kit.  This is better but still very noticably slower than regular wired gigabit ethernet.  My next idea was to bond the Powerline ethernet and wireless ‘N’ interfaces in order to aggregate the interfaces for a speed boost and for fail over reliability.  This works!

Here’s the key: ignore almost all the examples and howtos you found on Google.  There are some very confusing and complicated and downright wrong explanations and examples out there.  I also suspect that some people just prefer to do it the hard way.

Anyway, here’s my set up and what worked for me:

My router gives me 4 Gigabit ethernet ports and dual band wifi.  The wifi is encrypted with WPA2 PSK (CCMP).  I have static addresses for my desktop and printer.  Other stuff gets an address via DHCP.

One Gigabit port is used to connect with a Powerline adapter.  Another port goes to my desktop and another to my printer/scanner.

My server runs Debian Jessie 8.2.  It is on another floor and is connected by ethernet to another Powerline adapter which is paired to the one at the router.  The server also has a USB dual band wireless adapter.  The wireless driver is in the standard Debian kernel and the firmware was available from a package in Debian’s non-free repo.

So, to get the network interfaces bonded I neeeded to install ifenslave and then reboot or restart networking service.

# apt-get install ifenslave && reboot

Next edit /etc/network/interfaces so it looks like this:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

## BONDING RR ###
allow-hotplug eth0
auto eth0
iface eth0 inet manual
bond-master bond0

allow-hotplug wlan1
auto wlan1
iface wlan1 inet manual
bond-master bond0
wpa-ssid “MY_SSID”
wpa-psk “MY_SECRET_KEY”
wireless-channel “36”

 
auto bond0
iface bond0 inet static
address 192.168.1.3
netmask 255.255.255.0
gateway 192.168.1.1
bond-mode 0
bond-miimon 100

 

Naturally you need to specify your own SSID and key and of course your own preferred IP address, netmask and gateway.  You might not need to specify the wireless channel.  I found it useful to do so in order to avoid using the more congested 2.4GHz band.

I specified a static address on the server but did not reserve an address on the router, which does the sane thing and allocates the address requested  by the server.  This works perfectly for me but may not work on a busier LAN.

I reboot.  It works!

Here’s the proof:

# ifconfig
bond0 Link encap:Ethernet HWaddr 00:1d:72:a0:dc:ed
inet addr:192.168.1.3 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::21d:72ff:fea0:dced/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:2436064 errors:0 dropped:2995 overruns:0 frame:0
TX packets:2438371 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1741347675 (1.6 GiB) TX bytes:4336225638 (4.0 GiB)

eth0 Link encap:Ethernet HWaddr 00:1d:72:a0:dc:ed
inet6 addr: fe80::21d:72ff:fea0:dced/64 Scope:Link
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:1213626 errors:0 dropped:0 overruns:0 frame:0
TX packets:582146 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:746352277 (711.7 MiB) TX bytes:2081911527 (1.9 GiB)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:528 errors:0 dropped:0 overruns:0 frame:0
TX packets:528 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:67546 (65.9 KiB) TX bytes:67546 (65.9 KiB)

wlan1 Link encap:Ethernet HWaddr 00:1d:72:a0:dc:ed
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:1222485 errors:0 dropped:0 overruns:0 frame:0
TX packets:1856282 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:994998751 (948.9 MiB) TX bytes:2254380081 (2.0 GiB)

 

 

MPD Stream lossless flac or wav

April 1, 2014

Modern networks are so fast and disk space so abundant and cheap that compressing a music collection to mp3, vorbis or similar now seems mostly pointless even for streaming, especially at home. Even away from home and streaming via ssh tunnels there is often no need for compression. I spent ages looking for a way to stream lossless audio and finally realised it was right under my nose and already running in the form of my mpd server. Lesson learned: Read The Fine Manual but don’t believe everything it says or assume it complete!

The mpd man page and typical example mpd.conf are out of date. For example mpd.conf states that streamed output must be vorbis or mp3. This is no longer the case. Run mpd –version to see a list of supported encoders. My mpd server (Debian Wheezy) shows:

Encoder plugins:
null vorbis lame wave flac

(If you compile mpd yourself you can include extra lossy encoders such as twolame, opus and shine).

so I set up my mpd server to stream lossless audio. If your audio collection is flac derived from CD (44100Hz 16-bit PCM with 2 channels) then you can use an output like this one:

audio_output {
type "httpd"
name "FLAC Stream"
encoder "flac"
port "8000"
format "44100:16:2"
}

(format must be defined for flac streams)

If you have a variety of formats and don’t want changes in bit depth or sample rate then you can choose to output to raw pcm wav like this:

audio_output {
type "httpd"
name "pcm wav Stream"
encoder "wave"
port "8000"
}

As this is raw (headerless) pcm some players won’t play it, or will require a format to be defined (sox’s play command is like this). Fortunately mplayer or mplayer2 will play back a raw pcm stream without issue. This means it integrates easily into your local alsa/pulse/jack setup, so you can direct the audio to any predefined software devices such as equalisers, crossfeeds, mixers, or direct to hardware devices such as USB DAC or onboard spdif and so on. Of course you can also use mplayer’s built in audio filters and/or numerous applications which have mplayer as a backend.

To play without stuttering or dropping out on track changes you can use something like:

mplayer -idle -cache 2048 your-mpd-host:8000

VLC will also play back these kinds of headerless streams.

On Android devices MPDroid supports streaming, and if you have an Android device with good multimedia support it might support both flac and raw pcm. My old (2010 vintage) Archos 43 and 28 Internet Tablets handle this really well and MPDroid passes the audio off to the devices’ DSP so it is relatively undemanding on the battery.

Debian Wheezy startx – it can work and here’s how:

March 26, 2013

I noted in https://takla.wordpress.com/2013/02/18/debian-wheezy-testing-with-xfce-on-the-eee-pc-1001p-everything-works/ that I’d had to change from using startx to using a display manager, and found it slightly annoying.  The difficulty arose because of a bug in upstream consolekit, see http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=597937

Fortunately it’s actually easy to fix.  It takes a minute, it works, and the fix will persist through upgrades.

As root create the file /usr/share/pam-configs/startx-fix
Name: ConsoleKit startx fix
Default: yes
Priority: 0
Session-Interactive-Only: yes
Session-Type: Additional
Session-Final:
optional pam_loginuid.so

save it and then run # dpkg-reconfigure libpam-runtime

Now you can uninstall the bloody awful lightdm or slim or whatever you’d got lumbered with.

When you next log-in use plain startx, not startxfce4 or similar session starter command. You find yourself are back in the world where doing the obvious and simplest thing actually works🙂

Debian Wheezy (testing) with Xfce on the Eee PC 1001P. Everything Works.

February 18, 2013

I’ve been running Debian Stable (Squeeze) on my Eee PC 1001P for about two years  (see https://takla.wordpress.com/2011/03/06/debian-on-asus-eee-pc-1001p) and noticed that Debian Testing (Wheezy) has been frozen for some time, meaning it’s now possible to move to the pending Wheezy release without any expectation of updates which produce unexpected behaviour or time sapping breakages.

Normally I’d simply dist-upgrade to the next version (my desktop has moved from Etch to Lenny to Squeeze to Wheezy this way) but in the case of my Eee PC I wanted to change from amd64 to i386.  The Eee PC has only 1GB of RAM and after doing some simple comparisons with some CPU intensive tasks (some command line gmic image smoothing and sharpening tasks – super CPU intensive) I found that the performance difference between i386 and amd64 on this hardware is quite tiny;  something like 5% quicker, or less.   The really noticeable differences are that amd64 uses more of that small amount of RAM, and also the multi-architecture support occupies a lot of disk space,  running apt-get update with multiple architecture support is really slow, and updates can be a lot bigger.  I don’t run wine but I do run GoogleEarth (works ok on amd64 but is simpler to build and quicker to run on i386) and I’d like to run some very old games (such as the original Cube shooter) which I never managed to get working via ia32 compatibility.  So i386 it is.

Install:

Installing Debian and  having everything work has become very simple on the Eee PC 1001P.  I used the Debian Live Xfce testing image available from http://live.debian.net/cdimage/release/next/i386/iso-hybrid/  and used dd to write it to a USB flash drive.   Before booting from USB you need to go into the Eee PC’s bios settings and set the boot device and also disable the boot booster (remember to re-enable the boot booster after you finish). I tried the live system, liked it and then rebooted and did a normal install using the graphical installer.  I kept my original /home partition and only formatted and overwrote / and swap.  There were no difficulties and nothing notable occurred.  Yawn.

Hardware Config:

All the hardware is supported and no non-free firmware or driver is required.  To ensure the screen backlight functions as expected, and to avoid an occasional IRQ issue (I think on resume from suspend)  you need to edit /etc/default/grub like so:

GRUB_CMDLINE_LINUX=”acpi_osi=Linux acpi_backlight=vendor irqpoll”

then as root “update-grub”.

If you installed using a USB stick or similar then edit /etc/fstab and remove any reference to it (probably it will show as /dev/sdb)  otherwise your removable devices will get mounted to /media/usb instead of /media.  Not a big problem, just a bit odd.

You can now uninstall the 486 kernel.  Keep the 686 version.

Now as root run ‘apt-get update && apt-get dist-upgrade’ to get the system up to date.

Install eeepc-acpi-scripts and laptop-mode-tools

Edit /etc/default/eeepc-acpi-scripts to show

PWR_CLOCK_AC=0
PWR_CLOCK_BATTERY=2
DEFAULT_SHENGINE_CONFIG=auto

There’s no need to edit anything else or to set up hdparm as described in my old post.  Current laptop-mode-tools  takes care of ths, so long as hdparm is installed (the default apt setting of recommends being enabled means it will arrive along with laptop-mode-tools).

That should be it as far as the hardware goes.  Reboot and eveything works, including the Super Hybrid Engine hardware button (top left above the keyboard) and its keyboard shortcut <Fn><Space>.  For an easy way to get the status of the S.H.E. put the following script in your path and make it executable:

#!/bin/bash

#script name: she
STATUS=”$(cat /sys/devices/platform/eeepc/cpufv)”
case $STATUS in
0x300) STATUS=Performance
;;
0x301) STATUS=Default
;;
0x302) STATUS=Powersave
;;
esac
echo “Super Hybrid Engine Status: “$STATUS””

exit 0

and when run in xterm it will give the S.H.E. status like so:

$ she
Super Hybrid Engine Status: Performance

or

$ she
Super Hybrid Engine Status: Default

or

$ she
Super Hybrid Engine Status: Powersave

When  you reboot you will want to add your usual applications and if you’re used to Xfce 4.6 or older you may need to reconfigure your panel and preferences.  Starting over might be an idea if upgrading.  There are some other changes:  Thunar in 4.8 finally has native browsing of Windows/Samba network shares so make sure you have the thunar vfs packages and backends;  thumbnailing is now handled by  tumbler, so install tumbler and tumbler-plugins-extra for nice thumbnails of your images, videos, pdfs etc.

One major change is that you almost certainly need to use a log-in manager in preference to a simple startx or startxfce4.  This is because more stuff like mounting file systems and authenticating various actions depends on console-kit.  I tried to continue with startxfce4 initiating console-kit but never managed to get it to work,  so now use lightdm with the gtk greeter.  It’s mildly annoying but in fact doesn’t add any significant time to the boot+log-in, or any load once the session is running.

The Webcam:

When I tried various live CDs and test installs on a small extra partition (Ubuntu 12.10, Debian Wheezy Gnome and similar) the webcam seemed to be broken/unsupported but it turns out the hardware is working fine, you just need some sane software that understands the extremely common uvcvideo device and the Eee PC’s built-in microphone.  I found that guvcview in the main Debian repo is ideal.  It’s a GTK viewer without any Gnome dependencies and it works perfectly with both video and sound.

Synaptics Touchpad

The touchpad’s multitouch is now properly supported (not emulated in software as in the past) with zero config in X but unfortunately Xfce 4.8’s mouse/touchpad config dialog hasn’t caught up yet, so I’m still using my own config in /etc/X11/xorg.conf

Section “InputClass”
Identifier      “Touchpad”                      # required
MatchIsTouchpad “yes”                           # required
Driver          “synaptics”                     # required
MatchDevicePath “/dev/input/event*”
Option          “MinSpeed”              “0.5”
Option          “MaxSpeed”              “1.0”
Option          “AccelFactor”           “0.075”
Option          “TapButton1”            “1”     # 1 finger tap
Option          “TapButton2”            “2”     # 2 finger tap: middleclick
Option          “TapButton3”            “3”     # 3 finger tap: right click
Option          “RTCornerButton”        “3”     # rightclick
Option          “LTCornerButton”        “2”     # middleclick
Option          “VertTwoFingerScroll”   “1”     # multitouch
Option          “HorizTwoFingerScroll”  “1”     # multitouch
Option          “LBCornerButton”        “8”     # browser “back” btn
Option          “RBCornerButton”        “9”     # browser “forward” btn
EndSection

Sound:

I’ve given up on Pulse Audio.  It is just hideous on this hardware, non stop crackles and interruptions.  Meanwhile ALSA works really well and is simple to set up and use.  I almost always use my Eee PC with In Ear Monitors so I prefer to use a crossfeed for less tiring listening.  I installed  bs2b-ladspa from the repos and then set up my ~/.asoundrc as follows:

defaults.pcm.rate_converter “samplerate_medium”
defaults.pcm.dmix.rate 44100

##default is output to bs2b meier type crossfeed
pcm.!default {
type plug
slave.pcm “bs2b”
}

pcm.bs2b {
type ladspa
slave.pcm “plug:dmix”
path “/usr/lib/ladspa/”
plugins [{
label bs2b
input {
controls [ 650 9.5 ]
}
}]
}

##use this to output without crossfeed
##i.e. mplayer -ao alsa:device=speakers
pcm.speakers {
type plug
slave.pcm “dmix”
}

This sets my sound to run through a Meier type crossfeed by default, with an option to have it bypass the crossfeed if I want to output to speakers.  The Eee PC’s hardware  supports sample rates from 44100 to 192000 Hz.  Good quality resampling is very CPU intensive so I set the default to 44100, so 99% of the music out there doesn’t need to be resampled so there is almost zero load.

Most modern video, especially HD, has audio with higher sample rates, typically 48000/96000/192000, so when watching video I use mplayer2 with the audio bypassing the software alsa mixer entirely.  This keeps the load off the CPU so it’s fine to watch 720p from a  network share via wifi.  MPlayer runs the audio through a crossfeed before sending it to the hardware mixer:  “mplayer -af ladspa=/usr/lib/ladspa/bs2b.so:bs2b:650:9.5 -ao alsa:device=hw=0.0”  Using the hardware mixer does block any other app or process from using the sound but that doesn’t seem like a big deal on a small personal machine like this.  If you like to simultaneously watch video, listen to music, talk on VOIP and watch youtube then don’t use the hardware mixer…..and maybe get yourself a more powerful laptop too.   This is all scripted of course, so it’s automated according to file type when clicking on a file in Thunar.  Yes, Thunar’s custom action facility is still superb!

One change in Thunar that caught me out is that if your custom actions call scripts/binaries in your ~/bin instead of system binaries/executables then the full path must be specified in the Thunar config dialog.  Once this is done it all works as before.

I now have a very nice i386 install with Xfce 4.8.  All the hardware works including the webcam,  wireless, ethernet, USB ports, special buttons, Super Hybrid Engine and so on.  It boots to a nice looking composited desktop very quickly and while requiring less than 100 MB RAM.  That includes automatically starting a Tilda instance, policykit authentication, network manager,  and having dispcalGUI apply a monitor profile so I have a colour managed desktop as far as is possible.  Compared to Debian Squeeze I find that Wheezy+Xfce has better hardware support (it is complete as far as I can tell), an incrementally improved desktop environment which remains familiar, and is more efficient.  This is very impressive indeed.

Bash Video Thumbnailer

September 1, 2012

Video thumbnail: a montage of screenshots from a video file, often accompanied by some file info.  Like this:

I wasn’t satisfied with the thumbnailers I had tried for a few reasons:

  • usually incredibly slow
  • work with some files/formats but not others
  • usually don’t understand anamorphic video and make shots with bad aspect ratio
  • often require X and a graphical desktop

So I decided to make my own bash script, videothumbs, that:

  • is quicker than the stuff I already tried
  • works with every video codec and container that my OS supports
  • gets the damn aspect ratio right!
  • works on headless or non-gui systems

And here it is: http://pastebin.com/x96WYVTx

20 March 2013: New version at http://pastebin.com/2iVWDEkx now makes all thumbs with ffmpeg as changes in newer versions of mplayer and some containers caused problems.

As you can see from the image above (click for full size), videothumbs creates an image identically named as the input file except for the file extension, 1024 pixels wide with 4 columns of 10 images.  At the top is some basic file info: file name, video codec and dimensions, audio codec and number of channels.

There is only one user option -o

“videothumbs -o  path  mymovie.mkv”

to have the thumbnail image output to path instead of the same directory as mymovie.mkv.

It uses mplayer or ffmpeg (depending on file type) to grab/create the images and imagemagick’s montage command to make the thumbnail sheet.  It’s quickest with files in Matroska (.mkv) or .mpg/.mpeg  containers.  MPlayer grabs uncompressed png frames really quickly from mkv or mpg but can choke seeking to a specific point in avi files (I think because a position specified in seconds doesn’t always correspond to a keyframe) and on some mp4 files (I don’t know why).  So, for everything that isn’t in mkv/mpg, videothumbs falls back to using ffmpeg to create the images.  This is slower, but still better than hanging….  For a quick comparison I booted Windows XP and made a thumbnail sheet using Media Player Classic: it took absolutely ages and was much slower than my script.

I’ve tested videothumbs on the following containers:

mkv, mp4, avi, vob, wmv, mov, divx, mpg

which contained various codecs:

video: h264, divx/xvid, wmv3, Sorenson Media Video 3 (Apple QuickTime), mpeg2 (DVD), ogv, ogg

audio: aac, ac3, dts, mp3, ogg vorbis, mp2, ima4 (Quicktime)

and probably some others too.  So far everything worked.  YMMV.  I’m running Debian Stable (Squeeze) with (proper) ffmpeg and mplayer from the unofficial deb-multimedia.org repositories.  I have no idea if this script will work with libav as it does with ffmpeg.

ffmpeg autocrop bash script function

June 1, 2012

This ffmpeg auto crop function is derived from this mplayer based script from the mplayer mailing lists in 2005 http://lists.mplayerhq.hu/pipermail/mplayer-users/2005-November/056636.html

My one differs a little.  It runs cropdetect with a 2x rounding because I only encode with  x264 which doesn’t require the ‘divisible by 16’ dimensions of older encoders (in theory there is an efficiency penalty with x264 like with the old divx/xvid encoders, but in practice the penalty is so tiny as to be effectively non-existent) and it always crops an extra 2 pixels from each side because it’s so usual for DVDs/vobs/rips to have a picture which has line of slightly different luminosity at one or more borders that the human eye sees easily but isn’t detected at all by cropdetect algorithms (and yes I’m the kind of person who runs mplayer with -noborder for manual crop detection so my eye is not tricked by edge effects).

http://pastebin.com/n8Jk3DjS

It works as a stand alone script or you can just drop it as a function in to your own script and use the crop value it produces (usual mplayer/mencoder/ffmpeg  w:h:x:y syntax).

 

 

Automatically convert tracks or entire directories to Ogg, MP3, Flac, M4A (Nero or FAAC), with tags.

May 26, 2012

Edit: New version uses multiple parallel processes for huge performance gain on dual/multicore processor systems, and on single core systems it’s recommended to run the new version with “PROCESSES=2” (see below) for proportionately similar benefit.

foma:  [f]lac [o]gg [m]p3 [a]ac

foma will convert any audio track (or the audio track from a video file) to any of Ogg Vorbis, MP3, Flac, or M4A.  It writes the tags to the new files.  You can choose to convert the files in situ, or to output them to a different directory.  It never overwrites any audio file.  If you input files it will convert the files ; if you input a directory it will create a new identically named directory (either as a nested subdirectory, or to your specified output destination) and then find and convert all the contained audio files to the new directory, writing the metadata and also an extended .m3u playlist, and copy over any images.  Optionally it will then run replaygain on the new directory.  foma can handle multiple files or directories, or a mix of files and directories, as input.  It’s very easy to use as a simple command,  or as an -exec or -execdir find command, or as  file manager context menu item/custom action.

Original foma: http://pastebin.com/Ctyz2uWa

Updated for multicore: http://pastebin.com/jC3Nhj8F

This is also usable for single core machines: change “PROCESSES=5” to “PROCESSES=2”.  If you do only want one process running then use the original script.

foma decodes with ffmpeg,  so you can convert audio from any file that ffmpeg understands.

It encodes using flac, oggenc,  lame,  faac or neroaacenc.

It tags using metaflac, vorbiscomment,  (m)id3v2, neroaactag/mp4tags.

It runs replaygain using metaflac, vorbisgain, mp3gain or aacgain.

It writes an extended m3u playlist using just ffmpeg’s metadata output and some shell commands.

After completing a directory conversion foma can automatically update your mpd library.

foma never overwrites your existing audio or image files (it will overwrite .m3u files).  If any target conversions already exist then they are skipped and a log appended to ~/foma.log.

foma script is short, modular and well commented so you can easily understand what it does and why.  It’s simple to add,  remove or modify encoders or taggers.  For example you might prefer to completely remove calls to Nero’s proprietary tools, or perhaps  add musepack or wavpack encoding and tagging.

Q: Why not just use ffmpeg without calling external encoders?

A: ffmpeg is great for decoding audio and grabbing metadata but it doesn’t support all encoders, or all the options of each supported encoder, and it can have trouble writing tags with some formats.  For example my installed version of ffmpeg loses all metadata at the writing stage on converting from ogg (libvorbis) to m4a (libfaac), though flac to m4a works fine.  With some formats you might find that writing  some metadata fields you want to use is unsupported and the data has been discarded.

I also want to strip replaygain data when converting to a lossy format because almost every lossy codec slightly raises the levels*.  Not only does this render the copied replaygain data inaccurate,  on a few tracks this will take a brickwall loudness mix into clipping.

By using ffmpeg to decode to PCM WAV then it’s possible to use any encoder that can read from STDIN or a named pipe. In this case it means neroAacEnc is scripted for automated/batch conversions but you could just as well do the same with whatever new encoder comes along, or with other encoders which are unsupported or incompletely supported in free software operating systems (ape and tak come to mind).

Q: Isn’t this an awful lot slower than just using ffmpeg or oggenc or whatever?

edit: following was for the original script.  foma is now massively faster than ffmpeg or oggenc or any other script or application which doesn’t run multiple parallel decode/encode processes.

A: Even with the extra metadata handling this script completes (on my 32-bit Debian stable system) almost as quickly as performing the same conversion with the ffmpeg binary; the time penalty is only about 5%).  I was also surprised to find that this script can be faster than the K.I.S.S**  solution, for example `oggenc -q 4 file.flac` is slower than `foma file.flac` every time.   ***On a less positive note if I perform the same conversion on the same machine running Windows XP SP3 32-bit using foobar2k as a frontend for oggenc.exe then the conversion takes only about 70% of the time as ffmpeg in Debian (edit:  I had another look at this and foobar achives its good performance by running two processes in parallel;  the Windows oggenc binaries don’t really perform any differently to those compiled using GCC, so the following sentence is redundant).  It may finally be time to head over to http://funroll-loops.info  or http://www.microsoft.com and bow down before the power of the teenagers||greysuits…..

*The only lossy format I’ve encountered which has no effect on the levels is lossy/hybrid wavpack but for compatibility and convenience reasons it’s not a codec I use for lossy compression.

**UNIX mantra: Keep It Simple, Stupid!

***No longer true.  New foma with parallel processes now easily outperforms other methods in Debian and in Windows XP.

Automatically create extm3u (extended .m3u) playlist in GNU/Linux

May 22, 2012

I couldn’t find a satisfactory command line method to create extended .m3u playlists in Debian.  The best is a perl script extm3u.pl which you can find at http://www.splitbrain.org/projects/extm3u.  It’s really good and very quick but only supports mp3, ogg and flac files.  I modified it to also support mp4/m4a and submitted a patch but the author wasn’t interested enough to respond.  In any case I want a tool that will support numerous audio formats so I wrote a bash script which uses normal GNU utilities such as awk and bc along with ffprobe (part of ffmpeg) and consequently can write an extended .m3u for any files that (your installed version of)  ffmpeg supports. The script can be found at http://pastebin.com/wPXZuPrU

20 March 2013: New version at http://pastebin.com/dfifNv3z supports opus codec files and has a fix for problem with wrong track duration (introduced by recent changes in ffmpeg/ffprobe)
21 April 2014: New version at same link as above, now works with locales which use , for decimal divider. Thanks to Tina Keil.

22 December 2015: updated version at same link http://pastebin.com/dfifNv3z to support relative paths, thanks to Dave.

9 January 2016 removed problematic relative paths function.

I’ll just post the usage/options here so you can see what it does (it isn’t complicated):

USAGE:
bashplaylist [options] {-o out} <directory>

OPTIONS:
-p  writes the file names in .m3u with full path
(default is simple file name without path)

-r  recurses through subdirectories and writes file names with
full path

-o <output directory>  (default is target directory)

bashplaylist finds the audio files in the directory, parses
the metadata, then writes an extended .m3u playlist

bashplaylist understands the same files as  your
installed version of ffmpeg.

If bashplaylist fails please check output directory exists
and is writeable.

#june 07 2012 edited script to remove unwanted / in regex which prevented ogg files from being parsed

Debian GNU/Linux: Split Lossless Audio with Cue

May 1, 2012

I wanted the simplest possible way to split cue+lossless into individual flacs, all named and tagged from the cue file.  There are some good scripts out there but I really don’t want to have to remember anything at all in terms of options and I don’t want any output format other than flac.  I’ve written a small script that does exactly what I want.

It detects cue sheet character encoding and if it’s anything other than UTF-8 it automatically writes a new UTF-8 cue sheet so that the final file names and tags retain their diacritic marks and non-Latin characters.

It discards unwanted pregap output.

It works well with find so it’s easy to use it recursively and/or for multiple cue+lossless files.  It works equally well as a file manager context menu entry and will run fine without needing a terminal.  This is a nice feature for Thunar custom actions.

It doesn’t modify, overwrite or delete existing files.

It works with any lossless file supported by shntool, which means just about anything.

It’s short  and simple so easily modified if desired.

This is a happy feeling non-judgemental script:  there are no options or settings or configuration files so if it doesn’t work it probably isn’t your fault, leaving you free to relax and move onto doing something else.

It’s as easy to use as `cue2flacs my_cuesheet.cue`

or

`find <path> -iname “*.cue” -execdir cue2flacs “{}” \+`

or

`for i in *.cue ; do cue2flacs “$i” ; done`

http://pastebin.com/NFQxEtug

edit:  an improved version of this script is at http://pastebin.com/pL63AQSr

The improvement is in detection of character encoding which is vastly better now due to using python-chardet, so writing a new utf8 cue sheet should work every time now.


				

ALSA Equalizer & Crossfeed on Debian Stable (Squeeze)

January 22, 2012

This is for ALSA, and is not suitable for systems using pulseaudio.

The aim:
to have a real time, audio equalizer (optionally systemwide if preferred)

to have high quality crossfeed to enhance playback with headphones

to have the option to use the above with all apps (systemwide) and otherwise to be able to choose or toggle the eq and crossfeed on/off when using mpd or mplayer.

What is needed:
ALSA uses plugins via an API called LADSPA. The Debian package swh-plugins contains a good LADSPA equalizer plugin, mbeq. A very nice crossfeed DSP, bs2b-ladspa, is available. The best real time controller for the equalizer is alsaequal, which isn’t in Debian Squeeze but is very easy to build (it’s available in Debian Testing/Wheezy).

Install mbeq, bs2b, and anything necessary to build alsaequal:

# apt-get install build-essential caps libasound2-dev libasound2-plugins bs2b-ladspa swh-plugins

Obtain alsaequal:

$ wget http://www.thedigitalmachine.net/tools/alsaequal-0.6.tar.bz2

Build alsaequal:
This only takes a minute.
Unpack alsaequal-0.6.tar.bz2 and after cd into alsaequal:
$ make
# make install

Create a suitable ~/.asoundrc:
The following ~/.asoundrc assumes use of the default soundcard with dmix as the default mixer because on 99% of systems this is how ALSA is automatically set up. If you have multiple sound cards and want to set one as default this can be done by editing /etc/modprobe.d/alsa-base.conf. For example I have an integrated hda-intel card and a USB card and I want the USB card to be the default sound device. In /etc/modprobe.d/alsa-base.conf I created the lines:

# Make usb audio the default card
options snd slots=snd-usb-audio,snd-hda-intel

So now the USB device driver always loads first on boot and the USB device is always the default. The integrated intel card is still available if I want to use it.

Back to the ~/.asoundrc

# eq controller
ctl.equal {
type equal
library "/usr/lib/ladspa/mbeq_1197.so"
module "mbeq"
}

#eq plug passes output to dmix – no crossfeed
pcm.equal {
type plug
slave.pcm plugequal
}
pcm.plugequal {
type equal
slave.pcm “plug:dmix”
library “/usr/lib/ladspa/mbeq_1197.so”
module “mbeq”
}

#eq plug passes output to crossfeed
pcm.plugequal2 {
type equal
slave.pcm crossfeed
library “/usr/lib/ladspa/mbeq_1197.so”
module “mbeq”
}
pcm.equal2{
type plug
slave.pcm plugequal2
}

#crossfeed outputs to dmix
pcm.crossfeed {
type plug
slave.pcm “bs2b”
}
pcm.bs2b {
type ladspa
slave.pcm “plug:dmix”
path “/usr/lib/ladspa/”
plugins [{
label bs2b
input {
controls [ 650 9.5 ]
}
}]
}

This has created several devices: an equalizer, a means to control the equalizer’s settings in real time, and a crossfeed based on Jan Meier’s famous crossfeed hardware (the dmix device already exists and is defined in /usr/share/alsa/pcm/dmix.conf – there is no need to touch it). There are two ways to access the equalizer: one passes the equalized output directly to dmix, and the other passes it to the crossfeed device, after which the crossfeed passes its output to the dmix mixer device. The mixer in this example is plug:dmix which can accept and mix multiple audio sources and is enabled automatically in any modern ALSA system. If you want every sound from all applications passed through the eq then change

pcm.equal {
to
pcm.!default {

Configure MPD’s outputs:
If you set the eq systemwide then you can remove the third output device from the following mpdconf example.

I run mpd under my own user name and my ~/.mpdconf contains the following audio outputs:

audio_output {
type "alsa"
name "My ALSA Device"
auto_resample "no"
mixer_device "default" # optional
mixer_control "PCM" # optional
}
audio_output {
type "alsa"
name "bs2b"
device "crossfeed"
auto_resample "no"
mixer_control "PCM"
mixer_device "default"
}
audio_output {
type "alsa"
name "Eq"
device "equal"
auto_resample "no"
mixer_control "PCM"
mixer_device "default"
}
audio_output {
type "alsa"
name "EQ+bs2b"
device "equal2"
auto_resample "no"
mixer_control "PCM"
mixer_device "default"
}

This allows me to toggle mpd output between the following states:

No Eq, no crossfeed
Crossfeed, no Eq
Eq, no crossfeed
Eq + crossfeed

Restart alsa and mpd so the changes can take effect:

# alsa force-reload && /etc/init.d/mpd restart

Configure the Equalizer:
This is easily done in a terminal using alsamixer, which is already installed as part of ALSA. So play some music using mpd with one of the equalizer outputs (or mplayer-ao alsa:device=equal ) if you’re using pcm.equal { then you can do

$ alsamixer -D equal

and if you’re using Eq systemwide with pcm.!default { then play audio with any app and you need only do

$ alsamixer

and now you can use the Eq sliders and hear the effect. When you’re happy with it and want to save the settings so they always take effect on boot you can run:

# alsactl store

MPlayer:
Now for the best way to use mplayer with both crossfeed and the configured equalizer. MPlayer has its own meier crossfeed so use this and then pass the audio to the ALSA ‘equal’ device just created and configured:

mplayer -af bs2b=profile=jmeier -ao alsa:device=equal

Alias for convenience:
On my playback system I don’t use any Eq with my speakers or my old Sennheiser Hi-Fi headphones but it’s very useful to add a little extra bass for use with my Sony studio monitor headphones, so they sound more like a Hi-Fi headphone and a little less like a slightly lightweight and sterile monitor. I have the above command aliased as mplayer-headphones in ~/.bash_aliases:

#use meier crossfeed emulation for headphones
alias mplayer-headphones='mplayer -af bs2b=profile=jmeier -ao alsa:device=equal'

Of course if you have set up Eq systemwide then you need only do:

mplayer -af bs2b=profile=jmeier

So there it is: high quality Eq and/or Meier-like crossfeed available to mplayer, mpd and clients, and (if you prefer) to any app which produces sound.

Resource useage:
On my system (Athlon64 4050e dual core 2.0Ghz running 32-bit Debian) running mpd and alsa with crossfeed and eq uses about 4% more CPU than without either, which is to say that CPU useage goes from 1% to 5% when no samplerate conversion is required. A similar change, 4 or 5 percentage points difference, is seen when samplerate conversion is required i.e. 48000Hz audio resampled to my system default 44100Hz using libsamplerate “samplerate_medium”.