8 *) echo >&2 "Usage: $0 OFFSET SOURCEDIR TARGETDIR"; exit 1 ;;
11 offset=$1 sourcedir=$2 targetdir=$3
13 tmp="$targetdir"/_tmp; mkdir "$tmp"
14 trap 'rm -rf "$targetdir"' EXIT INT TERM
17 for i in "$sourcedir"/*.flac; do
19 metaflac --export-tags-to="$tmp/${base%.flac}.tags" "$i"
20 len=$(metaflac --show-total-samples "$i")
21 lens="${lens:+$lens }$len"
25 if ((offset < 0)); then
26 $JBDIR/bin/cat-prefix $((4 * -offset)) </dev/zero
28 for i in "$sourcedir"/*.flac; do
29 flac -d -s -o- --force-raw-format --sign=signed --endian=little "$i"
31 if ((offset > 0)); then
32 $JBDIR/bin/cat-prefix $((4 * offset)) </dev/zero
35 if ((offset > 0)); then
36 $JBDIR/bin/cat-prefix $((4 * offset)) >/dev/null
39 for i in "$sourcedir"/*.flac; do
42 $JBDIR/bin/cat-prefix $((4 * len)) >"$tmp"/"${base%.flac}.pcm"
43 flac --force-raw-format --sign=signed --endian=little --channels=2 \
44 --bps=16 --sample-rate=44100 --best -o "$targetdir"/"$base" \
45 "$tmp"/"${base%.flac}.pcm"
46 metaflac --remove-all-tags \
47 --import-tags-from="$tmp"/"${base%.flac}.tags" \
50 if ((offset < 0)); then
51 $JBDIR/bin/cat-prefix $((4 * -offset)) >/dev/null
55 for i in "$sourcedir"/* "$sourcedir"/.[!.]*; do
56 if [ ! -e "$i" ]; then continue; fi
59 *) cp -r "$i" "$targetdir"/ ;;