annotate src/opus-1.3/celt/tests/test_unit_dft.c @ 83:ae30d91d2ffe

Replace these with versions built using an older toolset (so as to avoid ABI compatibilities when linking on Ubuntu 14.04 for packaging purposes)
author Chris Cannam
date Fri, 07 Feb 2020 11:51:13 +0000
parents 7aeed7906520
children
rev   line source
Chris@69 1 /* Copyright (c) 2008 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 "stack_alloc.h"
Chris@69 35 #include "kiss_fft.h"
Chris@69 36 #include "mathops.h"
Chris@69 37 #include "modes.h"
Chris@69 38
Chris@69 39 #ifndef M_PI
Chris@69 40 #define M_PI 3.141592653
Chris@69 41 #endif
Chris@69 42
Chris@69 43 int ret = 0;
Chris@69 44
Chris@69 45 void check(kiss_fft_cpx * in,kiss_fft_cpx * out,int nfft,int isinverse)
Chris@69 46 {
Chris@69 47 int bin,k;
Chris@69 48 double errpow=0,sigpow=0, snr;
Chris@69 49
Chris@69 50 for (bin=0;bin<nfft;++bin) {
Chris@69 51 double ansr = 0;
Chris@69 52 double ansi = 0;
Chris@69 53 double difr;
Chris@69 54 double difi;
Chris@69 55
Chris@69 56 for (k=0;k<nfft;++k) {
Chris@69 57 double phase = -2*M_PI*bin*k/nfft;
Chris@69 58 double re = cos(phase);
Chris@69 59 double im = sin(phase);
Chris@69 60 if (isinverse)
Chris@69 61 im = -im;
Chris@69 62
Chris@69 63 if (!isinverse)
Chris@69 64 {
Chris@69 65 re /= nfft;
Chris@69 66 im /= nfft;
Chris@69 67 }
Chris@69 68
Chris@69 69 ansr += in[k].r * re - in[k].i * im;
Chris@69 70 ansi += in[k].r * im + in[k].i * re;
Chris@69 71 }
Chris@69 72 /*printf ("%d %d ", (int)ansr, (int)ansi);*/
Chris@69 73 difr = ansr - out[bin].r;
Chris@69 74 difi = ansi - out[bin].i;
Chris@69 75 errpow += difr*difr + difi*difi;
Chris@69 76 sigpow += ansr*ansr+ansi*ansi;
Chris@69 77 }
Chris@69 78 snr = 10*log10(sigpow/errpow);
Chris@69 79 printf("nfft=%d inverse=%d,snr = %f\n",nfft,isinverse,snr );
Chris@69 80 if (snr<60) {
Chris@69 81 printf( "** poor snr: %f ** \n", snr);
Chris@69 82 ret = 1;
Chris@69 83 }
Chris@69 84 }
Chris@69 85
Chris@69 86 void test1d(int nfft,int isinverse,int arch)
Chris@69 87 {
Chris@69 88 size_t buflen = sizeof(kiss_fft_cpx)*nfft;
Chris@69 89 kiss_fft_cpx *in;
Chris@69 90 kiss_fft_cpx *out;
Chris@69 91 int k;
Chris@69 92 #ifdef CUSTOM_MODES
Chris@69 93 kiss_fft_state *cfg = opus_fft_alloc(nfft,0,0,arch);
Chris@69 94 #else
Chris@69 95 int id;
Chris@69 96 const kiss_fft_state *cfg;
Chris@69 97 CELTMode *mode = opus_custom_mode_create(48000, 960, NULL);
Chris@69 98 if (nfft == 480) id = 0;
Chris@69 99 else if (nfft == 240) id = 1;
Chris@69 100 else if (nfft == 120) id = 2;
Chris@69 101 else if (nfft == 60) id = 3;
Chris@69 102 else return;
Chris@69 103 cfg = mode->mdct.kfft[id];
Chris@69 104 #endif
Chris@69 105
Chris@69 106 in = (kiss_fft_cpx*)malloc(buflen);
Chris@69 107 out = (kiss_fft_cpx*)malloc(buflen);
Chris@69 108
Chris@69 109 for (k=0;k<nfft;++k) {
Chris@69 110 in[k].r = (rand() % 32767) - 16384;
Chris@69 111 in[k].i = (rand() % 32767) - 16384;
Chris@69 112 }
Chris@69 113
Chris@69 114 for (k=0;k<nfft;++k) {
Chris@69 115 in[k].r *= 32768;
Chris@69 116 in[k].i *= 32768;
Chris@69 117 }
Chris@69 118
Chris@69 119 if (isinverse)
Chris@69 120 {
Chris@69 121 for (k=0;k<nfft;++k) {
Chris@69 122 in[k].r /= nfft;
Chris@69 123 in[k].i /= nfft;
Chris@69 124 }
Chris@69 125 }
Chris@69 126
Chris@69 127 /*for (k=0;k<nfft;++k) printf("%d %d ", in[k].r, in[k].i);printf("\n");*/
Chris@69 128
Chris@69 129 if (isinverse)
Chris@69 130 opus_ifft(cfg,in,out, arch);
Chris@69 131 else
Chris@69 132 opus_fft(cfg,in,out, arch);
Chris@69 133
Chris@69 134 /*for (k=0;k<nfft;++k) printf("%d %d ", out[k].r, out[k].i);printf("\n");*/
Chris@69 135
Chris@69 136 check(in,out,nfft,isinverse);
Chris@69 137
Chris@69 138 free(in);
Chris@69 139 free(out);
Chris@69 140 #ifdef CUSTOM_MODES
Chris@69 141 opus_fft_free(cfg, arch);
Chris@69 142 #endif
Chris@69 143 }
Chris@69 144
Chris@69 145 int main(int argc,char ** argv)
Chris@69 146 {
Chris@69 147 ALLOC_STACK;
Chris@69 148 int arch = opus_select_arch();
Chris@69 149
Chris@69 150 if (argc>1) {
Chris@69 151 int k;
Chris@69 152 for (k=1;k<argc;++k) {
Chris@69 153 test1d(atoi(argv[k]),0,arch);
Chris@69 154 test1d(atoi(argv[k]),1,arch);
Chris@69 155 }
Chris@69 156 }else{
Chris@69 157 test1d(32,0,arch);
Chris@69 158 test1d(32,1,arch);
Chris@69 159 test1d(128,0,arch);
Chris@69 160 test1d(128,1,arch);
Chris@69 161 test1d(256,0,arch);
Chris@69 162 test1d(256,1,arch);
Chris@69 163 #ifndef RADIX_TWO_ONLY
Chris@69 164 test1d(36,0,arch);
Chris@69 165 test1d(36,1,arch);
Chris@69 166 test1d(50,0,arch);
Chris@69 167 test1d(50,1,arch);
Chris@69 168 test1d(60,0,arch);
Chris@69 169 test1d(60,1,arch);
Chris@69 170 test1d(120,0,arch);
Chris@69 171 test1d(120,1,arch);
Chris@69 172 test1d(240,0,arch);
Chris@69 173 test1d(240,1,arch);
Chris@69 174 test1d(480,0,arch);
Chris@69 175 test1d(480,1,arch);
Chris@69 176 #endif
Chris@69 177 }
Chris@69 178 return ret;
Chris@69 179 }