Jean-Marc Valin | ad20dd2 | 2011-10-28 12:09:00 -0400 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
Jean-Marc Valin | 00898f2 | 2012-10-30 01:26:36 -0400 | [diff] [blame] | 3 | # Copyright (c) 2011-2012 Jean-Marc Valin |
| 4 | # |
| 5 | # This file is extracted from RFC6716. Please see that RFC for additional |
| 6 | # information. |
| 7 | # |
| 8 | # Redistribution and use in source and binary forms, with or without |
| 9 | # modification, are permitted provided that the following conditions |
| 10 | # are met: |
| 11 | # |
| 12 | # - Redistributions of source code must retain the above copyright |
| 13 | # notice, this list of conditions and the following disclaimer. |
| 14 | # |
| 15 | # - Redistributions in binary form must reproduce the above copyright |
| 16 | # notice, this list of conditions and the following disclaimer in the |
| 17 | # documentation and/or other materials provided with the distribution. |
| 18 | # |
| 19 | # - Neither the name of Internet Society, IETF or IETF Trust, nor the |
| 20 | # names of specific contributors, may be used to endorse or promote |
| 21 | # products derived from this software without specific prior written |
| 22 | # permission. |
| 23 | # |
| 24 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 25 | # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 26 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 27 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER |
| 28 | # OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 29 | # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 30 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 31 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 32 | # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 33 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 34 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 35 | |
Jean-Marc Valin | 18a380a | 2016-04-20 13:27:06 -0400 | [diff] [blame] | 36 | rm -f logs_mono.txt logs_mono2.txt |
| 37 | rm -f logs_stereo.txt logs_stereo2.txt |
Jean-Marc Valin | 17c5966 | 2012-02-17 16:09:21 -0500 | [diff] [blame] | 38 | |
| 39 | if [ "$#" -ne "3" ]; then |
| 40 | echo "usage: run_vectors.sh <exec path> <vector path> <rate>" |
Jean-Marc Valin | 2d4f614 | 2011-10-28 16:16:35 -0400 | [diff] [blame] | 41 | exit 1 |
| 42 | fi |
| 43 | |
Jean-Marc Valin | ad20dd2 | 2011-10-28 12:09:00 -0400 | [diff] [blame] | 44 | CMD_PATH=$1 |
| 45 | VECTOR_PATH=$2 |
Jean-Marc Valin | 17c5966 | 2012-02-17 16:09:21 -0500 | [diff] [blame] | 46 | RATE=$3 |
Jean-Marc Valin | ad20dd2 | 2011-10-28 12:09:00 -0400 | [diff] [blame] | 47 | |
Jonathan Lennox | 3a1dc9d | 2015-08-04 15:24:21 -0400 | [diff] [blame] | 48 | : ${OPUS_DEMO:=$CMD_PATH/opus_demo} |
| 49 | : ${OPUS_COMPARE:=$CMD_PATH/opus_compare} |
Jean-Marc Valin | ad20dd2 | 2011-10-28 12:09:00 -0400 | [diff] [blame] | 50 | |
Mark Harris | 20e9378 | 2017-06-13 21:35:28 -0700 | [diff] [blame] | 51 | if [ -d "$VECTOR_PATH" ]; then |
| 52 | echo "Test vectors found in $VECTOR_PATH" |
Jean-Marc Valin | ad20dd2 | 2011-10-28 12:09:00 -0400 | [diff] [blame] | 53 | else |
Mark Harris | 20e9378 | 2017-06-13 21:35:28 -0700 | [diff] [blame] | 54 | echo "No test vectors found" |
Ralph Giles | 5f6e472 | 2012-03-19 17:10:13 -0700 | [diff] [blame] | 55 | #Don't make the test fail here because the test vectors |
| 56 | #will be distributed separately |
Jean-Marc Valin | ad20dd2 | 2011-10-28 12:09:00 -0400 | [diff] [blame] | 57 | exit 0 |
| 58 | fi |
| 59 | |
Mark Harris | 20e9378 | 2017-06-13 21:35:28 -0700 | [diff] [blame] | 60 | if [ ! -x "$OPUS_COMPARE" ]; then |
| 61 | echo "ERROR: Compare program not found: $OPUS_COMPARE" |
Aurélien Zanelli | fcecd29 | 2013-05-27 15:54:31 +0200 | [diff] [blame] | 62 | exit 1 |
| 63 | fi |
| 64 | |
Mark Harris | 20e9378 | 2017-06-13 21:35:28 -0700 | [diff] [blame] | 65 | if [ -x "$OPUS_DEMO" ]; then |
| 66 | echo "Decoding with $OPUS_DEMO" |
Jean-Marc Valin | ad20dd2 | 2011-10-28 12:09:00 -0400 | [diff] [blame] | 67 | else |
Mark Harris | 20e9378 | 2017-06-13 21:35:28 -0700 | [diff] [blame] | 68 | echo "ERROR: Decoder not found: $OPUS_DEMO" |
Jean-Marc Valin | ad20dd2 | 2011-10-28 12:09:00 -0400 | [diff] [blame] | 69 | exit 1 |
| 70 | fi |
| 71 | |
| 72 | echo "==============" |
Mark Harris | 20e9378 | 2017-06-13 21:35:28 -0700 | [diff] [blame] | 73 | echo "Testing mono" |
Jean-Marc Valin | ad20dd2 | 2011-10-28 12:09:00 -0400 | [diff] [blame] | 74 | echo "==============" |
| 75 | echo |
| 76 | |
Jean-Marc Valin | 7227300 | 2012-04-20 10:26:08 -0400 | [diff] [blame] | 77 | for file in 01 02 03 04 05 06 07 08 09 10 11 12 |
Jean-Marc Valin | ad20dd2 | 2011-10-28 12:09:00 -0400 | [diff] [blame] | 78 | do |
Mark Harris | 20e9378 | 2017-06-13 21:35:28 -0700 | [diff] [blame] | 79 | if [ -e "$VECTOR_PATH/testvector$file.bit" ]; then |
| 80 | echo "Testing testvector$file" |
Ralph Giles | 5f6e472 | 2012-03-19 17:10:13 -0700 | [diff] [blame] | 81 | else |
Mark Harris | 20e9378 | 2017-06-13 21:35:28 -0700 | [diff] [blame] | 82 | echo "Bitstream file not found: testvector$file.bit" |
Jean-Marc Valin | ad20dd2 | 2011-10-28 12:09:00 -0400 | [diff] [blame] | 83 | fi |
Mark Harris | 20e9378 | 2017-06-13 21:35:28 -0700 | [diff] [blame] | 84 | if "$OPUS_DEMO" -d "$RATE" 1 "$VECTOR_PATH/testvector$file.bit" tmp.out >> logs_mono.txt 2>&1; then |
| 85 | echo "successfully decoded" |
Jean-Marc Valin | ad20dd2 | 2011-10-28 12:09:00 -0400 | [diff] [blame] | 86 | else |
Mark Harris | 20e9378 | 2017-06-13 21:35:28 -0700 | [diff] [blame] | 87 | echo "ERROR: decoding failed" |
Jean-Marc Valin | ad20dd2 | 2011-10-28 12:09:00 -0400 | [diff] [blame] | 88 | exit 1 |
| 89 | fi |
Mark Harris | 20e9378 | 2017-06-13 21:35:28 -0700 | [diff] [blame] | 90 | "$OPUS_COMPARE" -r "$RATE" "$VECTOR_PATH/testvector${file}.dec" tmp.out >> logs_mono.txt 2>&1 |
Jean-Marc Valin | ad20dd2 | 2011-10-28 12:09:00 -0400 | [diff] [blame] | 91 | float_ret=$? |
Mark Harris | 20e9378 | 2017-06-13 21:35:28 -0700 | [diff] [blame] | 92 | "$OPUS_COMPARE" -r "$RATE" "$VECTOR_PATH/testvector${file}m.dec" tmp.out >> logs_mono2.txt 2>&1 |
Jean-Marc Valin | 18a380a | 2016-04-20 13:27:06 -0400 | [diff] [blame] | 93 | float_ret2=$? |
| 94 | if [ "$float_ret" -eq "0" ] || [ "$float_ret2" -eq "0" ]; then |
Mark Harris | 20e9378 | 2017-06-13 21:35:28 -0700 | [diff] [blame] | 95 | echo "output matches reference" |
Jean-Marc Valin | ad20dd2 | 2011-10-28 12:09:00 -0400 | [diff] [blame] | 96 | else |
Mark Harris | 20e9378 | 2017-06-13 21:35:28 -0700 | [diff] [blame] | 97 | echo "ERROR: output does not match reference" |
Jean-Marc Valin | ad20dd2 | 2011-10-28 12:09:00 -0400 | [diff] [blame] | 98 | exit 1 |
| 99 | fi |
| 100 | echo |
| 101 | done |
| 102 | |
| 103 | echo "==============" |
| 104 | echo Testing stereo |
| 105 | echo "==============" |
| 106 | echo |
| 107 | |
Jean-Marc Valin | 7227300 | 2012-04-20 10:26:08 -0400 | [diff] [blame] | 108 | for file in 01 02 03 04 05 06 07 08 09 10 11 12 |
Jean-Marc Valin | ad20dd2 | 2011-10-28 12:09:00 -0400 | [diff] [blame] | 109 | do |
Mark Harris | 20e9378 | 2017-06-13 21:35:28 -0700 | [diff] [blame] | 110 | if [ -e "$VECTOR_PATH/testvector$file.bit" ]; then |
| 111 | echo "Testing testvector$file" |
Ralph Giles | 5f6e472 | 2012-03-19 17:10:13 -0700 | [diff] [blame] | 112 | else |
Mark Harris | 20e9378 | 2017-06-13 21:35:28 -0700 | [diff] [blame] | 113 | echo "Bitstream file not found: testvector$file" |
Jean-Marc Valin | ad20dd2 | 2011-10-28 12:09:00 -0400 | [diff] [blame] | 114 | fi |
Mark Harris | 20e9378 | 2017-06-13 21:35:28 -0700 | [diff] [blame] | 115 | if "$OPUS_DEMO" -d "$RATE" 2 "$VECTOR_PATH/testvector$file.bit" tmp.out >> logs_stereo.txt 2>&1; then |
| 116 | echo "successfully decoded" |
Jean-Marc Valin | ad20dd2 | 2011-10-28 12:09:00 -0400 | [diff] [blame] | 117 | else |
Mark Harris | 20e9378 | 2017-06-13 21:35:28 -0700 | [diff] [blame] | 118 | echo "ERROR: decoding failed" |
Jean-Marc Valin | ad20dd2 | 2011-10-28 12:09:00 -0400 | [diff] [blame] | 119 | exit 1 |
| 120 | fi |
Mark Harris | 20e9378 | 2017-06-13 21:35:28 -0700 | [diff] [blame] | 121 | "$OPUS_COMPARE" -s -r "$RATE" "$VECTOR_PATH/testvector${file}.dec" tmp.out >> logs_stereo.txt 2>&1 |
Jean-Marc Valin | ad20dd2 | 2011-10-28 12:09:00 -0400 | [diff] [blame] | 122 | float_ret=$? |
Mark Harris | 20e9378 | 2017-06-13 21:35:28 -0700 | [diff] [blame] | 123 | "$OPUS_COMPARE" -s -r "$RATE" "$VECTOR_PATH/testvector${file}m.dec" tmp.out >> logs_stereo2.txt 2>&1 |
Jean-Marc Valin | 18a380a | 2016-04-20 13:27:06 -0400 | [diff] [blame] | 124 | float_ret2=$? |
| 125 | if [ "$float_ret" -eq "0" ] || [ "$float_ret2" -eq "0" ]; then |
Mark Harris | 20e9378 | 2017-06-13 21:35:28 -0700 | [diff] [blame] | 126 | echo "output matches reference" |
Jean-Marc Valin | ad20dd2 | 2011-10-28 12:09:00 -0400 | [diff] [blame] | 127 | else |
Mark Harris | 20e9378 | 2017-06-13 21:35:28 -0700 | [diff] [blame] | 128 | echo "ERROR: output does not match reference" |
Jean-Marc Valin | ad20dd2 | 2011-10-28 12:09:00 -0400 | [diff] [blame] | 129 | exit 1 |
| 130 | fi |
| 131 | echo |
| 132 | done |
| 133 | |
| 134 | |
| 135 | |
Mark Harris | 20e9378 | 2017-06-13 21:35:28 -0700 | [diff] [blame] | 136 | echo "All tests have passed successfully" |
Jean-Marc Valin | 18a380a | 2016-04-20 13:27:06 -0400 | [diff] [blame] | 137 | mono1=`grep quality logs_mono.txt | awk '{sum+=$4}END{if (NR == 12) sum /= 12; else sum = 0; print sum}'` |
| 138 | mono2=`grep quality logs_mono2.txt | awk '{sum+=$4}END{if (NR == 12) sum /= 12; else sum = 0; print sum}'` |
| 139 | echo $mono1 $mono2 | awk '{if ($2 > $1) $1 = $2; print "Average mono quality is", $1, "%"}' |
| 140 | |
| 141 | stereo1=`grep quality logs_stereo.txt | awk '{sum+=$4}END{if (NR == 12) sum /= 12; else sum = 0; print sum}'` |
| 142 | stereo2=`grep quality logs_stereo2.txt | awk '{sum+=$4}END{if (NR == 12) sum /= 12; else sum = 0; print sum}'` |
| 143 | echo $stereo1 $stereo2 | awk '{if ($2 > $1) $1 = $2; print "Average stereo quality is", $1, "%"}' |