/* * Copyright (C) 2004 Steve Harris * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * $Id: distortion-test.c $ */ #include #include #include #include #include #include #include #include #include "gdither.h" #define SIZE 16384 #ifndef M_PI #define M_PI 3.1415926 #endif float in[SIZE]; int32_t out[SIZE]; double sin_tbl[SIZE]; double sinless_tbl[SIZE]; void find_snr(GDitherType dt, const char *desc); void find_res(GDitherType dt, const char *desc); int main(int argc, char *argv[]) { int i; for (i=0; i harm_peak) harm_peak = amp[i]; if (1 || amp[i] > -100.0) { harm_sum += amp[i]; harm_cnt++; } } else { if (amp[i] > floor_peak) floor_peak = amp[i]; floor_sum += amp[i]; floor_cnt++; } //sprintf(tmp, "%f\t%g\n", 48000.0 / (double)SIZE * (double)i, amp[i]); //write(5, tmp, strlen(tmp)); //printf("%d\t%g\n", i, amp_db); } printf("%s mean harmonic resonace = %.1fdB\n", desc, harm_sum / harm_cnt - floor_sum / floor_cnt); printf("%s peak harmonic resonance = %.1fdB\n", desc, harm_peak - floor_peak); if (dt != GDitherNone && harm_sum / harm_cnt - floor_sum / floor_cnt > 6.0) { printf("excessive resonance peaks, failing\n"); exit(1); } if (dt != GDitherNone && harm_peak - floor_peak > 6.0) { printf("excessive resonance peaks, failing\n"); exit(1); } } void find_snr(GDitherType dt, const char *desc) { GDither *ds = gdither_new(dt, 1, GDither32bit, 24); int i; double sum_sq = 0.0; double val; gdither_runf(ds, 0, SIZE, in, out); for (i=0; i -141.0) { printf("excessive noise, failed\n"); exit(1); } break; case GDitherTri: if (val > -144.0) { printf("excessive noise, failed\n"); exit(1); } break; case GDitherShaped: if (val > -130.0) { printf("excessive noise, failed\n"); exit(1); } break; } } /* vi:set ts=8 sts=4 sw=4: */