cannam@85: /* cannam@85: ** Copyright (C) 2002-2011 Erik de Castro Lopo cannam@85: ** cannam@85: ** This program is free software; you can redistribute it and/or modify cannam@85: ** it under the terms of the GNU General Public License as published by cannam@85: ** the Free Software Foundation; either version 2 of the License, or cannam@85: ** (at your option) any later version. cannam@85: ** cannam@85: ** This program is distributed in the hope that it will be useful, cannam@85: ** but WITHOUT ANY WARRANTY; without even the implied warranty of cannam@85: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the cannam@85: ** GNU General Public License for more details. cannam@85: ** cannam@85: ** You should have received a copy of the GNU General Public License cannam@85: ** along with this program; if not, write to the Free Software cannam@85: ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. cannam@85: */ cannam@85: cannam@85: #include cannam@85: #include cannam@85: #include cannam@85: cannam@85: #include cannam@85: cannam@85: #include "util.h" cannam@85: cannam@85: static void name_test (void) ; cannam@85: static void error_test (void) ; cannam@85: static void src_ratio_test (void) ; cannam@85: static void zero_input_test (int converter) ; cannam@85: cannam@85: int cannam@85: main (void) cannam@85: { cannam@85: puts ("") ; cannam@85: cannam@85: printf (" version : %s\n\n", src_get_version ()) ; cannam@85: cannam@85: /* Current max converter is SRC_LINEAR. */ cannam@85: name_test () ; cannam@85: cannam@85: error_test () ; cannam@85: cannam@85: src_ratio_test () ; cannam@85: cannam@85: zero_input_test (SRC_ZERO_ORDER_HOLD) ; cannam@85: zero_input_test (SRC_LINEAR) ; cannam@85: zero_input_test (SRC_SINC_FASTEST) ; cannam@85: cannam@85: puts ("") ; cannam@85: return 0 ; cannam@85: } /* main */ cannam@85: cannam@85: static void cannam@85: name_test (void) cannam@85: { const char *name ; cannam@85: int k = 0 ; cannam@85: cannam@85: puts (" name_test :") ; cannam@85: cannam@85: while (1) cannam@85: { name = src_get_name (k) ; cannam@85: if (name == NULL) cannam@85: break ; cannam@85: printf ("\tName %d : %s\n", k, name) ; cannam@85: printf ("\tDesc %d : %s\n", k, src_get_description (k)) ; cannam@85: k ++ ; cannam@85: } ; cannam@85: cannam@85: puts ("") ; cannam@85: cannam@85: return ; cannam@85: } /* name_test */ cannam@85: cannam@85: /*------------------------------------------------------------------------------ cannam@85: */ cannam@85: cannam@85: typedef struct cannam@85: { double ratio ; cannam@85: int should_pass ; cannam@85: } RATIO_TEST ; cannam@85: cannam@85: static RATIO_TEST ratio_test [] = cannam@85: { { 1.0 / 256.1, 0 }, cannam@85: { 1.0 / 256.0, 1 }, cannam@85: { 1.0, 1 }, cannam@85: { 256.0, 1 }, cannam@85: { 256.1, 0 }, cannam@85: { -1.0, 0 } cannam@85: } ; cannam@85: cannam@85: static void cannam@85: src_ratio_test (void) cannam@85: { int k ; cannam@85: cannam@85: puts (" src_ratio_test (SRC ratio must be in range [1/256, 256]):" ) ; cannam@85: cannam@85: cannam@85: for (k = 0 ; k < ARRAY_LEN (ratio_test) ; k++) cannam@85: { if (ratio_test [k].should_pass && src_is_valid_ratio (ratio_test [k].ratio) == 0) cannam@85: { printf ("\n\nLine %d : SRC ratio %f should have passed.\n\n", __LINE__, ratio_test [k].ratio) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: if (! ratio_test [k].should_pass && src_is_valid_ratio (ratio_test [k].ratio) != 0) cannam@85: { printf ("\n\nLine %d : SRC ratio %f should not have passed.\n\n", __LINE__, ratio_test [k].ratio) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: printf ("\t SRC ratio (%9.5f) : %s ................... ok\n", ratio_test [k].ratio, cannam@85: (ratio_test [k].should_pass ? "pass" : "fail")) ; cannam@85: } ; cannam@85: cannam@85: puts ("") ; cannam@85: cannam@85: return ; cannam@85: } /* src_ratio_test */ cannam@85: cannam@85: static void cannam@85: error_test (void) cannam@85: { const char *errorstr ; cannam@85: int k, errors = 0 ; cannam@85: cannam@85: puts (" error_test :") ; cannam@85: cannam@85: for (k = 0 ; 1 ; k++) cannam@85: { errorstr = src_strerror (k) ; cannam@85: printf ("\t%-2d : %s\n", k, errorstr) ; cannam@85: if (errorstr == NULL) cannam@85: { errors ++ ; cannam@85: continue ; cannam@85: } ; cannam@85: if (strstr (errorstr, "Placeholder.") == errorstr) cannam@85: break ; cannam@85: } ; cannam@85: cannam@85: if (errors != 0) cannam@85: { printf ("\n\nLine %d : Missing error numbers above.\n\n", __LINE__) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: puts ("") ; cannam@85: cannam@85: return ; cannam@85: } /* error_test */ cannam@85: cannam@85: static void cannam@85: zero_input_test (int converter) cannam@85: { SRC_DATA data ; cannam@85: SRC_STATE *state ; cannam@85: float out [100] ; cannam@85: int error ; cannam@85: cannam@85: printf (" %s (%-26s) ........ ", __func__, src_get_name (converter)) ; cannam@85: fflush (stdout) ; cannam@85: cannam@85: if ((state = src_new (converter, 1, &error)) == NULL) cannam@85: { printf ("\n\nLine %d : src_new failed : %s.\n\n", __LINE__, src_strerror (error)) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: data.data_in = (float *) 0xdeadbeef ; cannam@85: data.input_frames = 0 ; cannam@85: data.data_out = out ; cannam@85: data.output_frames = ARRAY_LEN (out) ; cannam@85: data.end_of_input = 0 ; cannam@85: data.src_ratio = 1.0 ; cannam@85: cannam@85: if ((error = src_process (state, &data))) cannam@85: { printf ("\n\nLine %d : src_new failed : %s.\n\n", __LINE__, src_strerror (error)) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: state = src_delete (state) ; cannam@85: cannam@85: puts ("ok") ; cannam@85: } /* zero_input_test */