Mercurial > hg > sv-dependency-builds
comparison src/libsamplerate-0.1.9/tests/callback_hang_test.c @ 41:481f5f8c5634
Current libsamplerate source
author | Chris Cannam |
---|---|
date | Tue, 18 Oct 2016 13:24:45 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
40:1df64224f5ac | 41:481f5f8c5634 |
---|---|
1 /* | |
2 ** Copyright (c) 2002-2016, Erik de Castro Lopo <erikd@mega-nerd.com> | |
3 ** All rights reserved. | |
4 ** | |
5 ** This code is released under 2-clause BSD license. Please see the | |
6 ** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING | |
7 */ | |
8 | |
9 #include "config.h" | |
10 | |
11 #include <stdio.h> | |
12 #include <stdlib.h> | |
13 #include <unistd.h> | |
14 #include <math.h> | |
15 | |
16 #if HAVE_ALARM && HAVE_SIGNAL && HAVE_SIGALRM | |
17 | |
18 #include <signal.h> | |
19 | |
20 #include <samplerate.h> | |
21 | |
22 #include "util.h" | |
23 | |
24 #define SHORT_BUFFER_LEN 512 | |
25 #define LONG_BUFFER_LEN (1 << 14) | |
26 | |
27 typedef struct | |
28 { double ratio ; | |
29 int count ; | |
30 } SRC_PAIR ; | |
31 | |
32 static void callback_hang_test (int converter) ; | |
33 | |
34 static void alarm_handler (int number) ; | |
35 static long input_callback (void *cb_data, float **data) ; | |
36 | |
37 | |
38 int | |
39 main (void) | |
40 { | |
41 /* Set up SIGALRM handler. */ | |
42 signal (SIGALRM, alarm_handler) ; | |
43 | |
44 puts ("") ; | |
45 callback_hang_test (SRC_ZERO_ORDER_HOLD) ; | |
46 callback_hang_test (SRC_LINEAR) ; | |
47 callback_hang_test (SRC_SINC_FASTEST) ; | |
48 puts ("") ; | |
49 | |
50 return 0 ; | |
51 } /* main */ | |
52 | |
53 | |
54 static void | |
55 callback_hang_test (int converter) | |
56 { static float output [LONG_BUFFER_LEN] ; | |
57 static SRC_PAIR pairs [] = | |
58 { | |
59 { 1.2, 5 }, { 1.1, 1 }, { 1.0, 1 }, { 3.0, 1 }, { 2.0, 1 }, { 0.3, 1 }, | |
60 { 1.2, 0 }, { 1.1, 10 }, { 1.0, 1 } | |
61 } ; | |
62 | |
63 | |
64 SRC_STATE *src_state ; | |
65 | |
66 double src_ratio = 1.0 ; | |
67 int k, error ; | |
68 | |
69 printf ("\tcallback_hang_test (%-28s) ....... ", src_get_name (converter)) ; | |
70 fflush (stdout) ; | |
71 | |
72 /* Perform sample rate conversion. */ | |
73 src_state = src_callback_new (input_callback, converter, 1, &error, NULL) ; | |
74 if (src_state == NULL) | |
75 { printf ("\n\nLine %d : src_callback_new () failed : %s\n\n", __LINE__, src_strerror (error)) ; | |
76 exit (1) ; | |
77 } ; | |
78 | |
79 for (k = 0 ; k < ARRAY_LEN (pairs) ; k++) | |
80 { alarm (1) ; | |
81 src_ratio = pairs [k].ratio ; | |
82 src_callback_read (src_state, src_ratio, pairs [k].count, output) ; | |
83 } ; | |
84 | |
85 src_state = src_delete (src_state) ; | |
86 | |
87 alarm (0) ; | |
88 puts ("ok") ; | |
89 | |
90 return ; | |
91 } /* callback_hang_test */ | |
92 | |
93 static void | |
94 alarm_handler (int number) | |
95 { | |
96 (void) number ; | |
97 printf ("\n\n Error : Hang inside src_callback_read() detected. Exiting!\n\n") ; | |
98 exit (1) ; | |
99 } /* alarm_handler */ | |
100 | |
101 static long | |
102 input_callback (void *cb_data, float **data) | |
103 { | |
104 static float buffer [20] ; | |
105 | |
106 (void) cb_data ; | |
107 *data = buffer ; | |
108 | |
109 return ARRAY_LEN (buffer) ; | |
110 } /* input_callback */ | |
111 | |
112 #else | |
113 | |
114 int | |
115 main (void) | |
116 { | |
117 puts ("\tCan't run this test on this platform.") ; | |
118 return 0 ; | |
119 } /* main */ | |
120 | |
121 #endif |