Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: webrtc/modules/audio_coding/codecs/isac/main/source/transform.c

Issue 1177993003: iSAC: Move global trig tables into the codec instance (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "settings.h" 11 #include "settings.h"
12 #include "fft.h" 12 #include "fft.h"
13 #include "codec.h" 13 #include "codec.h"
14 #include "os_specific_inline.h" 14 #include "os_specific_inline.h"
15 #include <math.h> 15 #include <math.h>
16 16
17 static double costab1[FRAMESAMPLES_HALF]; 17 void WebRtcIsac_InitTransform(TransformTables* tables) {
18 static double sintab1[FRAMESAMPLES_HALF];
19 static double costab2[FRAMESAMPLES_QUARTER];
20 static double sintab2[FRAMESAMPLES_QUARTER];
21
22 void WebRtcIsac_InitTransform()
23 {
24 int k; 18 int k;
25 double fact, phase; 19 double fact, phase;
26 20
27 fact = PI / (FRAMESAMPLES_HALF); 21 fact = PI / (FRAMESAMPLES_HALF);
28 phase = 0.0; 22 phase = 0.0;
29 for (k = 0; k < FRAMESAMPLES_HALF; k++) { 23 for (k = 0; k < FRAMESAMPLES_HALF; k++) {
30 costab1[k] = cos(phase); 24 tables->costab1[k] = cos(phase);
31 sintab1[k] = sin(phase); 25 tables->sintab1[k] = sin(phase);
32 phase += fact; 26 phase += fact;
33 } 27 }
34 28
35 fact = PI * ((double) (FRAMESAMPLES_HALF - 1)) / ((double) FRAMESAMPLES_HALF); 29 fact = PI * ((double) (FRAMESAMPLES_HALF - 1)) / ((double) FRAMESAMPLES_HALF);
36 phase = 0.5 * fact; 30 phase = 0.5 * fact;
37 for (k = 0; k < FRAMESAMPLES_QUARTER; k++) { 31 for (k = 0; k < FRAMESAMPLES_QUARTER; k++) {
38 costab2[k] = cos(phase); 32 tables->costab2[k] = cos(phase);
39 sintab2[k] = sin(phase); 33 tables->sintab2[k] = sin(phase);
40 phase += fact; 34 phase += fact;
41 } 35 }
42 } 36 }
43 37
44 38 void WebRtcIsac_Time2Spec(const TransformTables* tables,
45 void WebRtcIsac_Time2Spec(double *inre1, 39 double* inre1,
46 double *inre2, 40 double* inre2,
47 int16_t *outreQ7, 41 int16_t* outreQ7,
48 int16_t *outimQ7, 42 int16_t* outimQ7,
49 FFTstr *fftstr_obj) 43 FFTstr* fftstr_obj) {
50 {
51
52 int k; 44 int k;
53 int dims[1]; 45 int dims[1];
54 double tmp1r, tmp1i, xr, xi, yr, yi, fact; 46 double tmp1r, tmp1i, xr, xi, yr, yi, fact;
55 double tmpre[FRAMESAMPLES_HALF], tmpim[FRAMESAMPLES_HALF]; 47 double tmpre[FRAMESAMPLES_HALF], tmpim[FRAMESAMPLES_HALF];
56 48
57 49
58 dims[0] = FRAMESAMPLES_HALF; 50 dims[0] = FRAMESAMPLES_HALF;
59 51
60 52
61 /* Multiply with complex exponentials and combine into one complex vector */ 53 /* Multiply with complex exponentials and combine into one complex vector */
62 fact = 0.5 / sqrt(FRAMESAMPLES_HALF); 54 fact = 0.5 / sqrt(FRAMESAMPLES_HALF);
63 for (k = 0; k < FRAMESAMPLES_HALF; k++) { 55 for (k = 0; k < FRAMESAMPLES_HALF; k++) {
64 tmp1r = costab1[k]; 56 tmp1r = tables->costab1[k];
the sun 2015/06/15 15:08:51 Premature pessimization? I hope the dereference i
kwiberg-webrtc 2015/06/15 21:57:28 I'm glad you asked. Given this small test program
the sun 2015/06/16 08:19:54 Hey, now I AM glad I asked. That was super informa
kwiberg-webrtc 2015/06/16 08:31:44 I know just enough assembly to decrypt what code l
the sun 2015/06/16 08:46:36 I was just thinking that it did auto-vectorization
65 tmp1i = sintab1[k]; 57 tmp1i = tables->sintab1[k];
66 tmpre[k] = (inre1[k] * tmp1r + inre2[k] * tmp1i) * fact; 58 tmpre[k] = (inre1[k] * tmp1r + inre2[k] * tmp1i) * fact;
67 tmpim[k] = (inre2[k] * tmp1r - inre1[k] * tmp1i) * fact; 59 tmpim[k] = (inre2[k] * tmp1r - inre1[k] * tmp1i) * fact;
68 } 60 }
69 61
70 62
71 /* Get DFT */ 63 /* Get DFT */
72 WebRtcIsac_Fftns(1, dims, tmpre, tmpim, -1, 1.0, fftstr_obj); 64 WebRtcIsac_Fftns(1, dims, tmpre, tmpim, -1, 1.0, fftstr_obj);
73 65
74 /* Use symmetry to separate into two complex vectors and center frames in time around zero */ 66 /* Use symmetry to separate into two complex vectors and center frames in time around zero */
75 for (k = 0; k < FRAMESAMPLES_QUARTER; k++) { 67 for (k = 0; k < FRAMESAMPLES_QUARTER; k++) {
76 xr = tmpre[k] + tmpre[FRAMESAMPLES_HALF - 1 - k]; 68 xr = tmpre[k] + tmpre[FRAMESAMPLES_HALF - 1 - k];
77 yi = -tmpre[k] + tmpre[FRAMESAMPLES_HALF - 1 - k]; 69 yi = -tmpre[k] + tmpre[FRAMESAMPLES_HALF - 1 - k];
78 xi = tmpim[k] - tmpim[FRAMESAMPLES_HALF - 1 - k]; 70 xi = tmpim[k] - tmpim[FRAMESAMPLES_HALF - 1 - k];
79 yr = tmpim[k] + tmpim[FRAMESAMPLES_HALF - 1 - k]; 71 yr = tmpim[k] + tmpim[FRAMESAMPLES_HALF - 1 - k];
80 72
81 tmp1r = costab2[k]; 73 tmp1r = tables->costab2[k];
82 tmp1i = sintab2[k]; 74 tmp1i = tables->sintab2[k];
83 outreQ7[k] = (int16_t)WebRtcIsac_lrint((xr * tmp1r - xi * tmp1i) * 128.0); 75 outreQ7[k] = (int16_t)WebRtcIsac_lrint((xr * tmp1r - xi * tmp1i) * 128.0);
84 outimQ7[k] = (int16_t)WebRtcIsac_lrint((xr * tmp1i + xi * tmp1r) * 128.0); 76 outimQ7[k] = (int16_t)WebRtcIsac_lrint((xr * tmp1i + xi * tmp1r) * 128.0);
85 outreQ7[FRAMESAMPLES_HALF - 1 - k] = (int16_t)WebRtcIsac_lrint((-yr * tmp1i - yi * tmp1r) * 128.0); 77 outreQ7[FRAMESAMPLES_HALF - 1 - k] = (int16_t)WebRtcIsac_lrint((-yr * tmp1i - yi * tmp1r) * 128.0);
86 outimQ7[FRAMESAMPLES_HALF - 1 - k] = (int16_t)WebRtcIsac_lrint((-yr * tmp1r + yi * tmp1i) * 128.0); 78 outimQ7[FRAMESAMPLES_HALF - 1 - k] = (int16_t)WebRtcIsac_lrint((-yr * tmp1r + yi * tmp1i) * 128.0);
87 } 79 }
88 } 80 }
89 81
90 82 void WebRtcIsac_Spec2time(const TransformTables* tables,
91 void WebRtcIsac_Spec2time(double *inre, double *inim, double *outre1, double *ou tre2, FFTstr *fftstr_obj) 83 double* inre,
92 { 84 double* inim,
93 85 double* outre1,
86 double* outre2,
87 FFTstr* fftstr_obj) {
94 int k; 88 int k;
95 double tmp1r, tmp1i, xr, xi, yr, yi, fact; 89 double tmp1r, tmp1i, xr, xi, yr, yi, fact;
96 90
97 int dims; 91 int dims;
98 92
99 dims = FRAMESAMPLES_HALF; 93 dims = FRAMESAMPLES_HALF;
100 94
101 for (k = 0; k < FRAMESAMPLES_QUARTER; k++) { 95 for (k = 0; k < FRAMESAMPLES_QUARTER; k++) {
102 /* Move zero in time to beginning of frames */ 96 /* Move zero in time to beginning of frames */
103 tmp1r = costab2[k]; 97 tmp1r = tables->costab2[k];
104 tmp1i = sintab2[k]; 98 tmp1i = tables->sintab2[k];
105 xr = inre[k] * tmp1r + inim[k] * tmp1i; 99 xr = inre[k] * tmp1r + inim[k] * tmp1i;
106 xi = inim[k] * tmp1r - inre[k] * tmp1i; 100 xi = inim[k] * tmp1r - inre[k] * tmp1i;
107 yr = -inim[FRAMESAMPLES_HALF - 1 - k] * tmp1r - inre[FRAMESAMPLES_HALF - 1 - k] * tmp1i; 101 yr = -inim[FRAMESAMPLES_HALF - 1 - k] * tmp1r - inre[FRAMESAMPLES_HALF - 1 - k] * tmp1i;
108 yi = -inre[FRAMESAMPLES_HALF - 1 - k] * tmp1r + inim[FRAMESAMPLES_HALF - 1 - k] * tmp1i; 102 yi = -inre[FRAMESAMPLES_HALF - 1 - k] * tmp1r + inim[FRAMESAMPLES_HALF - 1 - k] * tmp1i;
109 103
110 /* Combine into one vector, z = x + j * y */ 104 /* Combine into one vector, z = x + j * y */
111 outre1[k] = xr - yi; 105 outre1[k] = xr - yi;
112 outre1[FRAMESAMPLES_HALF - 1 - k] = xr + yi; 106 outre1[FRAMESAMPLES_HALF - 1 - k] = xr + yi;
113 outre2[k] = xi + yr; 107 outre2[k] = xi + yr;
114 outre2[FRAMESAMPLES_HALF - 1 - k] = -xi + yr; 108 outre2[FRAMESAMPLES_HALF - 1 - k] = -xi + yr;
115 } 109 }
116 110
117 111
118 /* Get IDFT */ 112 /* Get IDFT */
119 WebRtcIsac_Fftns(1, &dims, outre1, outre2, 1, FRAMESAMPLES_HALF, fftstr_obj); 113 WebRtcIsac_Fftns(1, &dims, outre1, outre2, 1, FRAMESAMPLES_HALF, fftstr_obj);
120 114
121 115
122 /* Demodulate and separate */ 116 /* Demodulate and separate */
123 fact = sqrt(FRAMESAMPLES_HALF); 117 fact = sqrt(FRAMESAMPLES_HALF);
124 for (k = 0; k < FRAMESAMPLES_HALF; k++) { 118 for (k = 0; k < FRAMESAMPLES_HALF; k++) {
125 tmp1r = costab1[k]; 119 tmp1r = tables->costab1[k];
126 tmp1i = sintab1[k]; 120 tmp1i = tables->sintab1[k];
127 xr = (outre1[k] * tmp1r - outre2[k] * tmp1i) * fact; 121 xr = (outre1[k] * tmp1r - outre2[k] * tmp1i) * fact;
128 outre2[k] = (outre2[k] * tmp1r + outre1[k] * tmp1i) * fact; 122 outre2[k] = (outre2[k] * tmp1r + outre1[k] * tmp1i) * fact;
129 outre1[k] = xr; 123 outre1[k] = xr;
130 } 124 }
131 } 125 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698