annotate src/libsamplerate-0.1.8/tests/callback_hang_test.c @ 23:619f715526df sv_v2.1

Update Vamp plugin SDK to 2.5
author Chris Cannam
date Thu, 09 May 2013 10:52:46 +0100
parents c7265573341e
children
rev   line source
Chris@0 1 /*
Chris@0 2 ** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
Chris@0 3 **
Chris@0 4 ** This program is free software; you can redistribute it and/or modify
Chris@0 5 ** it under the terms of the GNU General Public License as published by
Chris@0 6 ** the Free Software Foundation; either version 2 of the License, or
Chris@0 7 ** (at your option) any later version.
Chris@0 8 **
Chris@0 9 ** This program is distributed in the hope that it will be useful,
Chris@0 10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 ** GNU General Public License for more details.
Chris@0 13 **
Chris@0 14 ** You should have received a copy of the GNU General Public License
Chris@0 15 ** along with this program; if not, write to the Free Software
Chris@0 16 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
Chris@0 17 */
Chris@0 18
Chris@0 19 #include "config.h"
Chris@0 20
Chris@0 21 #include <stdio.h>
Chris@0 22 #include <stdlib.h>
Chris@0 23 #include <unistd.h>
Chris@0 24 #include <math.h>
Chris@0 25
Chris@0 26 #if HAVE_ALARM && HAVE_SIGNAL && HAVE_SIGALRM
Chris@0 27
Chris@0 28 #include <signal.h>
Chris@0 29
Chris@0 30 #include <samplerate.h>
Chris@0 31
Chris@0 32 #include "util.h"
Chris@0 33
Chris@0 34 #define SHORT_BUFFER_LEN 512
Chris@0 35 #define LONG_BUFFER_LEN (1 << 14)
Chris@0 36
Chris@0 37 typedef struct
Chris@0 38 { double ratio ;
Chris@0 39 int count ;
Chris@0 40 } SRC_PAIR ;
Chris@0 41
Chris@0 42 static void callback_hang_test (int converter) ;
Chris@0 43
Chris@0 44 static void alarm_handler (int number) ;
Chris@0 45 static long input_callback (void *cb_data, float **data) ;
Chris@0 46
Chris@0 47
Chris@0 48 int
Chris@0 49 main (void)
Chris@0 50 {
Chris@0 51 /* Set up SIGALRM handler. */
Chris@0 52 signal (SIGALRM, alarm_handler) ;
Chris@0 53
Chris@0 54 puts ("") ;
Chris@0 55 callback_hang_test (SRC_ZERO_ORDER_HOLD) ;
Chris@0 56 callback_hang_test (SRC_LINEAR) ;
Chris@0 57 callback_hang_test (SRC_SINC_FASTEST) ;
Chris@0 58 puts ("") ;
Chris@0 59
Chris@0 60 return 0 ;
Chris@0 61 } /* main */
Chris@0 62
Chris@0 63
Chris@0 64 static void
Chris@0 65 callback_hang_test (int converter)
Chris@0 66 { static float output [LONG_BUFFER_LEN] ;
Chris@0 67 static SRC_PAIR pairs [] =
Chris@0 68 {
Chris@0 69 { 1.2, 5 }, { 1.1, 1 }, { 1.0, 1 }, { 3.0, 1 }, { 2.0, 1 }, { 0.3, 1 },
Chris@0 70 { 1.2, 0 }, { 1.1, 10 }, { 1.0, 1 }
Chris@0 71 } ;
Chris@0 72
Chris@0 73
Chris@0 74 SRC_STATE *src_state ;
Chris@0 75
Chris@0 76 double src_ratio = 1.0 ;
Chris@0 77 int k, error ;
Chris@0 78
Chris@0 79 printf ("\tcallback_hang_test (%-28s) ....... ", src_get_name (converter)) ;
Chris@0 80 fflush (stdout) ;
Chris@0 81
Chris@0 82 /* Perform sample rate conversion. */
Chris@0 83 src_state = src_callback_new (input_callback, converter, 1, &error, NULL) ;
Chris@0 84 if (src_state == NULL)
Chris@0 85 { printf ("\n\nLine %d : src_callback_new () failed : %s\n\n", __LINE__, src_strerror (error)) ;
Chris@0 86 exit (1) ;
Chris@0 87 } ;
Chris@0 88
Chris@0 89 for (k = 0 ; k < ARRAY_LEN (pairs) ; k++)
Chris@0 90 { alarm (1) ;
Chris@0 91 src_ratio = pairs [k].ratio ;
Chris@0 92 src_callback_read (src_state, src_ratio, pairs [k].count, output) ;
Chris@0 93 } ;
Chris@0 94
Chris@0 95 src_state = src_delete (src_state) ;
Chris@0 96
Chris@0 97 alarm (0) ;
Chris@0 98 puts ("ok") ;
Chris@0 99
Chris@0 100 return ;
Chris@0 101 } /* callback_hang_test */
Chris@0 102
Chris@0 103 static void
Chris@0 104 alarm_handler (int number)
Chris@0 105 {
Chris@0 106 (void) number ;
Chris@0 107 printf ("\n\n Error : Hang inside src_callback_read() detected. Exiting!\n\n") ;
Chris@0 108 exit (1) ;
Chris@0 109 } /* alarm_handler */
Chris@0 110
Chris@0 111 static long
Chris@0 112 input_callback (void *cb_data, float **data)
Chris@0 113 {
Chris@0 114 static float buffer [20] ;
Chris@0 115
Chris@0 116 (void) cb_data ;
Chris@0 117 *data = buffer ;
Chris@0 118
Chris@0 119 return ARRAY_LEN (buffer) ;
Chris@0 120 } /* input_callback */
Chris@0 121
Chris@0 122 #else
Chris@0 123
Chris@0 124 int
Chris@0 125 main (void)
Chris@0 126 {
Chris@0 127 puts ("\tCan't run this test on this platform.") ;
Chris@0 128 return 0 ;
Chris@0 129 } /* main */
Chris@0 130
Chris@0 131 #endif