Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Help with shntool ! (Read 11296 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Help with shntool !

This is what I want to achieve:

I want shntool to output a cuesheet with automatic placement of tracks of a given length, using an existing WAV file.
I was playing with it and I was able to split the WAV file itself in slices of 1:00 minute each, but it gave me several files. What I want is the same thing but output to a cuesheet. Any help from the non-unix and unix experts will be appreciated!

Help with shntool !

Reply #1
I don't know how to do that automatically, but if you had started typing into a text editor, you'd be done by now!

If you want to do that with a 1000 minute file, I suppose you could use a spreadsheet to increment the times, and save-as a text file (and rename to .CUE).

Help with shntool !

Reply #2
I'm thinking about a bash script....

Help with shntool !

Reply #3
You were on the right track. shntool's cue sheet generator needs separate files as input, so splitting was the right thing to do.
  • shntool split -q -l 1:00 "audio.wav"
  • shntool cue split-track*.wav > audio.cue
  • del split-track*.wav

You could combine the first two commands into one:
  • shntool split -q -l 1:00 "audio.wav" && shntool cue split-track*.wav > audio.cue

I'm not sure if you can do the del after that on the same line. Anyone?

If you needed to do it with an MP3 instead of a lossless source, then this is how I'd do it:
  • Load the MP3 in mp3DirectCut.
  • Special > Auto Cue (Shift+Ctrl+A).
  • Enter 1:00 when prompted.
  • Special > Save Cue Sheet and edit with Notepad.
  • In the cue sheet, change MP3 to WAVE and change FILE to point to the .wav (and make whatever other edits you need).
  • Close mp3DirectCut without saving, and delete the MP3.

Help with shntool !

Reply #4
Quote
I'm not sure if you can do the del after that on the same line. Anyone?


I just did it... (I'm on Linux so that could explain if Windows didn't let you?)


shntool split -q -l 1:00 "policy.wav" && shntool cue split-track*.wav > policy.cue && rm split-track*.wav

Now the issue is... to rename the "joined.wav" FILE statement within the cuesheet to inherit the intended WAV filename!

Help with shntool !

Reply #5
Well, I am going to try to write down a kind of algorithm here so anyone could help me with a bash script... invoked from KDE or GNOME right-click menu "Open With ThisScript..."

- When clicking on the file "thisfile.wav" and opening the context menu and choosing "Open With ThisScript..." would start the script PROCESSING the selected file (not any just .wav in the directory, which will contain many .wav files)

1) The script first needs to grab the file name and store it on a variable ("thisfile.wav")
2) Then shntool must process the file just like the line in the post above....

Quote
shntool split -l 1:00 $WAVFILE && shntool cue split-track*.wav > $WAVFILE.cue && rm split-track*.wav


3) and as a last part, a tool should replace the automatic "joined.wav" FILE statemente within the cuesheet, using the $WAVFILE instead.


So it will end with two files:
thisfile.wav
thisfile.cue  (and inside the cuesheet we would have "thisfile.wav" as the FILE statement)

(it occurred to me that the generated name would be thisfile.wav.cue, so the script should also treat this, removing the ".wav" from it)

Help with shntool !

Reply #6
Right, you didn't say what OS, so I assumed Windows.
rename the "joined.wav" FILE statement within the cuesheet to inherit the intended WAV filename!

Either of these should do:
  • sed 's#joined\.wav#policy\.wav#' policy.cue > policy-fixed.cue && mv -f policy-fixed.cue policy.cue
  • sed -i .bak 's#joined\.wav#policy\.wav#' policy.cue && rm policy.cue.bak

Someone else will have to script-ify it for you.

Help with shntool !

Reply #7
I kind of figured how to make bash process the file, however my problem now is with sed, which can't interpret $1 as a variable, I am sure missing something! Any help appreciated!

Code: [Select]
#!/usr/bin/env bash

shntool split -l 5:00 $1
shntool cue split-track*.wav > $1.cue
rm split-track*.wav

