annotate src/opus-1.3/celt/tests/test_unit_mdct.c @ 79:91c729825bca pa_catalina

Update build for AUDIO_COMPONENT_FIX
author Chris Cannam
date Wed, 30 Oct 2019 12:40:34 +0000
parents 7aeed7906520
children
rev   line source
Chris@69 1 /* Copyright (c) 2008-2011 Xiph.Org Foundation
Chris@69 2 Written by Jean-Marc Valin */
Chris@69 3 /*
Chris@69 4 Redistribution and use in source and binary forms, with or without
Chris@69 5 modification, are permitted provided that the following conditions
Chris@69 6 are met:
Chris@69 7
Chris@69 8 - Redistributions of source code must retain the above copyright
Chris@69 9 notice, this list of conditions and the following disclaimer.
Chris@69 10
Chris@69 11 - Redistributions in binary form must reproduce the above copyright
Chris@69 12 notice, this list of conditions and the following disclaimer in the
Chris@69 13 documentation and/or other materials provided with the distribution.
Chris@69 14
Chris@69 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Chris@69 16 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Chris@69 17 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Chris@69 18 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
Chris@69 19 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
Chris@69 20 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
Chris@69 21 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
Chris@69 22 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
Chris@69 23 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
Chris@69 24 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Chris@69 25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Chris@69 26 */
Chris@69 27
Chris@69 28 #ifdef HAVE_CONFIG_H
Chris@69 29 #include "config.h"
Chris@69 30 #endif
Chris@69 31
Chris@69 32 #include <stdio.h>
Chris@69 33
Chris@69 34 #include "mdct.h"
Chris@69 35 #include "stack_alloc.h"
Chris@69 36 #include "kiss_fft.h"
Chris@69 37 #include "mdct.h"
Chris@69 38 #include "modes.h"
Chris@69 39
Chris@69 40 #ifndef M_PI
Chris@69 41 #define M_PI 3.141592653
Chris@69 42 #endif
Chris@69 43
Chris@69 44 int ret = 0;
Chris@69 45 void check(kiss_fft_scalar * in,kiss_fft_scalar * out,int nfft,int isinverse)
Chris@69 46 {
Chris@69 47 int bin,k;
Chris@69 48 double errpow=0,sigpow=0;
Chris@69 49 double snr;
Chris@69 50 for (bin=0;bin<nfft/2;++bin) {
Chris@69 51 double ansr = 0;
Chris@69 52 double difr;
Chris@69 53
Chris@69 54 for (k=0;k<nfft;++k) {
Chris@69 55 double phase = 2*M_PI*(k+.5+.25*nfft)*(bin+.5)/nfft;
Chris@69 56 double re = cos(phase);
Chris@69 57
Chris@69 58 re /= nfft/4;
Chris@69 59
Chris@69 60 ansr += in[k] * re;
Chris@69 61 }
Chris@69 62 /*printf ("%f %f\n", ansr, out[bin]);*/
Chris@69 63 difr = ansr - out[bin];
Chris@69 64 errpow += difr*difr;
Chris@69 65 sigpow += ansr*ansr;
Chris@69 66 }
Chris@69 67 snr = 10*log10(sigpow/errpow);
Chris@69 68 printf("nfft=%d inverse=%d,snr = %f\n",nfft,isinverse,snr );
Chris@69 69 if (snr<60) {
Chris@69 70 printf( "** poor snr: %f **\n", snr);
Chris@69 71 ret = 1;
Chris@69 72 }
Chris@69 73 }
Chris@69 74
Chris@69 75 void check_inv(kiss_fft_scalar * in,kiss_fft_scalar * out,int nfft,int isinverse)
Chris@69 76 {
Chris@69 77 int bin,k;
Chris@69 78 double errpow=0,sigpow=0;
Chris@69 79 double snr;
Chris@69 80 for (bin=0;bin<nfft;++bin) {
Chris@69 81 double ansr = 0;
Chris@69 82 double difr;
Chris@69 83
Chris@69 84 for (k=0;k<nfft/2;++k) {
Chris@69 85 double phase = 2*M_PI*(bin+.5+.25*nfft)*(k+.5)/nfft;
Chris@69 86 double re = cos(phase);
Chris@69 87
Chris@69 88 /*re *= 2;*/
Chris@69 89
Chris@69 90 ansr += in[k] * re;
Chris@69 91 }
Chris@69 92 /*printf ("%f %f\n", ansr, out[bin]);*/
Chris@69 93 difr = ansr - out[bin];
Chris@69 94 errpow += difr*difr;
Chris@69 95 sigpow += ansr*ansr;
Chris@69 96 }
Chris@69 97 snr = 10*log10(sigpow/errpow);
Chris@69 98 printf("nfft=%d inverse=%d,snr = %f\n",nfft,isinverse,snr );
Chris@69 99 if (snr<60) {
Chris@69 100 printf( "** poor snr: %f **\n", snr);
Chris@69 101 ret = 1;
Chris@69 102 }
Chris@69 103 }
Chris@69 104
Chris@69 105
Chris@69 106 void test1d(int nfft,int isinverse,int arch)
Chris@69 107 {
Chris@69 108 size_t buflen = sizeof(kiss_fft_scalar)*nfft;
Chris@69 109 kiss_fft_scalar *in;
Chris@69 110 kiss_fft_scalar *in_copy;
Chris@69 111 kiss_fft_scalar *out;
Chris@69 112 opus_val16 *window;
Chris@69 113 int k;
Chris@69 114
Chris@69 115 #ifdef CUSTOM_MODES
Chris@69 116 int shift = 0;
Chris@69 117 const mdct_lookup *cfg;
Chris@69 118 mdct_lookup _cfg;
Chris@69 119 clt_mdct_init(&_cfg, nfft, 0, arch);
Chris@69 120 cfg = &_cfg;
Chris@69 121 #else
Chris@69 122 int shift;
Chris@69 123 const mdct_lookup *cfg;
Chris@69 124 CELTMode *mode = opus_custom_mode_create(48000, 960, NULL);
Chris@69 125 if (nfft == 1920) shift = 0;
Chris@69 126 else if (nfft == 960) shift = 1;
Chris@69 127 else if (nfft == 480) shift = 2;
Chris@69 128 else if (nfft == 240) shift = 3;
Chris@69 129 else return;
Chris@69 130 cfg = &mode->mdct;
Chris@69 131 #endif
Chris@69 132
Chris@69 133 in = (kiss_fft_scalar*)malloc(buflen);
Chris@69 134 in_copy = (kiss_fft_scalar*)malloc(buflen);
Chris@69 135 out = (kiss_fft_scalar*)malloc(buflen);
Chris@69 136 window = (opus_val16*)malloc(sizeof(opus_val16)*nfft/2);
Chris@69 137
Chris@69 138 for (k=0;k<nfft;++k) {
Chris@69 139 in[k] = (rand() % 32768) - 16384;
Chris@69 140 }
Chris@69 141
Chris@69 142 for (k=0;k<nfft/2;++k) {
Chris@69 143 window[k] = Q15ONE;
Chris@69 144 }
Chris@69 145 for (k=0;k<nfft;++k) {
Chris@69 146 in[k] *= 32768;
Chris@69 147 }
Chris@69 148
Chris@69 149 if (isinverse)
Chris@69 150 {
Chris@69 151 for (k=0;k<nfft;++k) {
Chris@69 152 in[k] /= nfft;
Chris@69 153 }
Chris@69 154 }
Chris@69 155
Chris@69 156 for (k=0;k<nfft;++k)
Chris@69 157 in_copy[k] = in[k];
Chris@69 158 /*for (k=0;k<nfft;++k) printf("%d %d ", in[k].r, in[k].i);printf("\n");*/
Chris@69 159
Chris@69 160 if (isinverse)
Chris@69 161 {
Chris@69 162 for (k=0;k<nfft;++k)
Chris@69 163 out[k] = 0;
Chris@69 164 clt_mdct_backward(cfg,in,out, window, nfft/2, shift, 1, arch);
Chris@69 165 /* apply TDAC because clt_mdct_backward() no longer does that */
Chris@69 166 for (k=0;k<nfft/4;++k)
Chris@69 167 out[nfft-k-1] = out[nfft/2+k];
Chris@69 168 check_inv(in,out,nfft,isinverse);
Chris@69 169 } else {
Chris@69 170 clt_mdct_forward(cfg,in,out,window, nfft/2, shift, 1, arch);
Chris@69 171 check(in_copy,out,nfft,isinverse);
Chris@69 172 }
Chris@69 173 /*for (k=0;k<nfft;++k) printf("%d %d ", out[k].r, out[k].i);printf("\n");*/
Chris@69 174
Chris@69 175
Chris@69 176 free(in);
Chris@69 177 free(in_copy);
Chris@69 178 free(out);
Chris@69 179 free(window);
Chris@69 180 #ifdef CUSTOM_MODES
Chris@69 181 clt_mdct_clear(&_cfg, arch);
Chris@69 182 #endif
Chris@69 183 }
Chris@69 184
Chris@69 185 int main(int argc,char ** argv)
Chris@69 186 {
Chris@69 187 ALLOC_STACK;
Chris@69 188 int arch = opus_select_arch();
Chris@69 189
Chris@69 190 if (argc>1) {
Chris@69 191 int k;
Chris@69 192 for (k=1;k<argc;++k) {
Chris@69 193 test1d(atoi(argv[k]),0,arch);
Chris@69 194 test1d(atoi(argv[k]),1,arch);
Chris@69 195 }
Chris@69 196 }else{
Chris@69 197 test1d(32,0,arch);
Chris@69 198 test1d(32,1,arch);
Chris@69 199 test1d(256,0,arch);
Chris@69 200 test1d(256,1,arch);
Chris@69 201 test1d(512,0,arch);
Chris@69 202 test1d(512,1,arch);
Chris@69 203 test1d(1024,0,arch);
Chris@69 204 test1d(1024,1,arch);
Chris@69 205 test1d(2048,0,arch);
Chris@69 206 test1d(2048,1,arch);
Chris@69 207 #ifndef RADIX_TWO_ONLY
Chris@69 208 test1d(36,0,arch);
Chris@69 209 test1d(36,1,arch);
Chris@69 210 test1d(40,0,arch);
Chris@69 211 test1d(40,1,arch);
Chris@69 212 test1d(60,0,arch);
Chris@69 213 test1d(60,1,arch);
Chris@69 214 test1d(120,0,arch);
Chris@69 215 test1d(120,1,arch);
Chris@69 216 test1d(240,0,arch);
Chris@69 217 test1d(240,1,arch);
Chris@69 218 test1d(480,0,arch);
Chris@69 219 test1d(480,1,arch);
Chris@69 220 test1d(960,0,arch);
Chris@69 221 test1d(960,1,arch);
Chris@69 222 test1d(1920,0,arch);
Chris@69 223 test1d(1920,1,arch);
Chris@69 224 #endif
Chris@69 225 }
Chris@69 226 return ret;
Chris@69 227 }