0

I have a set of stereo .AIFF piano samples from http://theremin.music.uiowa.edu/MISpiano.html

Each sample is preceded by ~5 sec silence, and fades into ~30 seconds of silence; i.e. it continues well below the threshold of my hearing.

I wish to trim both ends. This will involve fading out, so as to avoid a sharp discontinuity.

Furthermore I am only interested in the left channel.

How can I accomplish this from my OS X terminal?

π

PS hold your horses, I'm going to answer this one myself :)

P i
  • 29,020
  • 36
  • 159
  • 267

1 Answers1

1

Here we go:

for filePath in IN/*.aiff
do
    # Trim silence both ends
    #   http://digitalcardboard.com/blog/2009/08/25/the-sox-of-silence/
    ./sox $filePath ./TMP/1_trim.wav silence 1 0.1 1%  1 0.1 0.5%

    # LEFT channel
    #   https://www.nesono.com/node/275
    ./sox TMP/1_trim.wav ./TMP/2_mono.wav remix 1


    # Get length (seconds)
    #   http://stackoverflow.com/questions/4534372/get-length-of-wav-from-sox-output
    #     file_length=`./sox ./TMP/2_mono.wav 2>&1 -n stat | grep Length | cut -d : -f 2 | cut -f 1`
    file_length=`./soxi -D ./TMP/2_mono.wav`

    # amount to truncate
    trunc=$(echo "$file_length*0.75" | bc -l)

    #   http://stackoverflow.com/questions/965053/extract-filename-and-extension-in-bash
   filename=$(basename "$filePath")

    # fade out
    #   http://www.benmcdowell.com/blog/2012/01/29/batch-processing-audio-file-cleanup-with-sox/
    ./sox ./TMP/2_mono.wav ./OUT/$filename fade t 0 $file_length $trunc
done
P i
  • 29,020
  • 36
  • 159
  • 267
  • I have the same samples and the same task. I wanted a little more fidelity on the lead in and out, this worked great: sox Piano.mf.A3.aiff Piano.mf.A3.trim.wav silence 1 1 .1% 1 1 .1%. Thanks for the answer! – RealBlueSky Mar 09 '14 at 19:23
  • Do upvote the question if it was helpful, there is some idiot trying to close it. Too many idiots pressing buttons on this site :| – P i Mar 09 '14 at 20:08