#! /bin/bash set -e : ${JBDIR=/mnt/jb} zero_start=0 trim_end=0 offset=0 while getopts flF:L:o:b:a: opt; do case "$opt" in f) zero_start=$((588 * 5 - 1)) ;; l) trim_end=$((588 * 5)) ;; F) zero_start=$OPTARG ;; L) trim_end=$OPTARG ;; o) offset=$OPTARG ;; b) before=$OPTARG ;; a) after=$OPTARG ;; *) exit 1 ;; esac done shift $((OPTIND - 1)) case $# in 1) ;; *) echo >&2 "missing file argument" ;; esac file=$1 len=$(metaflac --show-total-samples "$file") if ((offset < 0)); then start=0 stop=$((stop + offset)) elif ((offset >= 0)); then start=$offset stop=$len fi { if ((offset < 0)); then if [ "${before+set}" ]; then n=$(metaflac --show-total-samples "$before") flac -d -s -o- --force-raw-format --sign=signed --endian=little \ --skip=$((n + offset)) --until=$n \ "$before" else $JBDIR/bin/cat-prefix $((4 * -offset)) 0)); then if [ "${after+set}" ]; then flac -d -s -o- --force-raw-format --sign=signed --endian=little \ --skip=0 --until=$offset \ "$after" else $JBDIR/bin/cat-prefix $((4 * offset)) 0)); then $JBDIR/bin/cat-prefix $((4 * zero_start)) /dev/null len=$((len - zero_start)) fi if ((trim_end > 0)); then $JBDIR/bin/cat-prefix $((4 * (len - trim_end))) $JBDIR/bin/cat-prefix $((4 * trim_end)) /dev/null else cat fi }