annotate src/libsamplerate-0.1.8/tests/misc_test.c @ 169:223a55898ab9 tip default

Add null config files
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 02 Mar 2020 14:03:47 +0000
parents 545efbb81310
children
rev   line source
cannam@85 1 /*
cannam@85 2 ** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
cannam@85 3 **
cannam@85 4 ** This program is free software; you can redistribute it and/or modify
cannam@85 5 ** it under the terms of the GNU General Public License as published by
cannam@85 6 ** the Free Software Foundation; either version 2 of the License, or
cannam@85 7 ** (at your option) any later version.
cannam@85 8 **
cannam@85 9 ** This program is distributed in the hope that it will be useful,
cannam@85 10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
cannam@85 11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cannam@85 12 ** GNU General Public License for more details.
cannam@85 13 **
cannam@85 14 ** You should have received a copy of the GNU General Public License
cannam@85 15 ** along with this program; if not, write to the Free Software
cannam@85 16 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
cannam@85 17 */
cannam@85 18
cannam@85 19 #include <stdio.h>
cannam@85 20 #include <stdlib.h>
cannam@85 21 #include <string.h>
cannam@85 22
cannam@85 23 #include <samplerate.h>
cannam@85 24
cannam@85 25 #include "util.h"
cannam@85 26
cannam@85 27 static void name_test (void) ;
cannam@85 28 static void error_test (void) ;
cannam@85 29 static void src_ratio_test (void) ;
cannam@85 30 static void zero_input_test (int converter) ;
cannam@85 31
cannam@85 32 int
cannam@85 33 main (void)
cannam@85 34 {
cannam@85 35 puts ("") ;
cannam@85 36
cannam@85 37 printf (" version : %s\n\n", src_get_version ()) ;
cannam@85 38
cannam@85 39 /* Current max converter is SRC_LINEAR. */
cannam@85 40 name_test () ;
cannam@85 41
cannam@85 42 error_test () ;
cannam@85 43
cannam@85 44 src_ratio_test () ;
cannam@85 45
cannam@85 46 zero_input_test (SRC_ZERO_ORDER_HOLD) ;
cannam@85 47 zero_input_test (SRC_LINEAR) ;
cannam@85 48 zero_input_test (SRC_SINC_FASTEST) ;
cannam@85 49
cannam@85 50 puts ("") ;
cannam@85 51 return 0 ;
cannam@85 52 } /* main */
cannam@85 53
cannam@85 54 static void
cannam@85 55 name_test (void)
cannam@85 56 { const char *name ;
cannam@85 57 int k = 0 ;
cannam@85 58
cannam@85 59 puts (" name_test :") ;
cannam@85 60
cannam@85 61 while (1)
cannam@85 62 { name = src_get_name (k) ;
cannam@85 63 if (name == NULL)
cannam@85 64 break ;
cannam@85 65 printf ("\tName %d : %s\n", k, name) ;
cannam@85 66 printf ("\tDesc %d : %s\n", k, src_get_description (k)) ;
cannam@85 67 k ++ ;
cannam@85 68 } ;
cannam@85 69
cannam@85 70 puts ("") ;
cannam@85 71
cannam@85 72 return ;
cannam@85 73 } /* name_test */
cannam@85 74
cannam@85 75 /*------------------------------------------------------------------------------
cannam@85 76 */
cannam@85 77
cannam@85 78 typedef struct
cannam@85 79 { double ratio ;
cannam@85 80 int should_pass ;
cannam@85 81 } RATIO_TEST ;
cannam@85 82
cannam@85 83 static RATIO_TEST ratio_test [] =
cannam@85 84 { { 1.0 / 256.1, 0 },
cannam@85 85 { 1.0 / 256.0, 1 },
cannam@85 86 { 1.0, 1 },
cannam@85 87 { 256.0, 1 },
cannam@85 88 { 256.1, 0 },
cannam@85 89 { -1.0, 0 }
cannam@85 90 } ;
cannam@85 91
cannam@85 92 static void
cannam@85 93 src_ratio_test (void)
cannam@85 94 { int k ;
cannam@85 95
cannam@85 96 puts (" src_ratio_test (SRC ratio must be in range [1/256, 256]):" ) ;
cannam@85 97
cannam@85 98
cannam@85 99 for (k = 0 ; k < ARRAY_LEN (ratio_test) ; k++)
cannam@85 100 { if (ratio_test [k].should_pass && src_is_valid_ratio (ratio_test [k].ratio) == 0)
cannam@85 101 { printf ("\n\nLine %d : SRC ratio %f should have passed.\n\n", __LINE__, ratio_test [k].ratio) ;
cannam@85 102 exit (1) ;
cannam@85 103 } ;
cannam@85 104 if (! ratio_test [k].should_pass && src_is_valid_ratio (ratio_test [k].ratio) != 0)
cannam@85 105 { printf ("\n\nLine %d : SRC ratio %f should not have passed.\n\n", __LINE__, ratio_test [k].ratio) ;
cannam@85 106 exit (1) ;
cannam@85 107 } ;
cannam@85 108 printf ("\t SRC ratio (%9.5f) : %s ................... ok\n", ratio_test [k].ratio,
cannam@85 109 (ratio_test [k].should_pass ? "pass" : "fail")) ;
cannam@85 110 } ;
cannam@85 111
cannam@85 112 puts ("") ;
cannam@85 113
cannam@85 114 return ;
cannam@85 115 } /* src_ratio_test */
cannam@85 116
cannam@85 117 static void
cannam@85 118 error_test (void)
cannam@85 119 { const char *errorstr ;
cannam@85 120 int k, errors = 0 ;
cannam@85 121
cannam@85 122 puts (" error_test :") ;
cannam@85 123
cannam@85 124 for (k = 0 ; 1 ; k++)
cannam@85 125 { errorstr = src_strerror (k) ;
cannam@85 126 printf ("\t%-2d : %s\n", k, errorstr) ;
cannam@85 127 if (errorstr == NULL)
cannam@85 128 { errors ++ ;
cannam@85 129 continue ;
cannam@85 130 } ;
cannam@85 131 if (strstr (errorstr, "Placeholder.") == errorstr)
cannam@85 132 break ;
cannam@85 133 } ;
cannam@85 134
cannam@85 135 if (errors != 0)
cannam@85 136 { printf ("\n\nLine %d : Missing error numbers above.\n\n", __LINE__) ;
cannam@85 137 exit (1) ;
cannam@85 138 } ;
cannam@85 139
cannam@85 140 puts ("") ;
cannam@85 141
cannam@85 142 return ;
cannam@85 143 } /* error_test */
cannam@85 144
cannam@85 145 static void
cannam@85 146 zero_input_test (int converter)
cannam@85 147 { SRC_DATA data ;
cannam@85 148 SRC_STATE *state ;
cannam@85 149 float out [100] ;
cannam@85 150 int error ;
cannam@85 151
cannam@85 152 printf (" %s (%-26s) ........ ", __func__, src_get_name (converter)) ;
cannam@85 153 fflush (stdout) ;
cannam@85 154
cannam@85 155 if ((state = src_new (converter, 1, &error)) == NULL)
cannam@85 156 { printf ("\n\nLine %d : src_new failed : %s.\n\n", __LINE__, src_strerror (error)) ;
cannam@85 157 exit (1) ;
cannam@85 158 } ;
cannam@85 159
cannam@85 160 data.data_in = (float *) 0xdeadbeef ;
cannam@85 161 data.input_frames = 0 ;
cannam@85 162 data.data_out = out ;
cannam@85 163 data.output_frames = ARRAY_LEN (out) ;
cannam@85 164 data.end_of_input = 0 ;
cannam@85 165 data.src_ratio = 1.0 ;
cannam@85 166
cannam@85 167 if ((error = src_process (state, &data)))
cannam@85 168 { printf ("\n\nLine %d : src_new failed : %s.\n\n", __LINE__, src_strerror (error)) ;
cannam@85 169 exit (1) ;
cannam@85 170 } ;
cannam@85 171
cannam@85 172 state = src_delete (state) ;
cannam@85 173
cannam@85 174 puts ("ok") ;
cannam@85 175 } /* zero_input_test */