1 #ifndef PCM_H
2 #define PCM_H
3 
4 /********************************************************
5  Audio Tools, a module and set of tools for manipulating audio data
6  Copyright (C) 2007-2014  Brian Langenberger
7 
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21 *******************************************************/
22 
23 
24 /******************
25   FrameList Object
26 *******************/
27 
28 #ifndef STANDALONE
29 typedef struct {
30     PyObject_HEAD;
31 
32     unsigned int frames; /*the total number of PCM frames in this FrameList
33                            aka the total number of rows in the "samples" array*/
34     unsigned int channels; /*the total number of channels in this FrameList
35                              aka the total number of columns in "samples*/
36     unsigned int bits_per_sample; /*the maximum size of each sample, in bits*/
37 
38     int* samples;            /*the actual sample data itself,
39                                stored raw as 32-bit signed integers*/
40     unsigned samples_length; /*the total number of samples
41                                which must be evenly distributable
42                                between channels and bits-per-sample*/
43 } pcm_FrameList;
44 
45 void
46 FrameList_dealloc(pcm_FrameList* self);
47 
48 PyObject*
49 FrameList_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
50 
51 int FrameList_init(pcm_FrameList *self, PyObject *args, PyObject *kwds);
52 
53 /*generates a new pcm_FrameList object via _PyObject_New
54   whose fields *must* be populated by additional C code*/
55 pcm_FrameList*
56 FrameList_create(void);
57 
58 PyObject*
59 FrameList_empty(PyObject *dummy, PyObject *args);
60 
61 int
62 FrameList_CheckExact(PyObject *o);
63 
64 PyObject*
65 FrameList_frames(pcm_FrameList *self, void* closure);
66 
67 PyObject*
68 FrameList_channels(pcm_FrameList *self, void* closure);
69 
70 PyObject*
71 FrameList_bits_per_sample(pcm_FrameList *self, void* closure);
72 
73 Py_ssize_t
74 FrameList_len(pcm_FrameList *o);
75 
76 PyObject*
77 FrameList_richcompare(PyObject *a, PyObject *b, int op);
78 
79 int
80 FrameList_equals(pcm_FrameList *a, pcm_FrameList *b);
81 
82 PyObject*
83 FrameList_GetItem(pcm_FrameList *o, Py_ssize_t i);
84 
85 PyObject*
86 FrameList_frame(pcm_FrameList *self, PyObject *args);
87 
88 PyObject*
89 FrameList_channel(pcm_FrameList *self, PyObject *args);
90 
91 PyObject*
92 FrameList_to_bytes(pcm_FrameList *self, PyObject *args);
93 
94 PyObject*
95 FrameList_to_float(pcm_FrameList *self, PyObject *args);
96 
97 PyObject*
98 FrameList_frame_count(pcm_FrameList *self, PyObject *args);
99 
100 PyObject*
101 FrameList_split(pcm_FrameList *self, PyObject *args);
102 
103 PyObject*
104 FrameList_concat(pcm_FrameList *a, PyObject *bb);
105 
106 PyObject*
107 FrameList_repeat(pcm_FrameList *a, Py_ssize_t i);
108 
109 PyObject*
110 FrameList_inplace_concat(pcm_FrameList *a, PyObject *bb);
111 
112 PyObject*
113 FrameList_inplace_repeat(pcm_FrameList *a, Py_ssize_t i);
114 
115 PyObject*
116 FrameList_from_list(PyObject *dummy, PyObject *args);
117 
118 PyObject*
119 FrameList_from_frames(PyObject *dummy, PyObject *args);
120 
121 PyObject*
122 FrameList_from_channels(PyObject *dummy, PyObject *args);
123 
124 /*for use with the PyArg_ParseTuple function*/
125 int
126 FrameList_converter(PyObject* obj, void** framelist);
127 
128 
129 /***********************
130   FloatFrameList Object
131 ************************/
132 
133 typedef struct {
134     PyObject_HEAD;
135 
136     unsigned int frames; /*the total number of PCM frames in this FrameList
137                            aka the total number of rows in the "samples" array*/
138     unsigned int channels; /*the total number of channels in this FrameList
139                              aka the total number of columns in "samples*/
140 
141     double *samples;          /*the actual sample data itself,
142                                 stored raw as doubles*/
143     unsigned samples_length;  /*the total number of samples
144                                 which must be evenly distributable
145                                 between channels*/
146 } pcm_FloatFrameList;
147 
148 void
149 FloatFrameList_dealloc(pcm_FloatFrameList* self);
150 
151 PyObject*
152 FloatFrameList_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
153 
154 int
155 FloatFrameList_init(pcm_FloatFrameList *self, PyObject *args, PyObject *kwds);
156 
157 int
158 FloatFrameList_CheckExact(PyObject *o);
159 
160 PyObject*
161 FloatFrameList_blank(PyObject *dummy, PyObject *args);
162 
163 pcm_FloatFrameList*
164 FloatFrameList_create(void);
165 
166 PyObject*
167 FloatFrameList_empty(PyObject *dummy, PyObject *args);
168 
169 PyObject*
170 FloatFrameList_frames(pcm_FloatFrameList *self, void* closure);
171 
172 PyObject*
173 FloatFrameList_channels(pcm_FloatFrameList *self, void* closure);
174 
175 Py_ssize_t
176 FloatFrameList_len(pcm_FloatFrameList *o);
177 
178 PyObject*
179 FloatFrameList_richcompare(PyObject *a, PyObject *b, int op);
180 
181 int
182 FloatFrameList_equals(pcm_FloatFrameList *a, pcm_FloatFrameList *b);
183 
184 PyObject*
185 FloatFrameList_GetItem(pcm_FloatFrameList *o, Py_ssize_t i);
186 
187 PyObject*
188 FloatFrameList_frame(pcm_FloatFrameList *self, PyObject *args);
189 
190 PyObject*
191 FloatFrameList_channel(pcm_FloatFrameList *self, PyObject *args);
192 
193 PyObject*
194 FloatFrameList_to_int(pcm_FloatFrameList *self, PyObject *args);
195 
196 PyObject*
197 FloatFrameList_split(pcm_FloatFrameList *self, PyObject *args);
198 
199 PyObject*
200 FloatFrameList_concat(pcm_FloatFrameList *a, PyObject *bb);
201 
202 PyObject*
203 FloatFrameList_repeat(pcm_FloatFrameList *a, Py_ssize_t i);
204 
205 PyObject*
206 FloatFrameList_inplace_concat(pcm_FloatFrameList *a, PyObject *bb);
207 
208 PyObject*
209 FloatFrameList_inplace_repeat(pcm_FloatFrameList *a, Py_ssize_t i);
210 
211 PyObject*
212 FloatFrameList_from_frames(PyObject *dummy, PyObject *args);
213 
214 PyObject*
215 FloatFrameList_from_channels(PyObject *dummy, PyObject *args);
216 
217 /*for use with the PyArg_ParseTuple function*/
218 int
219 FloatFrameList_converter(PyObject* obj, void** floatframelist);
220 
221 #endif
222 
223 typedef int (*FrameList_char_to_int_converter)(unsigned char *s);
224 
225 void
226 FrameList_char_to_samples(int *samples,
227                           unsigned char *data,
228                           FrameList_char_to_int_converter converter,
229                           unsigned samples_length,
230                           int bits_per_sample);
231 
232 FrameList_char_to_int_converter
233 FrameList_get_char_to_int_converter(int bits_per_sample,
234                                     int is_big_endian,
235                                     int is_signed);
236 
237 int
238 FrameList_S8_char_to_int(unsigned char *s);
239 
240 int
241 FrameList_U8_char_to_int(unsigned char *s);
242 
243 int
244 FrameList_SL16_char_to_int(unsigned char *s);
245 
246 int
247 FrameList_SB16_char_to_int(unsigned char *s);
248 
249 int
250 FrameList_UL16_char_to_int(unsigned char *s);
251 
252 int
253 FrameList_UB16_char_to_int(unsigned char *s);
254 
255 int
256 FrameList_SL24_char_to_int(unsigned char *s);
257 
258 int
259 FrameList_SB24_char_to_int(unsigned char *s);
260 
261 int
262 FrameList_UL24_char_to_int(unsigned char *s);
263 
264 int
265 FrameList_UB24_char_to_int(unsigned char *s);
266 
267 
268 typedef void (*FrameList_int_to_char_converter)(int i, unsigned char *s);
269 
270 void
271 FrameList_samples_to_char(unsigned char *data,
272                           int *samples,
273                           FrameList_int_to_char_converter converter,
274                           unsigned samples_length,
275                           int bits_per_sample);
276 
277 FrameList_int_to_char_converter
278 FrameList_get_int_to_char_converter(int bits_per_sample,
279                                     int is_big_endian,
280                                     int is_signed);
281 
282 void
283 FrameList_int_to_S8_char(int i, unsigned char *s);
284 
285 void
286 FrameList_int_to_U8_char(int i, unsigned char *s);
287 
288 void
289 FrameList_int_to_UB16_char(int i, unsigned char *s);
290 
291 void
292 FrameList_int_to_SB16_char(int i, unsigned char *s);
293 
294 void
295 FrameList_int_to_UL16_char(int i, unsigned char *s);
296 
297 void
298 FrameList_int_to_SL16_char(int i, unsigned char *s);
299 
300 void
301 FrameList_int_to_UB24_char(int i, unsigned char *s);
302 
303 void
304 FrameList_int_to_SB24_char(int i, unsigned char *s);
305 
306 void
307 FrameList_int_to_UL24_char(int i, unsigned char *s);
308 
309 void
310 FrameList_int_to_SL24_char(int i, unsigned char *s);
311 
312 #endif
313