2
** Copyright (C) 2008 Erik de Castro Lopo <erikd@mega-nerd.com>
4
** This program is free software; you can redistribute it and/or modify
5
** it under the terms of the GNU General Public License as published by
6
** the Free Software Foundation; either version 2 of the License, or
7
** (at your option) any later version.
9
** This program is distributed in the hope that it will be useful,
10
** but WITHOUT ANY WARRANTY; without even the implied warranty of
11
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
** GNU General Public License for more details.
14
** You should have received a copy of the GNU General Public License
15
** along with this program; if not, write to the Free Software
16
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
25
#include <samplerate.h>
30
#include "float_cast.h"
32
#define BUFFER_LEN (1<<17)
34
static float input [BUFFER_LEN] ;
35
static float output [BUFFER_LEN] ;
38
throughput_test (int converter, int channels, long best_throughput)
40
clock_t start_time, clock_time ;
42
long total_frames = 0, throughput ;
45
printf (" %-30s %2d ", src_get_name (converter), channels) ;
48
src_data.data_in = input ;
49
src_data.input_frames = ARRAY_LEN (input) / channels ;
51
src_data.data_out = output ;
52
src_data.output_frames = ARRAY_LEN (output) / channels ;
54
src_data.src_ratio = 0.99 ;
58
start_time = clock () ;
62
if ((error = src_simple (&src_data, converter, channels)) != 0)
63
{ puts (src_strerror (error)) ;
67
total_frames += src_data.output_frames_gen ;
69
clock_time = clock () - start_time ;
70
duration = (1.0 * clock_time) / CLOCKS_PER_SEC ;
72
while (duration < 5.0) ;
74
if (src_data.input_frames_used != src_data.input_frames)
75
{ printf ("\n\nLine %d : input frames used %ld should be %ld\n", __LINE__, src_data.input_frames_used, src_data.input_frames) ;
79
if (fabs (src_data.src_ratio * src_data.input_frames_used - src_data.output_frames_gen) > 2)
80
{ printf ("\n\nLine %d : input / output length mismatch.\n\n", __LINE__) ;
81
printf (" input len : %d\n", ARRAY_LEN (input) / channels) ;
82
printf (" output len : %ld (should be %g +/- 2)\n\n", src_data.output_frames_gen,
83
floor (0.5 + src_data.src_ratio * src_data.input_frames_used)) ;
87
throughput = lrint (floor (total_frames / duration)) ;
89
if (best_throughput == 0)
90
{ best_throughput = MAX (throughput, best_throughput) ;
91
printf ("%5.2f %10ld\n", duration, throughput) ;
94
{ best_throughput = MAX (throughput, best_throughput) ;
95
printf ("%5.2f %10ld %10ld\n", duration, throughput, best_throughput) ;
98
return best_throughput ;
99
} /* throughput_test */
103
{ const int max_channels = 10 ;
106
printf ("\n CPU : ") ;
111
" Converter Channels Duration Throughput\n"
112
" ---------------------------------------------------------------------"
115
for (k = 1 ; k <= max_channels / 2 ; k++)
116
throughput_test (SRC_SINC_FASTEST, k, 0) ;
119
for (k = 1 ; k <= max_channels / 2 ; k++)
120
throughput_test (SRC_SINC_MEDIUM_QUALITY, k, 0) ;
123
for (k = 1 ; k <= max_channels ; k++)
124
throughput_test (SRC_SINC_BEST_QUALITY, k, 0) ;
131
multi_run (int run_count)
134
printf ("\n CPU name : ") ;
139
" Converter Channels Duration Throughput Best Throughput\n"
140
" ----------------------------------------------------------------------------------------"
143
for (ch = 1 ; ch <= 5 ; ch++)
144
{ long sinc_fastest = 0, sinc_medium = 0, sinc_best = 0 ;
146
for (k = 0 ; k < run_count ; k++)
147
{ sinc_fastest = throughput_test (SRC_SINC_FASTEST, ch, sinc_fastest) ;
148
sinc_medium = throughput_test (SRC_SINC_MEDIUM_QUALITY, ch, sinc_medium) ;
149
sinc_best = throughput_test (SRC_SINC_BEST_QUALITY, ch, sinc_best) ;
153
/* Let the CPU cool down. We might be running on a laptop. */
159
" Converter Best Throughput\n"
160
" ------------------------------------------------"
163
printf (" %-30s %10ld\n", src_get_name (SRC_SINC_FASTEST), sinc_fastest) ;
164
printf (" %-30s %10ld\n", src_get_name (SRC_SINC_MEDIUM_QUALITY), sinc_medium) ;
165
printf (" %-30s %10ld\n", src_get_name (SRC_SINC_BEST_QUALITY), sinc_best) ;
172
usage_exit (const char * argv0)
173
{ const char * cptr ;
175
if ((cptr = strrchr (argv0, '/')) != NULL)
180
" %s - Single run of the throughput test.\n"
181
" %s --best-of N - Do N runs of test a print bext result.\n"
189
main (int argc, char ** argv)
192
memset (input, 0, sizeof (input)) ;
194
gen_windowed_sines (1, &freq, 1.0, input, BUFFER_LEN) ;
198
else if (argc == 3 && strcmp (argv [1], "--best-of") == 0)
199
{ int run_count = atoi (argv [2]) ;
201
if (run_count < 1 || run_count > 20)
202
{ printf ("Please be sensible. Run count should be in range (1, 10].\n") ;
206
multi_run (run_count) ;
209
usage_exit (argv [0]) ;
212
" Duration is in seconds.\n"
213
" Throughput is in frames/sec (more is better).\n"