sed 's#joined\.wav#$1\.wav#' $1.cue > $1-fixed.cue
mv -f $1-fixed.cue $1.cue

Help with shntool !

Reply #8
Simple quotes prevent variable names from being interpreted, use double quotes instead, ie :

Code: [Select]
sed "s#joined\.wav#$1\.wav#" $1.cue > $1-fixed.cue
Opus 96 kb/s (Android) / Vorbis -q5 (PC) / WavPack -hhx6m (Archive)

Help with shntool !

Reply #9
Thanks dutch109...

Code: [Select]
#!/usr/bin/env bash

shntool split -l 5:00 $1
shntool cue split-track*.wav > $1.cue
rm split-track*.wav

sed "s#joined.wav#$1#" $1.cue > $1-fixed.cue
mv -f $1-fixed.cue $1.cue


Now sed is working nicely, thanks for the tip. The FILE statement is returning the proper original name.
But the final result keeps generating:

album.wav
album.wav.cue


I believe I would have to insert a variable to handle the .wav extension in this case.
Any ideas?

Help with shntool !

Reply #10
You can remove the extension with something like this :
Code: [Select]
file_without_ext="${1%\.wav}"


Also instead of creating a new file with sed, you can make your modifications in place with the i option :
Code: [Select]
sed -i "s#joined.wav#$1#" $1.cue
Opus 96 kb/s (Android) / Vorbis -q5 (PC) / WavPack -hhx6m (Archive)

Help with shntool !

Reply #11
Thanks again dutch109...

Now it's working fully...
Code: [Select]
#!/usr/bin/env bash

shntool split -l 5:00 $1
shntool cue split-track*.wav > $1.cue
rm split-track*.wav

sed -i "s#joined.wav#$1#" $1.cue

audiofilename="${1%\.wav}"
mv -f $1.cue $audiofilename.cue

Help with shntool !

Reply #12
OK, I thought of integrating more goodies into this script, like insert a fixed "TITLE Speech on Whales" before the INDEXES statements, within the cuesheet. Any thoughts on how to do this? Perhaps a "PERFORMER" statement right after the TITLE statement would be good too. These fields will be fixed initially fixed but if I can get to have TITLE Part 1, TITLE Part 2, that would be ideal.

K3B is accepting the cuesheet very charmly.

Help with shntool !

Reply #13
Mhh, you can try something like this (that will preserve indentation in the cue file) :

Code: [Select]
sed -i "s/^\([ \t]*\)\(INDEX 01.*\)$/\1\2\n\1TITLE Title 1\n\1PERFORMER Performer/" cuesheet.cue
sed -i "s/^\([ \t]*\)\(INDEX 02.*\)$/\1\2\n\1TITLE Title 2\n\1PERFORMER Performer/" cuesheet.cue
etc.

When your bash scripts get over 200-300 lines, think about switching to another scripting language like Python, it's a lot more powerful and easier to maintain than bash.
Opus 96 kb/s (Android) / Vorbis -q5 (PC) / WavPack -hhx6m (Archive)

Help with shntool !

Reply #14
OK, there seems to be a problem when you record MONO speeches and save  them as MONO, because shntool won't process "non CD-Quality" files, and it considers a "CD-Quality" file, only a stereo file. So I have incremented the use of SoX in the script. The SoX job is to create a new stereo file, based on the readings of the mono file. As far as it goes, it processes FLAC perfectly, and curiously, the output file size is just only one or three megabytes bigger than the original mono file (can somebody please explain this particular case to me? - because I re-saved the new stereo file within Audacity as FLAC and I got much more megabytes, using the same compression level) - after SoX doing its thing, shntool now can properly create the cuesheet, and K3B can burn it smoothly the mono file through this cuesheet.

Code: [Select]
#!/usr/bin/env bash

sox -S $1 -c 2 stereo-$1
shntool split -l 1:00 stereo-$1
shntool cue split-track*.wav > $1.cue
rm split-track*.wav
rm stereo-$1

sed -i "s#joined.wav#$1#" $1.cue

