Saturday, 27 August 2011

How to slow down a guitar solo with free software on Ubuntu Linux

In my spare time, I like to play guitar. I also enjoy learning guitar solos the "hard way" - by working out the notes, slurs, slides, bends, taps, mutes and harmonics by ear. However, some solos -- no matter how many times you listen to them -- are just too fast to "reverse engineer" as your brain just isn't able to distinguish between individual notes. If you simply slow down the solo, you'll be able to hear the individual notes, but you'll be changing the pitch of the notes such that a C4 or "middle C" might sound like a B4. That's not much help as the music will sound different. What we need is a way to slow down the notes, but retain their original pitch.

Since I run Ubuntu Linux, I have access to a true "Embarrassment of Riches" when it comes to free and high quality music software. This post outlines some of the methods I've found to slow down guitar solos using different tools.

So, if you're wanting to get to grips with a particularly frantic Severed Fifth solo, this might be a good place to start.

Aside

For those who think I'm slightly mad adopting "the hard way", bear in mind that an important skill for a musician is a good ear; learning to hear if you guitar is in tune, or being able to name an interval just by listening to it, bending a note up by a precise number of semi-tones. These are all extremely useful but difficult skills to acquire without lots of practice. So, what better way to learn that to really listen to masters of their art? Further, by analysing a solo, you gain an insight into how a professional guitarist writes a solo and moves around the neck.

Added to which, some guitar tab books out there are just plain wrong. The tab is either hugely simplified, or instructs you to play the piece at a different neck position, or the transcriber maybe based the tab on a different recording to the official one, et cetera. Whatever the reason, some books include solos that deviate (potentially significantly) from the original recorded performance version. I'd rather stick to the original.


Audacity

