]>
iEval git - audio-libsamplerate.git/blob - varispeed_test.c
92ba260e23d2d3763066e1ffab4ee9f56bf4d862
2 ** Copyright (c) 2006-2016, Erik de Castro Lopo <erikd@mega-nerd.com>
3 ** All rights reserved.
5 ** This code is released under 2-clause BSD license. Please see the
6 ** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
16 #include <samplerate.h>
23 #define fftw_cleanup()
26 #define BUFFER_LEN (1 << 16)
28 static void varispeed_test (int converter
, double target_snr
) ;
34 printf (" Zero Order Hold interpolator : ") ;
35 varispeed_test (SRC_ZERO_ORDER_HOLD
, 10.0) ;
37 printf (" Linear interpolator : ") ;
38 varispeed_test (SRC_LINEAR
, 10.0) ;
40 printf (" Sinc interpolator : ") ;
41 varispeed_test (SRC_SINC_FASTEST
, 115.0) ;
50 varispeed_test (int converter
, double target_snr
)
51 { static float input
[BUFFER_LEN
], output
[BUFFER_LEN
] ;
52 double sine_freq
, snr
;
54 SRC_STATE
*src_state
;
57 int input_len
, error
;
59 memset (input
, 0, sizeof (input
)) ;
61 input_len
= ARRAY_LEN (input
) / 2 ;
64 gen_windowed_sines (1, &sine_freq
, 1.0, input
, input_len
) ;
66 /* Perform sample rate conversion. */
67 if ((src_state
= src_new (converter
, 1, &error
)) == NULL
)
68 { printf ("\n\nLine %d : src_new() failed : %s\n\n", __LINE__
, src_strerror (error
)) ;
72 src_data
.end_of_input
= 1 ;
74 src_data
.data_in
= input
;
75 src_data
.input_frames
= input_len
;
77 src_data
.src_ratio
= 3.0 ;
79 src_data
.data_out
= output
;
80 src_data
.output_frames
= ARRAY_LEN (output
) ;
82 if ((error
= src_set_ratio (src_state
, 1.0 / src_data
.src_ratio
)))
83 { printf ("\n\nLine %d : %s\n\n", __LINE__
, src_strerror (error
)) ;
87 if ((error
= src_process (src_state
, &src_data
)))
88 { printf ("\n\nLine %d : %s\n\n", __LINE__
, src_strerror (error
)) ;
89 printf (" src_data.input_frames : %ld\n", src_data
.input_frames
) ;
90 printf (" src_data.output_frames : %ld\n\n", src_data
.output_frames
) ;
94 if (src_data
.input_frames_used
!= input_len
)
95 { printf ("\n\nLine %d : unused input.\n", __LINE__
) ;
96 printf ("\tinput_len : %d\n", input_len
) ;
97 printf ("\tinput_frames_used : %ld\n\n", src_data
.input_frames_used
) ;
101 /* Copy the last output to the input. */
102 memcpy (input
, output
, sizeof (input
)) ;
103 reverse_data (input
, src_data
.output_frames_gen
) ;
105 if ((error
= src_reset (src_state
)))
106 { printf ("\n\nLine %d : %s\n\n", __LINE__
, src_strerror (error
)) ;
110 src_data
.end_of_input
= 1 ;
112 src_data
.data_in
= input
;
113 input_len
= src_data
.input_frames
= src_data
.output_frames_gen
;
115 src_data
.data_out
= output
;
116 src_data
.output_frames
= ARRAY_LEN (output
) ;
118 if ((error
= src_set_ratio (src_state
, 1.0 / src_data
.src_ratio
)))
119 { printf ("\n\nLine %d : %s\n\n", __LINE__
, src_strerror (error
)) ;
123 if ((error
= src_process (src_state
, &src_data
)))
124 { printf ("\n\nLine %d : %s\n\n", __LINE__
, src_strerror (error
)) ;
125 printf (" src_data.input_frames : %ld\n", src_data
.input_frames
) ;
126 printf (" src_data.output_frames : %ld\n\n", src_data
.output_frames
) ;
130 if (src_data
.input_frames_used
!= input_len
)
131 { printf ("\n\nLine %d : unused input.\n", __LINE__
) ;
132 printf ("\tinput_len : %d\n", input_len
) ;
133 printf ("\tinput_frames_used : %ld\n\n", src_data
.input_frames_used
) ;
137 src_state
= src_delete (src_state
) ;
139 snr
= calculate_snr (output
, src_data
.output_frames_gen
, 1) ;
141 if (target_snr
> snr
)
142 { printf ("\n\nLine %d : snr (%3.1f) does not meet target (%3.1f)\n\n", __LINE__
, snr
, target_snr
) ;
143 save_oct_float ("varispeed.mat", input
, src_data
.input_frames
, output
, src_data
.output_frames_gen
) ;
150 } /* varispeed_test */
This page took 0.052529 seconds and 3 git commands to generate.