rhino/demo/c/pvrecorder/src/miniaudio/tests/test_automated/ma_test_automated_data_converter.c
Go to the documentation of this file.
1 
3 {
4  ma_result result;
6 
8  config.resampling.algorithm = algorithm;
9 
10  result = ma_data_converter_init(&config, pDataConverter);
11  if (result != MA_SUCCESS) {
12  return result;
13  }
14 
15  return MA_SUCCESS;
16 }
17 
18 #if 0
19 ma_result test_data_converter__passthrough()
20 {
21  /*
22  Notes:
23  - The isPassthrough flag should be set to true. Both the positive and negative cases need to be tested.
24  - ma_data_converter_set_rate() should fail with MA_INVALID_OPERATION.
25  - The output should be identical to the input.
26  */
27  printf("Passthrough\n");
28 
29 
30 
31  return MA_SUCCESS;
32 }
33 #endif
34 
36 {
37  ma_result result = MA_SUCCESS;
38  ma_int16 input[4096];
39  ma_int16 i;
40 
41  MA_ASSERT(frameCountPerIteration < ma_countof(input));
42 
43  /* Fill the input buffer with sequential numbers so we can get an idea on the state of things. Useful for inspecting the linear backend in particular. */
44  for (i = 0; i < ma_countof(input); i += 1) {
45  input[i] = i;
46  }
47 
48  for (i = 0; i < ma_countof(input); i += (ma_int16)frameCountPerIteration) {
49  ma_int16 output[4096];
50  ma_uint64 outputFrameCount;
51  ma_uint64 inputFrameCount;
52  ma_uint64 expectedOutputFrameCount;
53 
54  /* We retrieve the required number of input frames for the specified number of output frames, and then compare with what we actually get when reading. */
55  expectedOutputFrameCount = ma_data_converter_get_expected_output_frame_count(pDataConverter, frameCountPerIteration);
56 
57  outputFrameCount = ma_countof(output);
58  inputFrameCount = frameCountPerIteration;
59  result = ma_data_converter_process_pcm_frames(pDataConverter, input, &inputFrameCount, output, &outputFrameCount);
60  if (result != MA_SUCCESS) {
61  printf("Failed to process frames.");
62  break;
63  }
64 
65  if (outputFrameCount != expectedOutputFrameCount) {
66  printf("ERROR: Predicted vs actual output count mismatch: predicted=%d, actual=%d\n", (int)expectedOutputFrameCount, (int)outputFrameCount);
67  result = MA_ERROR;
68  }
69  }
70 
71  if (result != MA_SUCCESS) {
72  printf("FAILED\n");
73  } else {
74  printf("PASSED\n");
75  }
76 
77  return result;
78 }
79 
81 {
82  ma_result result;
83  ma_bool32 hasError = MA_FALSE;
84  ma_data_converter converter;
85 
86  result = init_data_converter(rateIn, rateOut, algorithm, &converter);
87  if (result != MA_SUCCESS) {
88  hasError = MA_TRUE;
89  }
90 
91  result = test_data_converter__resampling_expected_output_fixed_interval(&converter, frameCountPerIteration);
92 
93  ma_data_converter_uninit(&converter);
94 
95  if (hasError) {
96  return MA_ERROR;
97  } else {
98  return MA_SUCCESS;
99  }
100 }
101 
103 {
104  ma_result result;
105  ma_bool32 hasError = MA_FALSE;
106 
107  result = test_data_converter__resampling_expected_output_by_algorithm_and_rate_fixed_interval(algorithm, 44100, 48000, frameCountPerIteration);
108  if (result != MA_SUCCESS) {
109  hasError = MA_TRUE;
110  }
111 
112  result = test_data_converter__resampling_expected_output_by_algorithm_and_rate_fixed_interval(algorithm, 48000, 44100, frameCountPerIteration);
113  if (result != MA_SUCCESS) {
114  hasError = MA_TRUE;
115  }
116 
117 
118  result = test_data_converter__resampling_expected_output_by_algorithm_and_rate_fixed_interval(algorithm, 44100, 192000, frameCountPerIteration);
119  if (result != MA_SUCCESS) {
120  hasError = MA_TRUE;
121  }
122 
123  result = test_data_converter__resampling_expected_output_by_algorithm_and_rate_fixed_interval(algorithm, 192000, 44100, frameCountPerIteration);
124  if (result != MA_SUCCESS) {
125  hasError = MA_TRUE;
126  }
127 
128  if (hasError) {
129  return MA_ERROR;
130  } else {
131  return MA_SUCCESS;
132  }
133 }
134 
136 {
137  ma_result result;
138  ma_bool32 hasError = MA_FALSE;
139 
141  if (result != MA_SUCCESS) {
142  hasError = MA_TRUE;
143  }
144 
146  if (result != MA_SUCCESS) {
147  hasError = MA_TRUE;
148  }
149 
151  if (result != MA_SUCCESS) {
152  hasError = MA_TRUE;
153  }
154 
155  if (hasError) {
156  return MA_ERROR;
157  } else {
158  return MA_SUCCESS;
159  }
160 }
161 
163 {
164  ma_result result;
165  ma_bool32 hasError = MA_FALSE;
166 
167  printf("Linear\n");
169  if (result != MA_SUCCESS) {
170  hasError = MA_TRUE;
171  }
172 
173  printf("Speex\n");
175  if (result != 0) {
176  hasError = MA_TRUE;
177  }
178 
179  if (hasError) {
180  return MA_ERROR;
181  } else {
182  return MA_SUCCESS;
183  }
184 }
185 
186 
187 
189 {
190  ma_result result = MA_SUCCESS;
191  ma_int16 input[4096];
192  ma_int16 i;
193 
194  MA_ASSERT(frameCountPerIteration < ma_countof(input));
195 
196  /* Fill the input buffer with sequential numbers so we can get an idea on the state of things. Useful for inspecting the linear backend in particular. */
197  for (i = 0; i < ma_countof(input); i += 1) {
198  input[i] = i;
199  }
200 
201  for (i = 0; i < ma_countof(input); i += (ma_int16)frameCountPerIteration) {
202  ma_int16 output[4096];
203  ma_uint64 outputFrameCount;
204  ma_uint64 inputFrameCount;
205  ma_uint64 requiredInputFrameCount;
206 
207  /* We retrieve the required number of input frames for the specified number of output frames, and then compare with what we actually get when reading. */
208  requiredInputFrameCount = ma_data_converter_get_required_input_frame_count(pDataConverter, frameCountPerIteration);
209 
210  outputFrameCount = frameCountPerIteration;
211  inputFrameCount = ma_countof(input);
212  result = ma_data_converter_process_pcm_frames(pDataConverter, input, &inputFrameCount, output, &outputFrameCount);
213  if (result != MA_SUCCESS) {
214  printf("Failed to process frames.");
215  break;
216  }
217 
218  if (inputFrameCount != requiredInputFrameCount) {
219  printf("ERROR: Predicted vs actual input count mismatch: predicted=%d, actual=%d\n", (int)requiredInputFrameCount, (int)inputFrameCount);
220  result = MA_ERROR;
221  }
222  }
223 
224  if (result != MA_SUCCESS) {
225  printf("FAILED\n");
226  } else {
227  printf("PASSED\n");
228  }
229 
230  return result;
231 }
232 
234 {
235  ma_result result;
236  ma_bool32 hasError = MA_FALSE;
237  ma_data_converter converter;
238 
239  result = init_data_converter(rateIn, rateOut, algorithm, &converter);
240  if (result != MA_SUCCESS) {
241  hasError = MA_TRUE;
242  }
243 
244  result = test_data_converter__resampling_required_input_fixed_interval(&converter, frameCountPerIteration);
245 
246  ma_data_converter_uninit(&converter);
247 
248  if (hasError) {
249  return MA_ERROR;
250  } else {
251  return MA_SUCCESS;
252  }
253 }
254 
256 {
257  ma_result result;
258  ma_bool32 hasError = MA_FALSE;
259 
260  result = test_data_converter__resampling_required_input_by_algorithm_and_rate_fixed_interval(algorithm, 44100, 48000, frameCountPerIteration);
261  if (result != MA_SUCCESS) {
262  hasError = MA_TRUE;
263  }
264 
265  result = test_data_converter__resampling_required_input_by_algorithm_and_rate_fixed_interval(algorithm, 48000, 44100, frameCountPerIteration);
266  if (result != MA_SUCCESS) {
267  hasError = MA_TRUE;
268  }
269 
270 
271  result = test_data_converter__resampling_required_input_by_algorithm_and_rate_fixed_interval(algorithm, 44100, 192000, frameCountPerIteration);
272  if (result != MA_SUCCESS) {
273  hasError = MA_TRUE;
274  }
275 
276  result = test_data_converter__resampling_required_input_by_algorithm_and_rate_fixed_interval(algorithm, 192000, 44100, frameCountPerIteration);
277  if (result != MA_SUCCESS) {
278  hasError = MA_TRUE;
279  }
280 
281  if (hasError) {
282  return MA_ERROR;
283  } else {
284  return MA_SUCCESS;
285  }
286 }
287 
289 {
290  ma_result result;
291  ma_bool32 hasError = MA_FALSE;
292 
294  if (result != MA_SUCCESS) {
295  hasError = MA_TRUE;
296  }
297 
299  if (result != MA_SUCCESS) {
300  hasError = MA_TRUE;
301  }
302 
304  if (result != MA_SUCCESS) {
305  hasError = MA_TRUE;
306  }
307 
308  if (hasError) {
309  return MA_ERROR;
310  } else {
311  return MA_SUCCESS;
312  }
313 }
314 
316 {
317  ma_result result;
318  ma_bool32 hasError = MA_FALSE;
319 
320  printf("Linear\n");
322  if (result != MA_SUCCESS) {
323  hasError = MA_TRUE;
324  }
325 
326  printf("Speex\n");
328  if (result != MA_SUCCESS) {
329  hasError = MA_TRUE;
330  }
331 
332  if (hasError) {
333  return MA_ERROR;
334  } else {
335  return MA_SUCCESS;
336  }
337 }
338 
339 
340 
341 
343 {
344  ma_result result;
345  ma_bool32 hasError = MA_FALSE;
346 
348  if (result != MA_SUCCESS) {
349  hasError = MA_TRUE;
350  }
351 
353  if (result != MA_SUCCESS) {
354  hasError = MA_TRUE;
355  }
356 
357  if (hasError) {
358  return MA_ERROR;
359  } else {
360  return MA_SUCCESS;
361  }
362 }
363 
364 
365 int test_entry__data_converter(int argc, char** argv)
366 {
367  ma_result result;
368  ma_bool32 hasError = MA_FALSE;
369 
370  (void)argc;
371  (void)argv;
372 
373 #if 0
374  result = test_data_converter__passthrough();
375  if (result != MA_SUCCESS) {
376  hasError = MA_TRUE;
377  }
378 #endif
379 
381  if (result != MA_SUCCESS) {
382  hasError = MA_TRUE;
383  }
384 
385 
386  if (hasError) {
387  return -1;
388  } else {
389  return 0;
390  }
391 }
test_data_converter__resampling
ma_result test_data_converter__resampling()
Definition: rhino/demo/c/pvrecorder/src/miniaudio/tests/test_automated/ma_test_automated_data_converter.c:342
ma_uint64
uint64_t ma_uint64
Definition: porcupine/demo/c/dr_libs/tests/external/miniaudio/miniaudio.h:1505
init_data_converter
ma_result init_data_converter(ma_uint32 rateIn, ma_uint32 rateOut, ma_resample_algorithm algorithm, ma_data_converter *pDataConverter)
Definition: rhino/demo/c/pvrecorder/src/miniaudio/tests/test_automated/ma_test_automated_data_converter.c:2
MA_FALSE
#define MA_FALSE
Definition: porcupine/demo/c/dr_libs/tests/external/miniaudio/miniaudio.h:1531
ma_data_converter_get_required_input_frame_count
ma_uint64 ma_data_converter_get_required_input_frame_count(ma_data_converter *pConverter, ma_uint64 outputFrameCount)
test_data_converter__resampling_required_input_by_algorithm_fixed_interval
ma_result test_data_converter__resampling_required_input_by_algorithm_fixed_interval(ma_resample_algorithm algorithm, ma_uint64 frameCountPerIteration)
Definition: rhino/demo/c/pvrecorder/src/miniaudio/tests/test_automated/ma_test_automated_data_converter.c:255
test_data_converter__resampling_expected_output_by_algorithm_and_rate_fixed_interval
ma_result test_data_converter__resampling_expected_output_by_algorithm_and_rate_fixed_interval(ma_resample_algorithm algorithm, ma_uint32 rateIn, ma_uint32 rateOut, ma_uint64 frameCountPerIteration)
Definition: rhino/demo/c/pvrecorder/src/miniaudio/tests/test_automated/ma_test_automated_data_converter.c:80
ma_resample_algorithm
ma_resample_algorithm
Definition: porcupine/demo/c/dr_libs/tests/external/miniaudio/miniaudio.h:2234
ma_bool32
ma_uint32 ma_bool32
Definition: porcupine/demo/c/dr_libs/tests/external/miniaudio/miniaudio.h:1529
ma_countof
#define ma_countof(x)
Definition: porcupine/demo/c/pvrecorder/src/miniaudio/extras/miniaudio_split/miniaudio.c:776
ma_int16
int16_t ma_int16
Definition: porcupine/demo/c/dr_libs/tests/external/miniaudio/miniaudio.h:1500
ma_data_converter_process_pcm_frames
ma_result ma_data_converter_process_pcm_frames(ma_data_converter *pConverter, const void *pFramesIn, ma_uint64 *pFrameCountIn, void *pFramesOut, ma_uint64 *pFrameCountOut)
Definition: porcupine/demo/c/pvrecorder/src/miniaudio/extras/miniaudio_split/miniaudio.c:35303
test_data_converter__resampling_expected_output
ma_result test_data_converter__resampling_expected_output()
Definition: rhino/demo/c/pvrecorder/src/miniaudio/tests/test_automated/ma_test_automated_data_converter.c:162
test_data_converter__resampling_required_input
ma_result test_data_converter__resampling_required_input()
Definition: rhino/demo/c/pvrecorder/src/miniaudio/tests/test_automated/ma_test_automated_data_converter.c:315
ma_result
int ma_result
Definition: porcupine/demo/c/dr_libs/tests/external/miniaudio/miniaudio.h:1658
test_data_converter__resampling_expected_output_by_algorithm_fixed_interval
ma_result test_data_converter__resampling_expected_output_by_algorithm_fixed_interval(ma_resample_algorithm algorithm, ma_uint64 frameCountPerIteration)
Definition: rhino/demo/c/pvrecorder/src/miniaudio/tests/test_automated/ma_test_automated_data_converter.c:102
ma_data_converter_config
Definition: porcupine/demo/c/dr_libs/tests/external/miniaudio/miniaudio.h:2397
ma_data_converter_get_expected_output_frame_count
ma_uint64 ma_data_converter_get_expected_output_frame_count(ma_data_converter *pConverter, ma_uint64 inputFrameCount)
test_entry__data_converter
int test_entry__data_converter(int argc, char **argv)
Definition: rhino/demo/c/pvrecorder/src/miniaudio/tests/test_automated/ma_test_automated_data_converter.c:365
ma_format_s16
@ ma_format_s16
Definition: porcupine/demo/c/dr_libs/tests/external/miniaudio/miniaudio.h:1787
test_data_converter__resampling_expected_output_fixed_interval
ma_result test_data_converter__resampling_expected_output_fixed_interval(ma_data_converter *pDataConverter, ma_uint64 frameCountPerIteration)
Definition: rhino/demo/c/pvrecorder/src/miniaudio/tests/test_automated/ma_test_automated_data_converter.c:35
MA_ASSERT
#define MA_ASSERT(condition)
Definition: porcupine/demo/c/pvrecorder/src/miniaudio/extras/miniaudio_split/miniaudio.c:770
test_data_converter__resampling_required_input_by_algorithm
ma_result test_data_converter__resampling_required_input_by_algorithm(ma_resample_algorithm algorithm)
Definition: rhino/demo/c/pvrecorder/src/miniaudio/tests/test_automated/ma_test_automated_data_converter.c:288
ma_uint32
uint32_t ma_uint32
Definition: porcupine/demo/c/dr_libs/tests/external/miniaudio/miniaudio.h:1503
test_data_converter__resampling_required_input_fixed_interval
ma_result test_data_converter__resampling_required_input_fixed_interval(ma_data_converter *pDataConverter, ma_uint64 frameCountPerIteration)
Definition: rhino/demo/c/pvrecorder/src/miniaudio/tests/test_automated/ma_test_automated_data_converter.c:188
ma_resample_algorithm_linear
@ ma_resample_algorithm_linear
Definition: porcupine/demo/c/dr_libs/tests/external/miniaudio/miniaudio.h:2236
MA_ERROR
#define MA_ERROR
Definition: porcupine/demo/c/dr_libs/tests/external/miniaudio/miniaudio.h:1660
ma_data_converter_config_init
ma_data_converter_config ma_data_converter_config_init(ma_format formatIn, ma_format formatOut, ma_uint32 channelsIn, ma_uint32 channelsOut, ma_uint32 sampleRateIn, ma_uint32 sampleRateOut)
Definition: porcupine/demo/c/pvrecorder/src/miniaudio/extras/miniaudio_split/miniaudio.c:34530
python.test_porcupine.argv
argv
Definition: test_porcupine.py:158
ma_data_converter_uninit
void ma_data_converter_uninit(ma_data_converter *pConverter)
Definition: porcupine/demo/c/pvrecorder/src/miniaudio/extras/miniaudio_split/miniaudio.c:34671
test_data_converter__resampling_expected_output_by_algorithm
ma_result test_data_converter__resampling_expected_output_by_algorithm(ma_resample_algorithm algorithm)
Definition: rhino/demo/c/pvrecorder/src/miniaudio/tests/test_automated/ma_test_automated_data_converter.c:135
ma_resample_algorithm_speex
@ ma_resample_algorithm_speex
Definition: porcupine/demo/c/dr_libs/tests/external/miniaudio/miniaudio.h:2237
config
static sai_transceiver_t config
Definition: imxrt1050/imxrt1050-evkb/source/pv_audio_rec.c:75
MA_TRUE
#define MA_TRUE
Definition: porcupine/demo/c/dr_libs/tests/external/miniaudio/miniaudio.h:1530
MA_SUCCESS
#define MA_SUCCESS
Definition: porcupine/demo/c/dr_libs/tests/external/miniaudio/miniaudio.h:1659
ma_data_converter
Definition: porcupine/demo/c/dr_libs/tests/external/miniaudio/miniaudio.h:2429
ma_data_converter_init
ma_result ma_data_converter_init(const ma_data_converter_config *pConfig, ma_data_converter *pConverter)
Definition: porcupine/demo/c/pvrecorder/src/miniaudio/extras/miniaudio_split/miniaudio.c:34543
test_data_converter__resampling_required_input_by_algorithm_and_rate_fixed_interval
ma_result test_data_converter__resampling_required_input_by_algorithm_and_rate_fixed_interval(ma_resample_algorithm algorithm, ma_uint32 rateIn, ma_uint32 rateOut, ma_uint64 frameCountPerIteration)
Definition: rhino/demo/c/pvrecorder/src/miniaudio/tests/test_automated/ma_test_automated_data_converter.c:233


picovoice_driver
Author(s):
autogenerated on Fri Apr 1 2022 02:13:56