Gamingforce Interactive Forums
85239 35211

Go Back   Exploding Garrmondo Weiner Interactive Swiss Army Penis > Garrmondo Music and Trading > Behind the Music
Register FAQ GFWiki Community Donate Arcade ChocoJournal Calendar

Notices

Welcome to the Exploding Garrmondo Weiner Interactive Swiss Army Penis.
GFF is a community of gaming and music enthusiasts. We have a team of dedicated moderators, constant member-organized activities, and plenty of custom features, including our unique journal system. If this is your first visit, be sure to check out the FAQ or our GFWiki. You will have to register before you can post. Membership is completely free (and gets rid of the pesky advertisement unit underneath this message).


MAC-flake transcoding scripts
Reply
 
Thread Tools
LiquidAcid
Chocorific


Member 6745

Level 38.97

May 2006


Reply With Quote
Old Aug 1, 2007, 08:29 AM Local time: Aug 1, 2007, 02:29 PM #1 of 1
MAC-flake transcoding scripts

Hi there,

when downloading lossless albums copies from the ed2k I often notice that these copies are encoded with the Monkey's Audio (APE) codec. My problem was that MAC isn't well supported on Linux (BSD, Unix, etc.) because the license isn't GPL and the author doesn't seem to interested in having a broad support of operating systems.

So in the past I always transcoded the APE file to wave via foobar2k (run through wine) and after that processing the WAVs with flac-1.1.2. Since flac-1.1.4 came out I wanted to test it but the package wasn't marked stable in my distribution (gentoo linux). I knew however that the Windows binary was stable and wrote some scripts for automatic encoding with verification and so on (also using wine). The tagging was done manually with foobar2k (I often change the style of tags, because I have my own system).

Now I had some free time and I was rather unsatisfied with the use of closed source software to transcode the music. So I decided to look for alternatives.

I found the flake compressor which encodes to FLAC, but better than the reference 1.1.4 encoder. Sadly it doesn't have a verification mode. The next thing was to get some MAC decoding tool.
I found JMAC, a MAC decoding (and encoding) tool that was implemented in Java. I wrapped some (tiny) bash script around it so I could use it for decoding.

Now the problem was that the lossless copies always came with just one large APE file and the corresponding cuesheet indicating the start- and endpoints of the track. I already had the possibility to decode from APE to WAV, only splitting was the problem.

For this I use the cuetools together with shntool, some general audio tool first written for use with the shorten codec.

Now here the scripts:

mac_decode.sh
Code:
#!/bin/sh

if [[ -n "$1" && -n "$2" ]]; then
        /usr/bin/java -jar /usr/local/lib/jmac-1.74/distributables/jmac.jar d "$1" "$2"

        if [ $? -ne 0 ]; then
                echo "mac: decoding error in file $1"
                exit 1
        fi
fi
A really tiny script that check for correct parameters and passes them to jmac. For this you need to download the jmac package and put it into the right paths on your system. Not much work.


flac_encode.sh
Code:
#!/bin/sh

OUT_NAME=$(/usr/bin/basename "$1" ".wav")
DIR_NAME=$(/usr/bin/dirname "$1")
FILE_NAME="$DIR_NAME/$OUT_NAME.flac"

# encode wave file to flac with flake compressor
/usr/local/bin/flake -12 "$1" -o "$FILE_NAME" &> /dev/null

if [ $? -ne 0 ]; then
        echo error while compressing
        /bin/rm -f "$FILE_NAME"
        exit 1
else
        TMP_NAME=$(/bin/mktemp) || exit 2

        # decode flake output with reference decompressor
        /usr/bin/flac --decode --silent -f -o "$TMP_NAME" "$FILE_NAME"

        # compare data
        /usr/bin/cmp --silent "$1" "$TMP_NAME"

        # check for error
        if [ $? -ne 0 ]; then
                echo error while verifying
                /bin/rm -f "$FILE_NAME" "$TMP_NAME"
                exit 3
        fi

        # remove temporary files
        /bin/rm -f "$TMP_NAME"
fi
Does encode from WAV to FLAC using the flake compressor (version from SVN). Does a verification process afterwards using the flac-1.1.4 reference decoder and does a full comparison with the original WAV data. Could replace this by a MD5 check, but since encoding is only done once...


mac_transcode.sh
Code:
#!/bin/sh

# expects a cue file

if [ -n "$1" ]; then

        BASE=$(/usr/bin/basename "$1" ".cue")
        DIR=$(/usr/bin/dirname "$1")

        cd "$DIR"

        TMPFILE=$(/bin/mktemp)
        if [ $? -ne 0 ]; then
                echo "couldn't create temporary file"
                exit 2
        fi

        echo "$TMPFILE"

        /usr/local/bin/mac_decode.sh "$BASE.ape" "$TMPFILE"

        if [ $? -ne 0 ]; then
                echo 'error while decoding ape file to wave data'
                /bin/rm -f "$TMPFILE"
                exit 3
        fi

        /usr/bin/cuebreakpoints --append-gaps "$BASE.cue" | /usr/bin/shntool split -o wav -n "track-" "$TMPFILE"
        /bin/rm -f "$TMPFILE"

        if [ $? -ne 0 ]; then
                echo 'error while splitting wave data with cue sheet'
                exit 4
        fi

        /usr/bin/find . -type f -and -name "track-*.wav" -exec bash -c '/usr/local/bin/flac_encode.sh "${0}" && /bin/rm -f "${0}"' {} \;

        if [ $? -ne 0 ]; then
                echo 'error while converting splitted wave data to flac'
                exit 5
        fi

else

        echo 'you have to specifiy a cue sheet file'
        exit 1

fi
transcoding script from MAC to FLAC. You supply the cuesheet name and the script should do the transcoding. Script depends on the standard naming:
Some very good lossless score.ape
Some very good lossless score.cue

I finished writing the scripts yesterday and tested them with the 2 disc Prometheus Cutthroat Island release and they produce identical results when using foobar2k.

Only thing that is lacking is maybe the transfer of the tags. Since I do this manually (see above) I don't intend to write anything for that. Could be easily done with apetag and metaflac.

EDIT:
1) The jmac decoder could be easily exchanged with the mac-port tool floating around on the net. It was taken down from sf.net by the author, so I don't know if there are some legal problems. Maybe mac-port is facter when decoding, but I'm not sure. At least jmac works for me.
2) The destination codec can also be easily exchanged if someone wants to encode to TAK, which should give much better compression ratio than flac with nearly same decompression speed.

Jam it back in, in the dark.

Last edited by LiquidAcid; Aug 1, 2007 at 08:35 AM.
Reply


Exploding Garrmondo Weiner Interactive Swiss Army Penis > Garrmondo Music and Trading > Behind the Music > MAC-flake transcoding scripts

Forum Jump


All times are GMT -5. The time now is 12:38 AM.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2024, vBulletin Solutions, Inc.