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

Side by Side Diff: opus/celt/tests/test_unit_dft.c

Issue 11196031: Add copy of opus library in deps/third_party. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/
Patch Set: Created 8 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « opus/celt/tests/test_unit_cwrs32.c ('k') | opus/celt/tests/test_unit_entropy.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4
5 #define SKIP_CONFIG_H
6
7 #ifndef CUSTOM_MODES
8 #define CUSTOM_MODES
9 #endif
10
11 #include <stdio.h>
12
13 #define CELT_C
14 #include "stack_alloc.h"
15 #include "kiss_fft.h"
16 #include "kiss_fft.c"
17 #include "mathops.c"
18 #include "entcode.c"
19
20
21 #ifndef M_PI
22 #define M_PI 3.141592653
23 #endif
24
25 int ret = 0;
26
27 void check(kiss_fft_cpx * in,kiss_fft_cpx * out,int nfft,int isinverse)
28 {
29 int bin,k;
30 double errpow=0,sigpow=0, snr;
31
32 for (bin=0;bin<nfft;++bin) {
33 double ansr = 0;
34 double ansi = 0;
35 double difr;
36 double difi;
37
38 for (k=0;k<nfft;++k) {
39 double phase = -2*M_PI*bin*k/nfft;
40 double re = cos(phase);
41 double im = sin(phase);
42 if (isinverse)
43 im = -im;
44
45 if (!isinverse)
46 {
47 re /= nfft;
48 im /= nfft;
49 }
50
51 ansr += in[k].r * re - in[k].i * im;
52 ansi += in[k].r * im + in[k].i * re;
53 }
54 /*printf ("%d %d ", (int)ansr, (int)ansi);*/
55 difr = ansr - out[bin].r;
56 difi = ansi - out[bin].i;
57 errpow += difr*difr + difi*difi;
58 sigpow += ansr*ansr+ansi*ansi;
59 }
60 snr = 10*log10(sigpow/errpow);
61 printf("nfft=%d inverse=%d,snr = %f\n",nfft,isinverse,snr );
62 if (snr<60) {
63 printf( "** poor snr: %f ** \n", snr);
64 ret = 1;
65 }
66 }
67
68 void test1d(int nfft,int isinverse)
69 {
70 size_t buflen = sizeof(kiss_fft_cpx)*nfft;
71
72 kiss_fft_cpx * in = (kiss_fft_cpx*)malloc(buflen);
73 kiss_fft_cpx * out= (kiss_fft_cpx*)malloc(buflen);
74 kiss_fft_state *cfg = opus_fft_alloc(nfft,0,0);
75 int k;
76
77 for (k=0;k<nfft;++k) {
78 in[k].r = (rand() % 32767) - 16384;
79 in[k].i = (rand() % 32767) - 16384;
80 }
81
82 for (k=0;k<nfft;++k) {
83 in[k].r *= 32768;
84 in[k].i *= 32768;
85 }
86
87 if (isinverse)
88 {
89 for (k=0;k<nfft;++k) {
90 in[k].r /= nfft;
91 in[k].i /= nfft;
92 }
93 }
94
95 /*for (k=0;k<nfft;++k) printf("%d %d ", in[k].r, in[k].i);printf("\n");*/
96
97 if (isinverse)
98 opus_ifft(cfg,in,out);
99 else
100 opus_fft(cfg,in,out);
101
102 /*for (k=0;k<nfft;++k) printf("%d %d ", out[k].r, out[k].i);printf("\n");*/
103
104 check(in,out,nfft,isinverse);
105
106 free(in);
107 free(out);
108 free(cfg);
109 }
110
111 int main(int argc,char ** argv)
112 {
113 ALLOC_STACK;
114 if (argc>1) {
115 int k;
116 for (k=1;k<argc;++k) {
117 test1d(atoi(argv[k]),0);
118 test1d(atoi(argv[k]),1);
119 }
120 }else{
121 test1d(32,0);
122 test1d(32,1);
123 test1d(128,0);
124 test1d(128,1);
125 test1d(256,0);
126 test1d(256,1);
127 #ifndef RADIX_TWO_ONLY
128 test1d(36,0);
129 test1d(36,1);
130 test1d(50,0);
131 test1d(50,1);
132 test1d(120,0);
133 test1d(120,1);
134 #endif
135 }
136 return ret;
137 }
OLDNEW
« no previous file with comments | « opus/celt/tests/test_unit_cwrs32.c ('k') | opus/celt/tests/test_unit_entropy.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698