]>
iEval git - audio-libsamplerate.git/blob - float_short_test.c
16cf682212546ce5fa99e4681ef0742b63687fdd
2 ** Copyright (c) 2003-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
13 #include <samplerate.h>
17 #define BUFFER_LEN 10000
19 static void float_to_short_test (void) ;
20 static void short_to_float_test (void) ;
22 static void float_to_int_test (void) ;
23 static void int_to_float_test (void) ;
30 float_to_short_test () ;
31 short_to_float_test () ;
33 float_to_int_test () ;
34 int_to_float_test () ;
41 /*=====================================================================================
45 float_to_short_test (void)
47 static float fpos
[] =
48 { 0.95, 0.99, 1.0, 1.01, 1.1, 2.0, 11.1, 111.1, 2222.2, 33333.3
50 static float fneg
[] =
51 { -0.95, -0.99, -1.0, -1.01, -1.1, -2.0, -11.1, -111.1, -2222.2, -33333.3
54 static short out
[MAX (ARRAY_LEN (fpos
), ARRAY_LEN (fneg
))] ;
58 printf ("\tfloat_to_short_test ............................. ") ;
60 src_float_to_short_array (fpos
, out
, ARRAY_LEN (fpos
)) ;
62 for (k
= 0 ; k
< ARRAY_LEN (fpos
) ; k
++)
64 { printf ("\n\n\tLine %d : out [%d] == %d\n", __LINE__
, k
, out
[k
]) ;
68 src_float_to_short_array (fneg
, out
, ARRAY_LEN (fneg
)) ;
70 for (k
= 0 ; k
< ARRAY_LEN (fneg
) ; k
++)
72 { printf ("\n\n\tLine %d : out [%d] == %d\n", __LINE__
, k
, out
[k
]) ;
79 } /* float_to_short_test */
81 /*-------------------------------------------------------------------------------------
85 short_to_float_test (void)
87 static short input
[BUFFER_LEN
] ;
88 static short output
[BUFFER_LEN
] ;
89 static float temp
[BUFFER_LEN
] ;
93 printf ("\tshort_to_float_test ............................. ") ;
95 for (k
= 0 ; k
< ARRAY_LEN (input
) ; k
++)
96 input
[k
] = (k
* 0x8000) / ARRAY_LEN (input
) ;
98 src_short_to_float_array (input
, temp
, ARRAY_LEN (temp
)) ;
99 src_float_to_short_array (temp
, output
, ARRAY_LEN (output
)) ;
101 for (k
= 0 ; k
< ARRAY_LEN (input
) ; k
++)
102 if (ABS (input
[k
] - output
[k
]) > 0)
103 { printf ("\n\n\tLine %d : index %d %d -> %d\n", __LINE__
, k
, input
[k
], output
[k
]) ;
110 } /* short_to_float_test */
112 /*=====================================================================================
116 float_to_int_test (void)
118 static float fpos
[] =
119 { 0.95, 0.99, 1.0, 1.01, 1.1, 2.0, 11.1, 111.1, 2222.2, 33333.3
121 static float fneg
[] =
122 { -0.95, -0.99, -1.0, -1.01, -1.1, -2.0, -11.1, -111.1, -2222.2, -33333.3
125 static int out
[MAX (ARRAY_LEN (fpos
), ARRAY_LEN (fneg
))] ;
129 printf ("\tfloat_to_int_test ............................... ") ;
131 src_float_to_int_array (fpos
, out
, ARRAY_LEN (fpos
)) ;
133 for (k
= 0 ; k
< ARRAY_LEN (fpos
) ; k
++)
134 if (out
[k
] < 30000 * 0x10000)
135 { printf ("\n\n\tLine %d : out [%d] == %d\n", __LINE__
, k
, out
[k
]) ;
139 src_float_to_int_array (fneg
, out
, ARRAY_LEN (fneg
)) ;
141 for (k
= 0 ; k
< ARRAY_LEN (fneg
) ; k
++)
142 if (out
[k
] > -30000 * 0x1000)
143 { printf ("\n\n\tLine %d : out [%d] == %d\n", __LINE__
, k
, out
[k
]) ;
150 } /* float_to_int_test */
152 /*-------------------------------------------------------------------------------------
156 int_to_float_test (void)
158 static int input
[BUFFER_LEN
] ;
159 static int output
[BUFFER_LEN
] ;
160 static float temp
[BUFFER_LEN
] ;
164 printf ("\tint_to_float_test ............................... ") ;
166 for (k
= 0 ; k
< ARRAY_LEN (input
) ; k
++)
167 input
[k
] = (k
* 0x80000000) / ARRAY_LEN (input
) ;
169 src_int_to_float_array (input
, temp
, ARRAY_LEN (temp
)) ;
170 src_float_to_int_array (temp
, output
, ARRAY_LEN (output
)) ;
172 for (k
= 0 ; k
< ARRAY_LEN (input
) ; k
++)
173 if (ABS (input
[k
] - output
[k
]) > 0)
174 { printf ("\n\n\tLine %d : index %d %d -> %d\n", __LINE__
, k
, input
[k
], output
[k
]) ;
181 } /* int_to_float_test */
This page took 0.051184 seconds and 3 git commands to generate.