#! /bin/bash set -e : ${JBDIR=/mnt/jb} i0=0 zero_start=0 trim_end=0 span=$((588*5 - 1)) debug="" while getopts flF:L:i:b:a:s:d opt; do case "$opt" in f) zero_start=$((588*5 - 1)) ;; l) trim_end=$((588*5)) ;; F) zero_start=$OPTARG ;; L) trim_end=$OPTARG ;; b) before=$OPTARG ;; a) after=$OPTARG ;; s) span=$OPTARG ;; d) debug=-d ;; *) exit 1 ;; esac done shift $((OPTIND - 1)) case $# in 0 | 1) echo >&2 "usage: $0 [-OPTIONS] FILE TARGET..." exit 1 ;; esac file=$1; shift ns=$(metaflac --show-total-samples "$file") read ck tot < <( { if [ "${before+set}" ]; then n=$(metaflac --show-total-samples "$before") flac -d -s -o- --force-raw-format --sign=signed --endian=little \ --skip=$((n - span)) \ "$before" else $JBDIR/bin/cat-prefix $((4 * span)) 0)); then $JBDIR/bin/cat-prefix $((4 * zero_start)) /dev/null fi cat } | $JBDIR/bin/flaccrip-compute -r ) while read off ck; do echo M $((off - span)) "$ck" done < <( $JBDIR/bin/flaccrip-slide \ -i "$zero_start" $debug \ $((ns - trim_end)) $ck $tot \ <( if ((span > zero_start)); then tail=$((span - zero_start)) if [ "${before+set}" ]; then n=$(metaflac --show-total-samples "$before") flac -d -s -o- --force-raw-format --sign=signed --endian=little \ --skip=$((n - tail)) \ "$before" else $JBDIR/bin/cat-prefix $((4 * tail)) trim_end)); then flac -d -s -o- --force-raw-format --sign=signed --endian=little \ --skip=$((ns - span - trim_end)) \ "$file" head=$((span - trim_end)) if [ "${after+set}" ]; then flac -d -s -o- --force-raw-format --sign=signed --endian=little \ --until=$head \ "$after" else $JBDIR/bin/cat-prefix $((4 * head))