opus_update.patch 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. diff --git a/celt/bands.c b/celt/bands.c
  2. index 6962587..32e1de6 100644
  3. --- a/celt/bands.c
  4. +++ b/celt/bands.c
  5. @@ -1234,9 +1234,23 @@ void quant_all_bands(int encode, const CELTMode *m, int start, int end,
  6. b = 0;
  7. }
  8. - if (resynth && M*eBands[i]-N >= M*eBands[start] && (update_lowband || lowband_offset==0))
  9. + if (resynth && (M*eBands[i]-N >= M*eBands[start] || i==start+1) && (update_lowband || lowband_offset==0))
  10. lowband_offset = i;
  11. + if (i == start+1)
  12. + {
  13. + int n1, n2;
  14. + int offset;
  15. + n1 = M*(eBands[start+1]-eBands[start]);
  16. + n2 = M*(eBands[start+2]-eBands[start+1]);
  17. + offset = M*eBands[start];
  18. + /* Duplicate enough of the first band folding data to be able to fold the second band.
  19. + Copies no data for CELT-only mode. */
  20. + OPUS_COPY(&norm[offset+n1], &norm[offset+2*n1 - n2], n2-n1);
  21. + if (C==2)
  22. + OPUS_COPY(&norm2[offset+n1], &norm2[offset+2*n1 - n2], n2-n1);
  23. + }
  24. +
  25. tf_change = tf_res[i];
  26. if (i>=m->effEBands)
  27. {
  28. @@ -1257,7 +1271,7 @@ void quant_all_bands(int encode, const CELTMode *m, int start, int end,
  29. fold_start = lowband_offset;
  30. while(M*eBands[--fold_start] > effective_lowband);
  31. fold_end = lowband_offset-1;
  32. - while(M*eBands[++fold_end] < effective_lowband+N);
  33. + while(++fold_end < i && M*eBands[fold_end] < effective_lowband+N);
  34. x_cm = y_cm = 0;
  35. fold_i = fold_start; do {
  36. x_cm |= collapse_masks[fold_i*C+0];
  37. diff --git a/celt/quant_bands.c b/celt/quant_bands.c
  38. index e5ed9ef..82fb823 100644
  39. --- a/celt/quant_bands.c
  40. +++ b/celt/quant_bands.c
  41. @@ -552,6 +552,7 @@ void log2Amp(const CELTMode *m, int start, int end,
  42. {
  43. opus_val16 lg = ADD16(oldEBands[i+c*m->nbEBands],
  44. SHL16((opus_val16)eMeans[i],6));
  45. + lg = MIN32(QCONST32(32.f, 16), lg);
  46. eBands[i+c*m->nbEBands] = PSHR32(celt_exp2(lg),4);
  47. }
  48. for (;i<m->nbEBands;i++)
  49. diff --git a/silk/LPC_inv_pred_gain.c b/silk/LPC_inv_pred_gain.c
  50. index 60c439b..6c301da 100644
  51. --- a/silk/LPC_inv_pred_gain.c
  52. +++ b/silk/LPC_inv_pred_gain.c
  53. @@ -84,8 +84,13 @@ static opus_int32 LPC_inverse_pred_gain_QA( /* O Returns inver
  54. /* Update AR coefficient */
  55. for( n = 0; n < k; n++ ) {
  56. - tmp_QA = Aold_QA[ n ] - MUL32_FRAC_Q( Aold_QA[ k - n - 1 ], rc_Q31, 31 );
  57. - Anew_QA[ n ] = MUL32_FRAC_Q( tmp_QA, rc_mult2 , mult2Q );
  58. + opus_int64 tmp64;
  59. + tmp_QA = silk_SUB_SAT32( Aold_QA[ n ], MUL32_FRAC_Q( Aold_QA[ k - n - 1 ], rc_Q31, 31 ) );
  60. + tmp64 = silk_RSHIFT_ROUND64( silk_SMULL( tmp_QA, rc_mult2 ), mult2Q);
  61. + if( tmp64 > silk_int32_MAX || tmp64 < silk_int32_MIN ) {
  62. + return 0;
  63. + }
  64. + Anew_QA[ n ] = ( opus_int32 )tmp64;
  65. }
  66. }
  67. diff --git a/silk/NLSF_stabilize.c b/silk/NLSF_stabilize.c
  68. index 979aaba..2ef2398 100644
  69. --- a/silk/NLSF_stabilize.c
  70. +++ b/silk/NLSF_stabilize.c
  71. @@ -134,7 +134,7 @@ void silk_NLSF_stabilize(
  72. /* Keep delta_min distance between the NLSFs */
  73. for( i = 1; i < L; i++ )
  74. - NLSF_Q15[i] = silk_max_int( NLSF_Q15[i], NLSF_Q15[i-1] + NDeltaMin_Q15[i] );
  75. + NLSF_Q15[i] = silk_max_int( NLSF_Q15[i], silk_ADD_SAT16( NLSF_Q15[i-1], NDeltaMin_Q15[i] ) );
  76. /* Last NLSF should be no higher than 1 - NDeltaMin[L] */
  77. NLSF_Q15[L-1] = silk_min_int( NLSF_Q15[L-1], (1<<15) - NDeltaMin_Q15[L] );
  78. diff --git a/silk/dec_API.c b/silk/dec_API.c
  79. index efd7918..21bb7e0 100644
  80. --- a/silk/dec_API.c
  81. +++ b/silk/dec_API.c
  82. @@ -72,6 +72,9 @@ opus_int silk_InitDecoder( /* O Returns error co
  83. for( n = 0; n < DECODER_NUM_CHANNELS; n++ ) {
  84. ret = silk_init_decoder( &channel_state[ n ] );
  85. }
  86. + silk_memset(&((silk_decoder *)decState)->sStereo, 0, sizeof(((silk_decoder *)decState)->sStereo));
  87. + /* Not strictly needed, but it's cleaner that way */
  88. + ((silk_decoder *)decState)->prev_decode_only_middle = 0;
  89. return ret;
  90. }
  91. diff --git a/silk/resampler_private_IIR_FIR.c b/silk/resampler_private_IIR_FIR.c
  92. index dbd6d9a..91a43aa 100644
  93. --- a/silk/resampler_private_IIR_FIR.c
  94. +++ b/silk/resampler_private_IIR_FIR.c
  95. @@ -75,10 +75,10 @@ void silk_resampler_private_IIR_FIR(
  96. silk_resampler_state_struct *S = (silk_resampler_state_struct *)SS;
  97. opus_int32 nSamplesIn;
  98. opus_int32 max_index_Q16, index_increment_Q16;
  99. - opus_int16 buf[ RESAMPLER_MAX_BATCH_SIZE_IN + RESAMPLER_ORDER_FIR_12 ];
  100. + opus_int16 buf[ 2*RESAMPLER_MAX_BATCH_SIZE_IN + RESAMPLER_ORDER_FIR_12 ];
  101. /* Copy buffered samples to start of buffer */
  102. - silk_memcpy( buf, S->sFIR, RESAMPLER_ORDER_FIR_12 * sizeof( opus_int32 ) );
  103. + silk_memcpy( buf, S->sFIR, RESAMPLER_ORDER_FIR_12 * sizeof( opus_int16 ) );
  104. /* Iterate over blocks of frameSizeIn input samples */
  105. index_increment_Q16 = S->invRatio_Q16;
  106. @@ -95,13 +95,13 @@ void silk_resampler_private_IIR_FIR(
  107. if( inLen > 0 ) {
  108. /* More iterations to do; copy last part of filtered signal to beginning of buffer */
  109. - silk_memcpy( buf, &buf[ nSamplesIn << 1 ], RESAMPLER_ORDER_FIR_12 * sizeof( opus_int32 ) );
  110. + silk_memmove( buf, &buf[ nSamplesIn << 1 ], RESAMPLER_ORDER_FIR_12 * sizeof( opus_int16 ) );
  111. } else {
  112. break;
  113. }
  114. }
  115. /* Copy last part of filtered signal to the state for the next call */
  116. - silk_memcpy( S->sFIR, &buf[ nSamplesIn << 1 ], RESAMPLER_ORDER_FIR_12 * sizeof( opus_int32 ) );
  117. + silk_memcpy( S->sFIR, &buf[ nSamplesIn << 1 ], RESAMPLER_ORDER_FIR_12 * sizeof( opus_int16 ) );
  118. }
  119. diff --git a/src/opus_decoder.c b/src/opus_decoder.c
  120. index 0cc56f8..8a30fbc 100644
  121. --- a/src/opus_decoder.c
  122. +++ b/src/opus_decoder.c
  123. @@ -595,16 +595,14 @@ static int opus_packet_parse_impl(const unsigned char *data, int len,
  124. /* Padding flag is bit 6 */
  125. if (ch&0x40)
  126. {
  127. - int padding=0;
  128. int p;
  129. do {
  130. if (len<=0)
  131. return OPUS_INVALID_PACKET;
  132. p = *data++;
  133. len--;
  134. - padding += p==255 ? 254: p;
  135. + len -= p==255 ? 254: p;
  136. } while (p==255);
  137. - len -= padding;
  138. }
  139. if (len<0)
  140. return OPUS_INVALID_PACKET;
  141. diff --git a/run_vectors.sh b/run_vectors.sh
  142. index 7cd23ed..4841b0a 100755
  143. --- a/run_vectors.sh
  144. +++ b/run_vectors.sh
  145. @@ -1,3 +1,5 @@
  146. +#!/bin/sh
  147. +#
  148. # Copyright (c) 2011-2012 IETF Trust, Jean-Marc Valin. All rights reserved.
  149. #
  150. # This file is extracted from RFC6716. Please see that RFC for additional
  151. @@ -31,10 +33,8 @@
  152. # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  153. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  154. -#!/bin/sh
  155. -
  156. -rm logs_mono.txt
  157. -rm logs_stereo.txt
  158. +rm -f logs_mono.txt logs_mono2.txt
  159. +rm -f logs_stereo.txt logs_stereo2.txt
  160. if [ "$#" -ne "3" ]; then
  161. echo "usage: run_vectors.sh <exec path> <vector path> <rate>"
  162. @@ -45,18 +45,23 @@ CMD_PATH=$1
  163. VECTOR_PATH=$2
  164. RATE=$3
  165. -OPUS_DEMO=$CMD_PATH/opus_demo
  166. -OPUS_COMPARE=$CMD_PATH/opus_compare
  167. +: ${OPUS_DEMO:=$CMD_PATH/opus_demo}
  168. +: ${OPUS_COMPARE:=$CMD_PATH/opus_compare}
  169. if [ -d $VECTOR_PATH ]; then
  170. echo Test vectors found in $VECTOR_PATH
  171. else
  172. echo No test vectors found
  173. - #Don't make the test fail here because the test vectors will be
  174. - #distributed separately
  175. + #Don't make the test fail here because the test vectors
  176. + #will be distributed separately
  177. exit 0
  178. fi
  179. +if [ ! -x $OPUS_COMPARE ]; then
  180. + echo ERROR: Compare program not found: $OPUS_COMPARE
  181. + exit 1
  182. +fi
  183. +
  184. if [ -x $OPUS_DEMO ]; then
  185. echo Decoding with $OPUS_DEMO
  186. else
  187. @@ -82,9 +87,11 @@ do
  188. echo ERROR: decoding failed
  189. exit 1
  190. fi
  191. - $OPUS_COMPARE -r $RATE $VECTOR_PATH/testvector$file.dec tmp.out >> logs_mono.txt 2>&1
  192. + $OPUS_COMPARE -r $RATE $VECTOR_PATH/testvector${file}.dec tmp.out >> logs_mono.txt 2>&1
  193. float_ret=$?
  194. - if [ "$float_ret" -eq "0" ]; then
  195. + $OPUS_COMPARE -r $RATE $VECTOR_PATH/testvector${file}m.dec tmp.out >> logs_mono2.txt 2>&1
  196. + float_ret2=$?
  197. + if [ "$float_ret" -eq "0" ] || [ "$float_ret2" -eq "0" ]; then
  198. echo output matches reference
  199. else
  200. echo ERROR: output does not match reference
  201. @@ -111,9 +118,11 @@ do
  202. echo ERROR: decoding failed
  203. exit 1
  204. fi
  205. - $OPUS_COMPARE -s -r $RATE $VECTOR_PATH/testvector$file.dec tmp.out >> logs_stereo.txt 2>&1
  206. + $OPUS_COMPARE -s -r $RATE $VECTOR_PATH/testvector${file}.dec tmp.out >> logs_stereo.txt 2>&1
  207. float_ret=$?
  208. - if [ "$float_ret" -eq "0" ]; then
  209. + $OPUS_COMPARE -s -r $RATE $VECTOR_PATH/testvector${file}m.dec tmp.out >> logs_stereo2.txt 2>&1
  210. + float_ret2=$?
  211. + if [ "$float_ret" -eq "0" ] || [ "$float_ret2" -eq "0" ]; then
  212. echo output matches reference
  213. else
  214. echo ERROR: output does not match reference
  215. @@ -125,5 +134,10 @@ done
  216. echo All tests have passed successfully
  217. -grep quality logs_mono.txt | awk '{sum+=$4}END{print "Average mono quality is", sum/NR, "%"}'
  218. -grep quality logs_stereo.txt | awk '{sum+=$4}END{print "Average stereo quality is", sum/NR, "%"}'
  219. +mono1=`grep quality logs_mono.txt | awk '{sum+=$4}END{if (NR == 12) sum /= 12; else sum = 0; print sum}'`
  220. +mono2=`grep quality logs_mono2.txt | awk '{sum+=$4}END{if (NR == 12) sum /= 12; else sum = 0; print sum}'`
  221. +echo $mono1 $mono2 | awk '{if ($2 > $1) $1 = $2; print "Average mono quality is", $1, "%"}'
  222. +
  223. +stereo1=`grep quality logs_stereo.txt | awk '{sum+=$4}END{if (NR == 12) sum /= 12; else sum = 0; print sum}'`
  224. +stereo2=`grep quality logs_stereo2.txt | awk '{sum+=$4}END{if (NR == 12) sum /= 12; else sum = 0; print sum}'`
  225. +echo $stereo1 $stereo2 | awk '{if ($2 > $1) $1 = $2; print "Average stereo quality is", $1, "%"}'