ga-infounused: Use `--no-textconv` in `git diff`
[sunny256-utils.git] / wavto16
blob82a9f72f26076bba2709dd25ce098d1b057fa0bf
1 #!/usr/bin/env bash
3 #=======================================================================
4 # wavto16
5 # File ID: e755fe92-820c-11e2-814c-0016d364066c
7 # Convert media files to 16 bit little endian .wav
9 # Author: Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later.
11 #=======================================================================
13 progname=wavto16
14 VERSION=0.2.0
16 ARGS="$(getopt -o "\
17 c:\
21 " -l "\
22 channels:,\
23 help,\
24 quiet,\
25 verbose,\
26 version,\
27 " -n "$progname" -- "$@")"
28 test "$?" = "0" || exit 1
29 eval set -- "$ARGS"
31 opt_channels=''
32 opt_help=0
33 opt_quiet=0
34 opt_verbose=0
35 while :; do
36 case "$1" in
37 -c|--channels) opt_channels=$2; shift 2 ;;
38 -h|--help) opt_help=1; shift ;;
39 -q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
40 -v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
41 --version) echo $progname $VERSION; exit 0 ;;
42 --) shift; break ;;
43 *) echo $progname: Internal error >&2; exit 1 ;;
44 esac
45 done
46 opt_verbose=$(($opt_verbose - $opt_quiet))
48 if test "$opt_help" = "1"; then
49 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
50 cat <<END
52 Convert media files to 16 bit little endian .wav . Works on all kinds of
53 media files that Mplayer/Mplayer2 supports.
55 Usage: $progname [options] file [files [...]]
57 Options:
59 -c NUM, --channels NUM
60 Use NUM channels in the resulting .wav file.
61 -h, --help
62 Show this help.
63 -q, --quiet
64 Be more quiet. Can be repeated to increase silence.
65 -v, --verbose
66 Increase level of verbosity. Can be repeated.
67 --version
68 Print version information.
70 END
71 exit 0
74 if test -z "$1"; then
75 echo $progname: No files specified >&2
76 exit 1
79 if test -n "$opt_channels"; then
80 echo "$opt_channels" | grep -qE '^[1-8]$' || {
81 echo -n $progname: Argument to -c/--channels must be an integer >&2
82 echo " between 1 and 8" >&2
83 exit 1
85 chan_str=",channels=$opt_channels"
86 else
87 chan_str=''
90 for f in "$@"; do
91 wavfile="$f"
92 tmpfile="$f.tmp.wav"
93 cp -p "$wavfile" "$wavfile.bck"
94 mplayer -novideo -af format=s16le$chan_str \
95 -ao "pcm:file=$tmpfile" "$wavfile"
96 mv "$tmpfile" "$wavfile"
97 done