run_vectors.sh 4.9 KB

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