File: nullptr_test.c

package info (click to toggle)
libsamplerate 0.2.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,444 kB
  • sloc: ansic: 371,377; sh: 121; makefile: 111
file content (108 lines) | stat: -rw-r--r-- 2,465 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
** Copyright (c) 2002-2016, Erik de Castro Lopo <erikd@mega-nerd.com>
** All rights reserved.
**
** This code is released under 2-clause BSD license. Please see the
** file at : https://github.com/libsndfile/libsamplerate/blob/master/COPYING
*/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <samplerate.h>

#include "util.h"

#define	BUFFER_LEN		(1 << 16)
#define NUM_CHANNELS 	1

static void
nullptr_test (int converter)
{	static float input [BUFFER_LEN * NUM_CHANNELS] ;
	static float output [BUFFER_LEN * NUM_CHANNELS] ;

	SRC_STATE* src_state ;
	SRC_DATA src_data, src_data2 ;

	int error ;

	printf ("        nullptr_test        (%-28s) ....... ", src_get_name (converter)) ;
	fflush (stdout) ;

	memset (input, 0, sizeof (input)) ;
	memset (output, 0, sizeof (output)) ;

	if ((src_state = src_new (converter, NUM_CHANNELS, &error)) == NULL)
	{	printf ("\n\nLine %d : src_new() failed : %s\n\n", __LINE__, src_strerror (error)) ;
		exit (1) ;
		} ;

	src_data.src_ratio = 1.1 ;
	src_data.input_frames = BUFFER_LEN ;
	src_data.output_frames = BUFFER_LEN ;
	src_data.data_in = input ;
	src_data.data_out = output ;
	src_data.output_frames_gen = 0 ;

	if ((error = src_process (src_state, &src_data)))
	{	printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
		exit (1) ;
		} ;

	//Input is zero-length
	src_data2 = src_data;
	src_data2.data_in = NULL;
	src_data2.input_frames = 0;

	if ((error = src_process (src_state, &src_data2)))
	{	printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
		exit (1) ;
		} ;

	//Output is zero-length
	src_data2 = src_data;
	src_data2.data_out = NULL;
	src_data2.output_frames = 0;

	if ((error = src_process (src_state, &src_data2)))
	{	printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
		exit (1) ;
		} ;

	//Input and output are zero-length
	src_data2 = src_data;
	src_data2.data_in = NULL;
	src_data2.data_out = NULL;
	src_data2.input_frames = 0;
	src_data2.output_frames = 0;

	if ((error = src_process (src_state, &src_data2)))
	{	printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
		exit (1) ;
		} ;


	src_state = src_delete (src_state) ;

	puts ("ok") ;
} /* nullptr_test */

int
main (void)
{
	puts("");

	nullptr_test (SRC_ZERO_ORDER_HOLD) ;
	nullptr_test (SRC_LINEAR) ;
#ifdef ENABLE_SINC_FAST_CONVERTER
	nullptr_test (SRC_SINC_FASTEST) ;
#endif
	puts("");

	return 0 ;
} /* main */