History

Progress on varispeed_test.

Erik de Castro Lopo committed 20 years ago

Commit 2a4a5151 parent 277998e2 files · +28 −117Browse files

Unified · Split

2 files
  1. tests/Makefile.am +1 −1
  2. tests/varispeed_test.c +27 −116
tests/Makefile.am+1−1
@@ -1,6 +1,6 @@
11 noinst_PROGRAMS = misc_test termination_test simple_test callback_test \
22 reset_test multi_channel_test snr_bw_test \
3− float_short_test src-evaluate benchmark
3+ float_short_test varispeed_test src-evaluate benchmark
44
55 SAMPLRATEDIR =../src
66 INCLUDES = -I$(srcdir)/$(SAMPLRATEDIR)
tests/varispeed_test.c+27−116
@@ -24,20 +24,20 @@ · 23 unmodified lines
2424
2525 #include "util.h"
2626
27−#define BUFFER_LEN ((1 << 16) - 20)
27+#define BUFFER_LEN (1 << 16)
2828
2929 static void varispeed_test (int converter) ;
3030
3131 int
3232 main (void)
3333 {
34− puts (" Zero Order Hold interpolator: ") ;
34+ printf (" Zero Order Hold interpolator : ") ;
3535 varispeed_test (SRC_ZERO_ORDER_HOLD) ;
3636
37− puts (" Linear interpolator: ") ;
37+ printf (" Linear interpolator : ") ;
3838 varispeed_test (SRC_LINEAR) ;
3939
40− puts (" Sinc interpolator: ") ;
40+ printf (" Sinc interpolator : ") ;
4141 varispeed_test (SRC_SINC_FASTEST) ;
4242
4343 return 0 ;
@@ -45,37 +45,16 @@ main (void) · 1 unmodified line
4545
4646 static void
4747 varispeed_test (int converter)
48−{ static float input [BUFFER_LEN], output [BUFFER_LEN] ;
49− double src_ratio ;
48+{ static float input [BUFFER_LEN], output [2 * BUFFER_LEN] ;
49+ double sine_freq ;
5050
5151 SRC_STATE *src_state ;
5252 SRC_DATA src_data ;
5353
54− int input_len, output_len, current_in, current_out ;
55− int k, error, terminate ;
54+ int error ;
5655
57−/* Erik */
58−for (k = 0 ; k < BUFFER_LEN ; k++) input [k] = k * 1.0 ;
59−
60− /* Calculate maximun input and output lengths. */
61− if (src_ratio >= 1.0)
62− { output_len = BUFFER_LEN ;
63− input_len = (int) floor (BUFFER_LEN / src_ratio) ;
64− }
65− else
66− { input_len = BUFFER_LEN ;
67− output_len = (int) floor (BUFFER_LEN * src_ratio) ;
68− } ;
69−
70− /* Reduce input_len by 10 so output is longer than necessary. */
71− input_len -= 20 ;
72−
73− if (output_len > BUFFER_LEN)
74− { printf ("\n\nLine %d : output_len > BUFFER_LEN\n\n", __LINE__) ;
75− exit (1) ;
76− } ;
77−
78− current_in = current_out = 0 ;
56+ sine_freq = 0.0011 ;
57+ gen_windowed_sines (1, &sine_freq, 1.0, input, ARRAY_LEN (input)) ;
7958
8059 /* Perform sample rate conversion. */
8160 if ((src_state = src_new (converter, 1, &error)) == NULL)
@@ -83,102 +62,34 @@ for (k = 0 ; k < BUFFER_LEN ; k++) input [k] = k * 1.0 ; · 1 unmodified line
8362 exit (1) ;
8463 } ;
8564
86− src_data.end_of_input = 0 ; /* Set this later. */
65+ src_data.end_of_input = 1 ;
8766
8867 src_data.data_in = input ;
68+ src_data.input_frames = ARRAY_LEN (input) ;
8969
90− src_data.src_ratio = src_ratio ;
70+ src_data.src_ratio = 3.0 ;
9171
9272 src_data.data_out = output ;
93− src_data.output_frames = ARRAY_LEN (output) / 10 ;
94−
95− terminate = 1 + (int) ceil ((src_ratio >= 1.0) ? src_ratio : 1.0 / src_ratio) ;
96−
97− while (1)
98− {
99− src_data.input_frames = next_block_length (0) ;
100− src_data.input_frames = MIN (src_data.input_frames, input_len - current_in) ;
101−
102− src_data.output_frames = ARRAY_LEN (output) - current_out ;
103− /*-Erik MIN (src_data.output_frames, output_len - current_out) ;-*/
104−
105− src_data.end_of_input = (current_in >= input_len) ? 1 : 0 ;
106−
107− if ((error = src_process (src_state, &src_data)))
108− { printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
109− printf (" src_data.input_frames : %ld\n", src_data.input_frames) ;
110− printf (" src_data.output_frames : %ld\n\n", src_data.output_frames) ;
111− exit (1) ;
112− } ;
113−
114− if (src_data.end_of_input && src_data.output_frames_gen == 0)
115− break ;
116−
117− if (src_data.input_frames_used > src_data.input_frames)
118− { printf ("\n\nLine %d : input_frames_used > input_frames\n\n", __LINE__) ;
119− printf (" src_data.input_frames : %ld\n", src_data.input_frames) ;
120− printf (" src_data.input_frames_used : %ld\n", src_data.input_frames_used) ;
121− printf (" src_data.output_frames : %ld\n", src_data.output_frames) ;
122− printf (" src_data.output_frames_gen : %ld\n\n", src_data.output_frames_gen) ;
123− exit (1) ;
124− } ;
125−
126− if (src_data.input_frames_used < 0)
127− { printf ("\n\nLine %d : input_frames_used (%ld) < 0\n\n", __LINE__, src_data.input_frames_used) ;
128− exit (1) ;
129− } ;
130−
131− if (src_data.output_frames_gen < 0)
132− { printf ("\n\nLine %d : output_frames_gen (%ld) < 0\n\n", __LINE__, src_data.output_frames_gen) ;
133− exit (1) ;
134− } ;
135−
136− current_in += src_data.input_frames_used ;
137− current_out += src_data.output_frames_gen ;
138−
139− if (current_in > input_len + terminate)
140− { printf ("\n\nLine %d : current_in (%d) > input_len (%d + %d)\n\n", __LINE__, current_in, input_len, terminate) ;
141− exit (1) ;
142− } ;
143−
144− if (current_out > output_len)
145− { printf ("\n\nLine %d : current_out (%d) > output_len (%d)\n\n", __LINE__, current_out, output_len) ;
146− exit (1) ;
147− } ;
148−
149− if (src_data.input_frames_used > input_len)
150− { printf ("\n\nLine %d : input_frames_used (%ld) > %d\n\n", __LINE__, src_data.input_frames_used, input_len) ;
151− exit (1) ;
152− } ;
153−
154− if (src_data.output_frames_gen > output_len)
155− { printf ("\n\nLine %d : output_frames_gen (%ld) > %d\n\n", __LINE__, src_data.output_frames_gen, output_len) ;
156− exit (1) ;
157− } ;
158−
159− if (src_data.data_in == NULL && src_data.output_frames_gen == 0)
160− break ;
161−
162−
163− src_data.data_in += src_data.input_frames_used ;
164− src_data.data_out += src_data.output_frames_gen ;
165− } ;
166−
167− src_state = src_delete (src_state) ;
73+ src_data.output_frames = ARRAY_LEN (output) ;
16874
169− if (fabs (current_out - src_ratio * input_len) > terminate)
170− { printf ("\n\nLine %d : bad output data length %d should be %2.1f +/- %d.\n", __LINE__,
171− current_out, src_ratio * input_len, terminate) ;
172− printf ("\tsrc_ratio : %.4f\n", src_ratio) ;
173− printf ("\tinput_len : %d\n\tinput_used : %d\n", input_len, current_in) ;
174− printf ("\toutput_len : %d\n\toutput_gen : %d\n\n", output_len, current_out) ;
75+ if ((error = src_set_ratio (src_state, 1.0 / src_data.src_ratio)))
76+ { printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
17577 exit (1) ;
17678 } ;
79+
80+ if ((error = src_process (src_state, &src_data)))
81+ { printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
82+ printf (" src_data.input_frames : %ld\n", src_data.input_frames) ;
83+ printf (" src_data.output_frames : %ld\n\n", src_data.output_frames) ;
84+ exit (1) ;
85+ } ;
86+
87+ src_state = src_delete (src_state) ;
17788
178− if (current_in != input_len)
89+ if (src_data.input_frames_used != ARRAY_LEN (input))
17990 { printf ("\n\nLine %d : unused input.\n", __LINE__) ;
180− printf ("\tinput_len : %d\n", input_len) ;
181− printf ("\tinput_frames_used : %d\n\n", current_in) ;
91+ printf ("\tinput_len : %d\n", ARRAY_LEN (input)) ;
92+ printf ("\tinput_frames_used : %ld\n\n", src_data.input_frames_used) ;
18293 exit (1) ;
18394 } ;
18495

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t