audiofilename="${1%\.flac}"
mv -f $1.cue $audiofilename.cue

Help with shntool !

Reply #15
I'm having a problem with the script... $1 is handling the whole path instead of just the local directory filename (when outside the script directory or from within KDE or GNOME file managers). Any ideas on how to workaround this?


Help with shntool !

Reply #17
thanks klonuo...

I followed some guidelines and I got most of things working now....

Code: [Select]
#!/usr/bin/env bash

FULLPATH=`dirname $0`
FILE=`basename $1`
FILENOEXT=`basename $1 .flac`

sox -S -V $FULLPATH/$FILE -c 2 $FULLPATH/stereo.wav

shntool split -l 5:00 $FULLPATH/stereo.wav -d $FULLPATH

shntool cue $FULLPATH/split-track*.wav >> $FULLPATH/$FILENOEXT.cue

rm $FULLPATH/split-track*.wav
rm $FULLPATH/stereo.wav

sed -i "s#joined.wav#$FILE#" $FULLPATH/$FILENOEXT.cue

Help with shntool !

Reply #18
The reason a mono file comes out not very much bigger than a stereo one is because FLAC supports joint stereo. Stereo audio can be represented as simple left & right channels (LR or "simple" stereo), or it can be stored as a mid (sum) channel and a side (difference) channel instead (this is MS or "mid-side" stereo). Mono or near-mono content in a stereo stream can be stored much more efficiently using mid-side stereo because the side channel is very quiet, if not silent. FLAC, I think depending on what encoding parameters you use, can pick whichever option saves more space as it encodes each block.

Help with shntool !

Reply #19
mjb2006, thanks for the explanation. That certainly makes sense.

I can think that SoX is creating a new flac with joint-stereo as default, whereas Audacity is saving as simple stereo!

Help with shntool !

Reply #20
I can think that SoX is creating a new flac with joint-stereo as default, whereas Audacity is saving as simple stereo!

Most likely it's beeing caused by Audacity applying dither, which adds uncorrelated noise to the channels. I am no expert for Audacity, but there is a switch to disable dithering.

Help with shntool !

Reply #21
Thanks TBeck, I am going to check that.

Help with shntool !

Reply #22
Interesting data:

-rw-r--r-- 1 linuxuser linuxuser  98M 2011-08-21 22:16 source-file.flac  (MONO)
-rw-r--r-- 1 linuxuser linuxuser  98M 2011-08-23 20:16 stereo-aud-nodither-at-all.flac
-rw-r--r-- 1 linuxuser linuxuser 124M 2011-08-23 20:10 stereo-aud-dither.flac
-rw-r--r-- 1 linuxuser linuxuser 117M 2011-08-23 20:06 stereo-sox-dither.flac
-rw-r--r-- 1 linuxuser linuxuser  98M 2011-08-23 20:25 stereo-sox-nodither.flac


SoX did dither the source file.
Audacity by default dithered it too, made it bigger.
When having the options to never dither at all, Audacity renders same filesize for a stereo version.

So most likely this resides on type of dithering.

Help with shntool !

Reply #23
Well...my further tests reveal that, as long as the audio file resides inside the script directory, it will be fine. But if you call the audiofile from any other location, the script fails... any help would be appreciated. I believe that basename and dirname are not doing their job...

Help with shntool !

Reply #24
In this new version, the program behaves as expected when in command line.
You can browse any directory and start the command (inside the bin path).
I removed some unnecessary things. However still no success in having the script to call over the FLAC file from the right path in Dolphin or Nautilus, associating the command in the context menu.

Code: [Select]
#!/usr/bin/env bash

FILE=`basename $1`
FILENOEXT=`basename $1 .flac`

sox -S -V $FILE -c 2 stereo.wav

shntool split -l 5:00 stereo.wav

shntool cue split-track*.wav >> $FILENOEXT.cue

rm split-track*.wav
rm stereo.wav

sed -i "s#joined.wav#$FILE#" $FILENOEXT.cue