1 /********************************************************************
3 * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
5 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
6 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
8 * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 *
9 * by the Xiph.Org Foundation http://www.xiph.org/ *
11 ********************************************************************
13 function: vorbis coded test suite using vorbisfile
14 last mod: $Id: test.c 13293 2007-07-24 00:09:47Z erikd $
16 ********************************************************************/
23 #include "write_read.h"
27 #define MAX(a,b) ((a) > (b) ? (a) : (b))
30 static int check_output (const float * data_in, unsigned len, float allowable);
34 static float data_out [DATA_LEN] ;
35 static float data_in [DATA_LEN] ;
37 /* Do safest and most used sample rates first. */
38 int sample_rates [] = { 44100, 48000, 32000, 22050, 16000, 96000 } ;
43 gen_windowed_sine (data_out, ARRAY_LEN (data_out), 0.95);
47 printf("\nTesting %d channel%s\n\n",ch,ch==1?"":"s");
49 for (k = 0 ; k < ARRAY_LEN (sample_rates); k ++) {
51 snprintf (filename, sizeof (filename), "vorbis_%dch_q%.1f_%u.ogg", ch,q*10,sample_rates [k]);
53 printf (" %-20s : ", filename);
56 /* Set to know value. */
57 set_data_in (data_in, ARRAY_LEN (data_in), 3.141);
59 write_vorbis_data_or_die (filename, sample_rates [k], q, data_out, ARRAY_LEN (data_out),ch);
60 read_vorbis_data_or_die (filename, sample_rates [k], data_in, ARRAY_LEN (data_in));
62 if (check_output (data_in, ARRAY_LEN (data_in), (.15f - .1f*q)) != 0)
80 check_output (const float * data_in, unsigned len, float allowable)
85 for (k = 0 ; k < len ; k++) {
86 float temp = fabs (data_in [k]);
87 max_abs = MAX (max_abs, temp);
90 if (max_abs < 0.95-allowable) {
91 printf ("Error : max_abs (%f) too small.\n", max_abs);
93 } else if (max_abs > .95+allowable) {
94 printf ("Error : max_abs (%f) too big.\n", max_abs);