File: maketests.sh

package info (click to toggle)
moc 1%3A2.6.0~svn-r3005-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,656 kB
  • sloc: ansic: 31,749; sh: 929; cpp: 487; makefile: 240
file content (199 lines) | stat: -rwxr-xr-x 4,746 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/bin/bash

#
# MOC - music on console
# Copyright (C) 2004-2005 Damian Pietras <daper@daper.net>
#
# maketests.sh Copyright (C) 2012 John Fitzgerald
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#

#
# TODO: - Add other supported formats.
#

AUDIO=false
VIDEO=false
FFMPEG="$(which avconv 2>/dev/null || which ffmpeg 2>/dev/null)"
SOX="$(which sox 2>/dev/null)"
SYNTH="synth 10 sine 440 vol 0.5"

# Clean error termination.
function die {
  echo $@ > /dev/stderr
  exit 1
}

[[ -x "$SOX" ]] || die This script requires the SoX package.

# Provide usage information.
function usage () {
  echo "Usage: ${0##*/} [-a] [--audio] [-h] [--video] [FORMAT ...]"
}

# Provide help information.
function help () {
  echo
  echo "MOC test file generation tool"
  echo
  usage
  echo
  echo "  -a|--all        Generate all formats"
  echo "     --audio      Generate all audio formats"
  echo "  -h|--help       This help information"
  echo "     --video      Generate all video formats"
  echo
  echo "Supported audio formats: flac mp3 vorbis wav"
  echo "Supported video formats: vob"
  echo
}

# Generate FLAC audio test files.
function flac {
  echo "Generating FLAC audio test files"
  for r in 8000 16000 24000 32000 48000 96000 192000 \
           11025 22050 44100 88200 176400
  do
    for b in 16 32
    do
      $SOX -b$b -c1 -r$r -e signed -n -L sinewave-s${b}le-1-$r.flac $SYNTH
      $SOX -b$b -c2 -r$r -e signed -n -L sinewave-s${b}le-2-$r.flac $SYNTH
    done
  done
}

# Generate MP3 audio test files.
function mp3 {
  echo "Generating MP3 audio test files"
  for r in 8000 16000 24000 32000 48000 11025 22050 44100
  do
    for c in 1 2
    do
      $SOX -b8 -c$c -r$r -n sinewave-u8-$c-$r.mp3 $SYNTH
      for b in 16 24 32
      do
        $SOX -b$b -c$c -r$r -n -L sinewave-s${b}le-$c-$r.mp3 $SYNTH
        $SOX -b$b -c$c -r$r -n -B sinewave-s${b}be-$c-$r.mp3 $SYNTH
      done
    done
  done
}

# Generate VOB video test files.
function vob {
  [[ -x "$FFMPEG" ]] || return
  echo "Generating VOB video test files"
  for r in 16000 22050 24000 32000 44100 48000
  do
    for c in 1 2
    do
      $FFMPEG -f rawvideo -pix_fmt yuv420p -s 320x240 -r 30000/1001 \
              -i /dev/zero \
              -f s16le -c pcm_s16le -ac 2 -ar 48000 \
              -i <($SOX -q -b16 -c2 -r 48000 -e signed -n -L -t s16 - $SYNTH) \
              -vcodec mpeg2video -acodec mp2 -shortest -ac $c -ar $r \
              -y sinewave-s16le-$c-$r.vob > /dev/null  2>&1
    done
  done
}

# Generate Ogg/Vorbis audio test files.
function vorbis {
  echo "Generating Ogg/Vorbis audio test files"
  for r in 8000 16000 24000 32000 48000 96000 192000 \
           11025 22050 44100 88200 176400
  do
    $SOX -b16 -c1 -r$r -e signed -n -L sinewave-s16le-1-$r.ogg $SYNTH
    $SOX -b16 -c2 -r$r -e signed -n -L sinewave-s16le-2-$r.ogg $SYNTH
  done
}

# Generate WAV audio test files.
function wav {
  echo "Generating WAV audio test files"
  for r in 8000 16000 24000 32000 48000 96000 192000 \
           11025 22050 44100 88200 176400
  do
    for c in 1 2
    do
      $SOX -b8 -c$c -r$r -n sinewave-u8-$c-$r.wav $SYNTH
      $SOX -b16 -c$c -r$r -n -B sinewave-s16be-$c-$r.wav $SYNTH
      for b in 16 24 32
      do
        $SOX -b$b -c$c -r$r -n -L sinewave-s${b}le-$c-$r.wav $SYNTH
      done
    done
  done
}

# Directory safety check.
ls sinewave-* > /dev/null 2>&1 && {
  echo
  echo "This script generates many filenames starting with 'sinewave-' in the"
  echo "current directory which already contains similarly named files."
  echo "Running it in this directory is a really, really bad idea.  (In fact,"
  echo "it's probably not wise to run this script in a non-empty directory at"
  echo "all.)  So we're aborting in the interests of safety."
  echo
  exit 1
} > /dev/stderr

# Process command line options.
for OPTS
do
  case $1 in
   -a|--all) AUDIO=true
             VIDEO=true
             ;;
    --audio) AUDIO=true
             ;;
  -h|--help) help
             exit 0
             ;;
    --video) VIDEO=true
             ;;
         -*) echo Unrecognised option: $1
             usage > /dev/stderr
             exit 1
             ;;
          *) break
             ;;
  esac
  shift
done

# Generate all audio formats.
$AUDIO && {
  flac
  mp3
  vorbis
  wav
}

# Generate all video formats.
$VIDEO && {
  vob
}

# Generate specified formats.
for ARGS
do
  case $1 in
  flac|mp3|vorbis|wav)
      $1
      ;;
  vob)
      $1
      ;;
  *)  echo "*** Unsupported format: $1"
      echo
      ;;
  esac
  shift
done

exit 0