From 93f975db15e56a1a423c40d65e1627ac888d42b0 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Wed, 13 May 2020 03:39:24 -0400 Subject: add man page for audiocue2bincue --- audiocue2bincue | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 audiocue2bincue (limited to 'audiocue2bincue') diff --git a/audiocue2bincue b/audiocue2bincue new file mode 100644 index 0000000..84c1582 --- /dev/null +++ b/audiocue2bincue @@ -0,0 +1,90 @@ +#!/usr/bin/env perl -w + +# Convert an audio file based CD image into a raw bin/cue. +# Uses libsndfile to do the audio file decoding and conversion, +# except for mp3 files (use lame for those). + +# Please don't try to convince me to use CPAN modules for things like +# cue sheets or audio format conversions. This is me using perl as a +# 'glue' language, not an 'enterprise applications platform'. + +($self = $0) =~ s,.*/,,; + +if(!@ARGV || $ARGV[0] eq '--help') { + print <", $ARGV[1]; + select $out; +} + +# Everyone always complains about regex looking like gibberish, +# so here's my attempt at writing a readable(ish) one. +$match_file = qr{ + ^\s* # optional leading space/tabs + FILE # required token + \s+ # required one or more spaces before the filename + "? # optional quote (spec doesn't require it) + ([^"]+) # actual filename goes in $1 + "? # optional quote afterwards + \s+ # required space(s) before the type + (\w+) # type (BINARY, WAVE, MP3 maybe, etc) goes in $2 +}x; + +@ARGV = ($ARGV[0]); + +%audiofiles = (); + +while(<>) { + if(/$match_file/) { + my ($file, $type) = ($1, $2); + $audiofiles{$file}++; + print fix_line($_, $file, $type); + } else { + print; + } +} + +for(keys %audiofiles) { + my $newfilename = $new_filenames{$_}; + (my $rawfilename = $newfilename) =~ s/\.bin$/.raw/; + + my @cmd = (); + + if($_ =~ /mp3$/i) { + @cmd = ( "lame", "-t", "--quiet", "--decode" ); + push @cmd, "-x" if $swapbytes; + push @cmd, ( $_, $rawfilename ); + } else { + my $endarg = "-endian=" . ($swapbytes ? "big" : "little"); + @cmd = ( "sndfile-convert", "-pcm16", $endarg, $_, $rawfilename ); + } + + warn "Converting $_ to raw .bin with $cmd[0]\n"; + system(@cmd); + rename($rawfilename, $newfilename); +} + +sub fix_line { + my ($line, $filename, $type) = @_; + my $newfilename; + + if($type eq 'BINARY') { + warn "$filename is already type BINARY, leaving as-is\n"; + return $line; + } + + ($newfilename = $filename) =~ s/(?:\.\w+)?$/.bin/; + $new_filenames{$filename} = $newfilename; + return "FILE \"$newfilename\" BINARY\r\n"; +} -- cgit v1.2.3