Revert 45697:
[reactos.git] / lib / 3rdparty / libsamplerate / common.h
1 /*
2 ** Copyright (C) 2002-2008 Erik de Castro Lopo <erikd@mega-nerd.com>
3 **
4 ** This program is free software; you can redistribute it and/or modify
5 ** it under the terms of the GNU General Public License as published by
6 ** the Free Software Foundation; either version 2 of the License, or
7 ** (at your option) any later version.
8 **
9 ** This program is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ** GNU General Public License for more details.
13 **
14 ** You should have received a copy of the GNU General Public License
15 ** along with this program; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 /*
20 ** This code is part of Secret Rabibt Code aka libsamplerate. A commercial
21 ** use license for this code is available, please see:
22 ** http://www.mega-nerd.com/SRC/procedure.html
23 */
24
25 #ifndef COMMON_H_INCLUDED
26 #define COMMON_H_INCLUDED
27
28 #ifdef HAVE_STDINT_H
29 #include <stdint.h>
30 #elif (SIZEOF_INT == 4)
31 typedef int int32_t ;
32 #elif (SIZEOF_LONG == 4)
33 typedef long int32_t ;
34 #endif
35
36 #define SRC_MAX_RATIO 256
37 #define SRC_MAX_RATIO_STR "256"
38
39 #define SRC_MIN_RATIO_DIFF (1e-20)
40
41 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
42 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
43
44 #define ARRAY_LEN(x) ((int) (sizeof (x) / sizeof ((x) [0])))
45 #define OFFSETOF(type,member) ((int) (&((type*) 0)->member))
46
47 #define MAKE_MAGIC(a,b,c,d,e,f) ((a) + ((b) << 4) + ((c) << 8) + ((d) << 12) + ((e) << 16) + ((f) << 20))
48
49 #ifdef __GNUC__
50 # define WARN_UNUSED __attribute__ ((warn_unused_result))
51 #else
52 # define WARN_UNUSED
53 #endif
54
55
56 #include "samplerate.h"
57
58 enum
59 { SRC_FALSE = 0,
60 SRC_TRUE = 1,
61
62 SRC_MODE_PROCESS = 555,
63 SRC_MODE_CALLBACK = 556
64 } ;
65
66 enum
67 { SRC_ERR_NO_ERROR = 0,
68
69 SRC_ERR_MALLOC_FAILED,
70 SRC_ERR_BAD_STATE,
71 SRC_ERR_BAD_DATA,
72 SRC_ERR_BAD_DATA_PTR,
73 SRC_ERR_NO_PRIVATE,
74 SRC_ERR_BAD_SRC_RATIO,
75 SRC_ERR_BAD_PROC_PTR,
76 SRC_ERR_SHIFT_BITS,
77 SRC_ERR_FILTER_LEN,
78 SRC_ERR_BAD_CONVERTER,
79 SRC_ERR_BAD_CHANNEL_COUNT,
80 SRC_ERR_SINC_BAD_BUFFER_LEN,
81 SRC_ERR_SIZE_INCOMPATIBILITY,
82 SRC_ERR_BAD_PRIV_PTR,
83 SRC_ERR_BAD_SINC_STATE,
84 SRC_ERR_DATA_OVERLAP,
85 SRC_ERR_BAD_CALLBACK,
86 SRC_ERR_BAD_MODE,
87 SRC_ERR_NULL_CALLBACK,
88 SRC_ERR_NO_VARIABLE_RATIO,
89 SRC_ERR_SINC_PREPARE_DATA_BAD_LEN,
90
91 /* This must be the last error number. */
92 SRC_ERR_MAX_ERROR
93 } ;
94
95 typedef struct SRC_PRIVATE_tag
96 { double last_ratio, last_position ;
97
98 int error ;
99 int channels ;
100
101 /* SRC_MODE_PROCESS or SRC_MODE_CALLBACK */
102 int mode ;
103
104 /* Pointer to data to converter specific data. */
105 void *private_data ;
106
107 /* Varispeed process function. */
108 int (*vari_process) (struct SRC_PRIVATE_tag *psrc, SRC_DATA *data) ;
109
110 /* Constant speed process function. */
111 int (*const_process) (struct SRC_PRIVATE_tag *psrc, SRC_DATA *data) ;
112
113 /* State reset. */
114 void (*reset) (struct SRC_PRIVATE_tag *psrc) ;
115
116 /* Data specific to SRC_MODE_CALLBACK. */
117 src_callback_t callback_func ;
118 void *user_callback_data ;
119 long saved_frames ;
120 float *saved_data ;
121 } SRC_PRIVATE ;
122
123 /* In src_sinc.c */
124 const char* sinc_get_name (int src_enum) ;
125 const char* sinc_get_description (int src_enum) ;
126
127 int sinc_set_converter (SRC_PRIVATE *psrc, int src_enum) ;
128
129 /* In src_linear.c */
130 const char* linear_get_name (int src_enum) ;
131 const char* linear_get_description (int src_enum) ;
132
133 int linear_set_converter (SRC_PRIVATE *psrc, int src_enum) ;
134
135 /* In src_zoh.c */
136 const char* zoh_get_name (int src_enum) ;
137 const char* zoh_get_description (int src_enum) ;
138
139 int zoh_set_converter (SRC_PRIVATE *psrc, int src_enum) ;
140
141 /*----------------------------------------------------------
142 ** Common static inline functions.
143 */
144
145 static inline double
146 fmod_one (double x)
147 { double res ;
148
149 res = x - lrint (x) ;
150 if (res < 0.0)
151 return res + 1.0 ;
152
153 return res ;
154 } /* fmod_one */
155
156 #endif /* COMMON_H_INCLUDED */
157