Audacity is an awesome (albeit -- sorry to have to say this -- not particularly pretty :) sound editor which is very easy to use. Since most people have used simple editors like this before, we'll start here. The process is simple:


  1. Install audacity if you don't already have it:
    $ sudo apt-get install audacity
  2. Load your sound file (Audacity will auto-convert all the usual formats automatically (.ogg, .mp3, etc).
  3. Select the start and end of the guitar solo by clicking on the blue wave form at the start of the solo and dragging until the end.
    Select the solo section in Audacity.

  4. Click Effect -> Change Tempo.
  5. Specify a value to change the tempo by (it should be a negative number to slow down the solo).
  6. Click Preview to ensure you're happy with the speed.
  7. Specify the tempo change in Audacity.
  8. Click OK.
I generally find that a value of between "-20" and "-30" works pretty well but you'll need to experiment with the preview, particularly if you're trying to learn something like a Van Halen solo!



MPlayer

Being somewhat of a Command-line Warrior by choice, I wondered about the process for accomplishing the same goal without a GUI. As it turns out, it's not that tricky...

MPlayer is an incredible movie player which has more options than gcc (which is saying something!) However, it doesn't need a movie to play - you can just feed it some music:

  1. Install mplayer if you don't already have it:
    $ sudo apt-get install mplayer
    
  2. Work out where the solo starts by playing the sound file with mplayer and noting the time. Thankfully, mplayer shows you the time offset as it plays the sample. For example:

    $ mplayer file.ogg
    Starting playback...
    A:  96.9 (01:36.9) of 250.0 (04:10.0)  0.3%
    

    Here, we see mplayer playing a sample at time 1 minute, 36.9 seconds.

  3. Obtain the solo end time using the same technique. Remember you can use the left and right arrow keys to skip back/forwards 10 seconds by default. If you'd rather be able to seek backwards and forwards by 1 second, you can do this:
    mkdir -p ~/.mplayer
    cat ~/.mplayer/input.conf <<EOT
    RIGHT seek +1
    LEFT seek -1
    EOT
    
    Run "man mplayer" for more details.
  4. Play the sample applying an audio filter to slow it down whilst retaining pitch:
    $ mplayer -af scaletempo -speed 0.6 solo.ogg
    



Rubberband

This is another command-line method. "Rubberband" also provides a LADSPA plugin for advanced usage. However, let's keep it simple:

  1. Install the rubberband command and ffmpeg:
    $ sudo apt-get install rubberband-cli ffmpeg
  2. Convert your sound file to .wav format (required for rubberband):
    $ ffmpeg -i file.mp3 /tmp/file.wav
  3. Rubberband the file (you might need to play with that 0.6 value):
    $ rubberband -T 0.6 /tmp/file.wav /tmp/slow.wav
  4. Play the file with any sound player:
    $ audacity /tmp/slow.wav
Run "man rubberband" for more details.

Play It Slowly

This is the simplest method I've found if you're happy to use a GUI. It's a perfect tool for the busy guitarist:

  1. Install "Play It Slowly":
    $ sudo apt-get install playitslowly
  2. Run it, specifying the file you want to use:
    $ playitslowly foo.mp3
  3. Click "Play"
  4. Tweak the "Start Position" and "End Position" sliders until you've got them aligned with the start and end of the solo respectively.
  5. Adjust the "Speed" slider to some value less than 1.0. Try 0.6 initially.
Play It Slowly keeps the process simple.
What's great about Play It Slowly is that not only does it understand most sound file formats, but you can listen to the solo and vary the speed (without affecting the pitch) dynamically - just move the slider as the music plays!

Taking it Further

If you want even more control, you'll need to consider one of the "big guns" of Linux audio such as:

These are incredibly powerful pieces of software. You'll also want to become familiar with the LADSPA system of plugins which all of the above support.

However, be warned that unless you're used to pro audio systems, the learning curve for these applications can be pretty steep...but very much worth the climb! :-)

Happy listening, learning and playing!

    Thursday, 25 August 2011

    Diff two files ignoring certain fields (like timestamps)

    This is a useful trick to avoid creating lots of intermediate temporary files when you're trying to compare two files that are almost the same, but which have some fields which are guaranteed to be different. Classic examples of this are two log files that have almost the same data in them, but where every line in these files is prefixed by a pesky timestamp which is different between the two files. bash process substitution (using named pipes) to the rescue! Let's assume we have two files "file1.log" and "file2.log" and the first six space-separated fields comprise a timestamp. To ignore those fields and just diff the log file contents we can do this:

    $ diff <(cut -d" " -f7- /tmp/file1.log) <(cut -d" " -f7- /tmp/file2.log)
    
    But why limit yourself to a textual diff. Go graphical if you prefer:
    $ meld <(cut -d" " -f7- /tmp/file1.log) <(cut -d" " -f7- /tmp/file2.log)
    
    This technique can be employed in other ways. Imagine you're working with a VCS / SCM tool such as bazaar. Here's how you can interactively edit a file whilst comparing it against the latest committed version in the branch or repository using vim's diff mode:
    $ vim -d src/foo.c <(bzr cat src/foo.c)
    

    Wednesday, 24 August 2011

    how to use bash lists to time a group of commands

    How do you run multiple commands in bash and calculate the total time taken to run all the commands? Use a list by surrounding the commands with curly braces:

    time { sleep 2; uptime; true && date; }

    The tricky bit is remembering to add that last semi-colon - without it, the command will fail to be parsed by bash. Also, the spaces either side of the curly braces are mandatory.

    Starting terminals in tmux in particular directories

    I've found a way to tweak my ~/.tmux.conf to create a terminals in particular directories:
    
    # start a window in $HOME/foo and call it "bar"
    set-option default-path "$HOME/foo"
    neww -n bar
    
    # another terminal in a different directory
    set-option default-path "/var/cache/weird"
    neww -n weird
    
    # revert to default for any further windows
    set-option default-path "$HOME"
    



    quick terminal reset

    Amazing how many people don't know this skool technique to reset a corrupted terminal:

    ^jstty sane^j


    Note - you don't press return/enter at all and those are CONTROL+j combos at either end.