| 1 |
/* |
| 2 |
** Copyright (c) 2002-2016, Erik de Castro Lopo <[email protected]> |
| 3 |
** All rights reserved. |
| 4 |
** |
| 5 |
** This code is released under 2-clause BSD license. Please see the |
| 6 |
** file at : https://github.com/libsndfile/libsamplerate/blob/master/COPYING |
| 7 |
*/ |
| 8 |
|
| 9 |
#ifdef HAVE_CONFIG_H |
| 10 |
#include "config.h" |
| 11 |
#endif |
| 12 |
|
| 13 |
#include <stdio.h> |
| 14 |
#include <stdlib.h> |
| 15 |
#include <string.h> |
| 16 |
|
| 17 |
#include <samplerate.h> |
| 18 |
|
| 19 |
#include "util.h" |
| 20 |
|
| 21 |
#define BUFFER_LEN (1 << 16) |
| 22 |
#define NUM_CHANNELS 1 |
| 23 |
|
| 24 |
static void |
| 25 |
nullptr_test (int converter) |
| 26 |
{ static float input [BUFFER_LEN * NUM_CHANNELS] ; |
| 27 |
static float output [BUFFER_LEN * NUM_CHANNELS] ; |
| 28 |
|
| 29 |
SRC_STATE* src_state ; |
| 30 |
SRC_DATA src_data, src_data2 ; |
| 31 |
|
| 32 |
int error ; |
| 33 |
|
| 34 |
printf (" nullptr_test (%-28s) ....... ", src_get_name (converter)) ; |
| 35 |
fflush (stdout) ; |
| 36 |
|
| 37 |
memset (input, 0, sizeof (input)) ; |
| 38 |
memset (output, 0, sizeof (output)) ; |
| 39 |
|
| 40 |
if ((src_state = src_new (converter, NUM_CHANNELS, &error)) == NULL) |
| 41 |
{ printf ("\n\nLine %d : src_new() failed : %s\n\n", __LINE__, src_strerror (error)) ; |
| 42 |
exit (1) ; |
| 43 |
} ; |
| 44 |
|
| 45 |
src_data.src_ratio = 1.1 ; |
| 46 |
src_data.input_frames = BUFFER_LEN ; |
| 47 |
src_data.output_frames = BUFFER_LEN ; |
| 48 |
src_data.data_in = input ; |
| 49 |
src_data.data_out = output ; |
| 50 |
src_data.output_frames_gen = 0 ; |
| 51 |
|
| 52 |
if ((error = src_process (src_state, &src_data))) |
| 53 |
{ printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ; |
| 54 |
exit (1) ; |
| 55 |
} ; |
| 56 |
|
| 57 |
//Input is zero-length |
| 58 |
src_data2 = src_data; |
| 59 |
src_data2.data_in = NULL; |
| 60 |
src_data2.input_frames = 0; |
| 61 |
|
| 62 |
if ((error = src_process (src_state, &src_data2))) |
| 63 |
{ printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ; |
| 64 |
exit (1) ; |
| 65 |
} ; |
| 66 |
|
| 67 |
//Output is zero-length |
| 68 |
src_data2 = src_data; |
| 69 |
src_data2.data_out = NULL; |
| 70 |
src_data2.output_frames = 0; |
| 71 |
|
| 72 |
if ((error = src_process (src_state, &src_data2))) |
| 73 |
{ printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ; |
| 74 |
exit (1) ; |
| 75 |
} ; |
| 76 |
|
| 77 |
//Input and output are zero-length |
| 78 |
src_data2 = src_data; |
| 79 |
src_data2.data_in = NULL; |
| 80 |
src_data2.data_out = NULL; |
| 81 |
src_data2.input_frames = 0; |
| 82 |
src_data2.output_frames = 0; |
| 83 |
|
| 84 |
if ((error = src_process (src_state, &src_data2))) |
| 85 |
{ printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ; |
| 86 |
exit (1) ; |
| 87 |
} ; |
| 88 |
|
| 89 |
|
| 90 |
src_state = src_delete (src_state) ; |
| 91 |
|
| 92 |
puts ("ok") ; |
| 93 |
} /* nullptr_test */ |
| 94 |
|
| 95 |
int |
| 96 |
main (void) |
| 97 |
{ |
| 98 |
puts(""); |
| 99 |
|
| 100 |
nullptr_test (SRC_ZERO_ORDER_HOLD) ; |
| 101 |
nullptr_test (SRC_LINEAR) ; |
| 102 |
#ifdef ENABLE_SINC_FAST_CONVERTER |
| 103 |
nullptr_test (SRC_SINC_FASTEST) ; |
| 104 |
#endif |
| 105 |
puts(""); |
| 106 |
|
| 107 |
return 0 ; |
| 108 |
} /* main */ |