Mercurial > hg > audiostuff
comparison spandsp-0.0.3/spandsp-0.0.3/tests/schedule_tests.c @ 5:f762bf195c4b
import spandsp-0.0.3
author | Peter Meerwald <pmeerw@cosy.sbg.ac.at> |
---|---|
date | Fri, 25 Jun 2010 16:00:21 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
4:26cd8f1ef0b1 | 5:f762bf195c4b |
---|---|
1 /* | |
2 * SpanDSP - a series of DSP components for telephony | |
3 * | |
4 * schedule_tests.c | |
5 * | |
6 * Written by Steve Underwood <steveu@coppice.org> | |
7 * | |
8 * Copyright (C) 2004 Steve Underwood | |
9 * | |
10 * All rights reserved. | |
11 * | |
12 * This program is free software; you can redistribute it and/or modify | |
13 * it under the terms of the GNU General Public License version 2, as | |
14 * published by the Free Software Foundation. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
24 * | |
25 * $Id: schedule_tests.c,v 1.13 2006/11/19 14:07:27 steveu Exp $ | |
26 */ | |
27 | |
28 /*! \page schedule_tests_page Event scheduler tests | |
29 \section schedule_tests_page_sec_1 What does it do? | |
30 ???. | |
31 | |
32 \section schedule_tests_page_sec_2 How does it work? | |
33 ???. | |
34 */ | |
35 | |
36 #ifdef HAVE_CONFIG_H | |
37 #include "config.h" | |
38 #endif | |
39 | |
40 #include <stdio.h> | |
41 #include <inttypes.h> | |
42 #include <stdlib.h> | |
43 #include <string.h> | |
44 #if defined(HAVE_TGMATH_H) | |
45 #include <tgmath.h> | |
46 #endif | |
47 #if defined(HAVE_MATH_H) | |
48 #include <math.h> | |
49 #endif | |
50 #include <tiffio.h> | |
51 | |
52 #include "spandsp.h" | |
53 | |
54 uint64_t when1; | |
55 uint64_t when2; | |
56 | |
57 static void callback1(span_sched_state_t *s, void *user_data) | |
58 { | |
59 int id; | |
60 uint64_t when; | |
61 | |
62 when = span_schedule_time(s); | |
63 printf("1: Callback at %f %" PRId64 "\n", (float) when/8000.0, when - when1); | |
64 if ((when - when1)) | |
65 { | |
66 printf("Callback occured at the wrong time.\n"); | |
67 exit(2); | |
68 } | |
69 id = span_schedule_event(s, 500, callback1, NULL); | |
70 when1 = when + 500*8; | |
71 when = span_schedule_next(s); | |
72 printf("1: Event %d, earliest is %" PRId64 "\n", id, when); | |
73 } | |
74 | |
75 static void callback2(span_sched_state_t *s, void *user_data) | |
76 { | |
77 int id; | |
78 uint64_t when; | |
79 | |
80 when = span_schedule_time(s); | |
81 printf("2: Callback at %f %" PRId64 "\n", (float) when/8000.0, when - when2); | |
82 id = span_schedule_event(s, 550, callback2, NULL); | |
83 if ((when - when2) != 80) | |
84 { | |
85 printf("Callback occured at the wrong time.\n"); | |
86 exit(2); | |
87 } | |
88 when2 = when + 550*8; | |
89 when = span_schedule_next(s); | |
90 printf("2: Event %d, earliest is %" PRId64 "\n", id, when); | |
91 } | |
92 | |
93 int main(int argc, char *argv[]) | |
94 { | |
95 int i; | |
96 int id1; | |
97 int id2; | |
98 span_sched_state_t sched; | |
99 uint64_t when; | |
100 | |
101 span_schedule_init(&sched); | |
102 | |
103 id1 = span_schedule_event(&sched, 500, callback1, NULL); | |
104 id2 = span_schedule_event(&sched, 550, callback2, NULL); | |
105 when1 = span_schedule_time(&sched) + 500*8; | |
106 when2 = span_schedule_time(&sched) + 550*8; | |
107 //span_schedule_del(&sched, id); | |
108 | |
109 for (i = 0; i < SAMPLE_RATE*100; i += 160) | |
110 { | |
111 span_schedule_update(&sched, 160); | |
112 } | |
113 when = span_schedule_time(&sched); | |
114 if ((when1 - when) < 0 || (when1 - when) > 4000 || (when2 - when) < 0 || (when2 - when) > 4400) | |
115 { | |
116 printf("Callback failed to occur.\n"); | |
117 exit(2); | |
118 } | |
119 span_schedule_release(&sched); | |
120 | |
121 printf("Tests passed.\n"); | |
122 return 0; | |
123 } | |
124 /*- End of function --------------------------------------------------------*/ | |
125 /*- End of file ------------------------------------------------------------*/ |