From a1005984a6e144fcd1701b4b71e9de5a17ebbca9 Mon Sep 17 00:00:00 2001
From: Ivan Kalvachev <ikalvachev@gmail.com>
Date: Sat, 1 Jul 2017 00:34:22 +0300
Subject: [PATCH 2/4] Code to measure the total distortion sum of the reference
and dsp implementation.
---
libavcodec/opus_pvq.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 70 insertions(+), 3 deletions(-)
@@ -420,10 +420,77 @@ static uint32_t celt_alg_quant(OpusRangeCoder *rc, float *X, uint32_t N, uint32_
celt_exp_rotation(X, N, blocks, K, spread, 1);
{
- START_TIMER
- gain /= sqrtf(pvq->pvq_search(X, y, K, N));
- STOP_TIMER("pvq_search");
+ static double adist1 = 0.0f;
+ static double adist2 = 0.0f;
+ static int cnt,cntlg;
+ float xn1[256];
+ float xn2[256];
+ int ysec[256];
+
+ float sq1 = 0.0f;
+ float sq2 = 0.0f;
+
+ float dist1 = 0.0f;
+ float dist2 = 0.0f;
+
+ int sum1 = 0, sum2 = 0;
+
+ // START_TIMER
+ gain /= sqrtf(pvq->pvq_search(X, y, K, N));
+ // STOP_TIMER("pvq_search");
+
+ ppp_pvq_search_c(X, ysec, K, N);
+
+
+ for (int i = 0; i < N; i++) {
+ sq1 += y[i]*y[i];
+ sq2 += ysec[i]*ysec[i];
+ sum1 += FFABS(y[i]);
+ sum2 += FFABS(ysec[i]);
+ }
+
+ if (sum1 != K) {
+ printf("\nERROR! sum Sy=%i K=%i N=%d \n", sum1, K, N);
+ printf(" X = ");
+ for(int i=0; i<N; i++){
+ printf("%8X, ",((unsigned int *)X)[i]);
+ }
+ printf("\n y1 = ");
+ for(int i=0; i<N; i++){
+ printf("%8d, ", y[i]);
+ }
+ printf("\n y2 = ");
+ for(int i=0; i<N; i++){
+ printf("%8d, ", ysec[i]);
+ }
+ printf("\nERROR!\n");
+ goto what;
+ //av_assert0(0);
+ }
+
+
+ for (int i = 0; i < N; i++) {
+ xn1[i] = (float)y[i]/sq1;
+ xn2[i] = (float)ysec[i]/sq2;
+ dist1 += (X[i] - xn1[i])*(X[i] - xn1[i]);
+ dist2 += (X[i] - xn2[i])*(X[i] - xn2[i]);
+ }
+
+ dist1 = sqrtf(dist1);
+ dist2 = sqrtf(dist2);
+
+ adist1 += (double)dist1;
+ adist2 += (double)dist2;
+
+ cnt++;
+ if(cnt>=2*cntlg){
+ cntlg=cnt;
+ printf("\nruns = %d\n", cnt);
+ printf("Distortion1 = %f\n", adist1);
+ printf("Distortion2 = %f\n", adist2);
+ }
}
+what:
celt_encode_pulses(rc, y, N, K);
celt_normalize_residual(y, X, N, gain);
--
2.13.0