-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsamplerate.xtm
200 lines (156 loc) · 6.41 KB
/
samplerate.xtm
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
(sys:load "libs/aot-cache/samplerate.xtm" 'quiet)
(sys:load-preload-check 'samplerate)
(define *xtmlib-samplerate-loaded* #f)
(impc:aot:suppress-aot-do
(sys:load "libs/base/base.xtm"))
(impc:aot:insert-forms (sys:load "libs/base/base.xtm" 'quiet))
(impc:aot:insert-header "xtmsamplerate")
(bind-dylib libsamplerate
(cond ((string=? (sys:platform) "OSX") "libsamplerate.dylib")
((string=? (sys:platform) "Linux") "libsamplerate.so")
((string=? (sys:platform) "Windows") "libsamplerate-1.dll")))
;; /* Opaque data type SRC_STATE. */
;; typedef struct SRC_STATE_tag SRC_STATE ;
(bind-type SRC_STATE <i8>)
;; /* SRC_DATA is used to pass data to src_simple() and src_process(). */
;; typedef struct
;; { const float *data_in ;
;; float *data_out ;
;; long input_frames, output_frames ;
;; long input_frames_used, output_frames_gen ;
;; int end_of_input ;
;; double src_ratio ;
;; } SRC_DATA ;
(bind-type SRC_DATA <float*,float*,i64,i64,i64,i64,i32,double>)
;; /*
;; ** User supplied callback function type for use with src_callback_new()
;; ** and src_callback_read(). First parameter is the same pointer that was
;; ** passed into src_callback_new(). Second parameter is pointer to a
;; ** pointer. The user supplied callback function must modify *data to
;; ** point to the start of the user supplied float array. The user supplied
;; ** function must return the number of frames that **data points to.
;; */
;; typedef long (*src_callback_t) (void *cb_data, float **data) ;
(bind-alias src_callback_t [i64,i8*,float**]*)
;; /*
;; ** Standard initialisation function : return an anonymous pointer to the
;; ** internal state of the converter. Choose a converter from the enums below.
;; ** Error returned in *error.
;; */
;; SRC_STATE* src_new (int converter_type, int channels, int *error) ;
(bind-lib libsamplerate src_new [SRC_STATE*,i32,i32,i32*]*)
;; /*
;; ** Initilisation for callback based API : return an anonymous pointer to the
;; ** internal state of the converter. Choose a converter from the enums below.
;; ** The cb_data pointer can point to any data or be set to NULL. Whatever the
;; ** value, when processing, user supplied function "func" gets called with
;; ** cb_data as first parameter.
;; */
;; SRC_STATE* src_callback_new (src_callback_t func, int converter_type, int channels,
;; int *error, void* cb_data) ;
(bind-lib libsamplerate src_callback_new [SRC_STATE*,src_callback_t,i32,i32,i32*,i8*]*)
;(bind-lib libsamplerate src_callback_new [SRC_STATE*,i8*,i32,i32,i32*,i8*]*)
;; /*
;; ** Cleanup all internal allocations.
;; ** Always returns NULL.
;; */
;; SRC_STATE* src_delete (SRC_STATE *state) ;
(bind-lib libsamplerate src_delete [SRC_STATE*,SRC_STATE*]*)
;; /*
;; ** Standard processing function.
;; ** Returns non zero on error.
;; */
;; int src_process (SRC_STATE *state, SRC_DATA *data) ;
(bind-lib libsamplerate src_process [i32,SRC_STATE*,SRC_DATA*]*)
;; /*
;; ** Callback based processing function. Read up to frames worth of data from
;; ** the converter int *data and return frames read or -1 on error.
;; */
;; long src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data) ;
(bind-lib libsamplerate src_callback_read [i64,SRC_STATE*,double,i64,float*]*)
;; /*
;; ** Simple interface for performing a single conversion from input buffer to
;; ** output buffer at a fixed conversion ratio.
;; ** Simple interface does not require initialisation as it can only operate on
;; ** a single buffer worth of audio.
;; */
;; int src_simple (SRC_DATA *data, int converter_type, int channels) ;
(bind-lib libsamplerate src_simple [i32,SRC_DATA*,i32,i32]*)
;; /*
;; ** This library contains a number of different sample rate converters,
;; ** numbered 0 through N.
;; **
;; ** Return a string giving either a name or a more full description of each
;; ** sample rate converter or NULL if no sample rate converter exists for
;; ** the given value. The converters are sequentially numbered from 0 to N.
;; */
;; const char *src_get_name (int converter_type) ;
;; const char *src_get_description (int converter_type) ;
;; const char *src_get_version (void) ;
(bind-lib libsamplerate src_get_name [i8*,i32]*)
(bind-lib libsamplerate src_get_description [i8*,i32]*)
(bind-lib libsamplerate src_get_version [i8*]*)
;; /*
;; ** Set a new SRC ratio. This allows step responses
;; ** in the conversion ratio.
;; ** Returns non zero on error.
;; */
;; int src_set_ratio (SRC_STATE *state, double new_ratio) ;
(bind-lib libsamplerate src_set_ratio [i32,SRC_STATE*,double]*)
;; /*
;; ** Get the current channel count.
;; ** Returns negative on error, positive channel count otherwise
;; */
;; int src_get_channels (SRC_STATE *state) ;
(bind-lib libsamplerate src_get_channels [i32,SRC_STATE*]*)
;; /*
;; ** Reset the internal SRC state.
;; ** Does not modify the quality settings.
;; ** Does not free any memory allocations.
;; ** Returns non zero on error.
;; */
;; int src_reset (SRC_STATE *state) ;
(bind-lib libsamplerate src_reset [i32,SRC_STATE*]*)
;; /*
;; ** Return TRUE if ratio is a valid conversion ratio, FALSE
;; ** otherwise.
;; */
;; int src_is_valid_ratio (double ratio) ;
(bind-lib libsamplerate src_is_valid_ratio [i32,double]*)
;; /*
;; ** Return an error number.
;; */
;; int src_error (SRC_STATE *state) ;
(bind-lib libsamplerate src_error [i32,SRC_STATE*]*)
;; /*
;; ** Convert the error number into a string.
;; */
;; const char* src_strerror (int error) ;
(bind-lib libsamplerate src_strerror [i8*,i32]*)
;; /*
;; ** The following enums can be used to set the interpolator type
;; ** using the function src_set_converter().
;; */
;; enum
;; {
;; SRC_SINC_BEST_QUALITY = 0,
;; SRC_SINC_MEDIUM_QUALITY = 1,
;; SRC_SINC_FASTEST = 2,
;; SRC_ZERO_ORDER_HOLD = 3,
;; SRC_LINEAR = 4,
;; } ;
(bind-val SRC_SINC_BEST_QUALITY enum #x0)
(bind-val SRC_SINC_MEDIUM_QUALITY enum #x1)
(bind-val SRC_SINC_FASTEST enum #x2)
(bind-val SRC_ZERO_ORDER_HOLD enum #x3)
(bind-val SRC_LINEAR enum #x4)
;; /*
;; ** Extra helper functions for converting from short to float and
;; ** back again.
;; */
;; void src_short_to_float_array (const short *in, float *out, int len) ;
(bind-lib libsamplerate src_short_to_float_array [void,i16*,float*,i32]*)
;; void src_float_to_short_array (const float *in, short *out, int len) ;
(bind-lib libsamplerate src_float_to_short_array [void,float*,i16*,i32]*)
;; void src_int_to_float_array (const int *in, float *out, int len) ;
;; void src_float_to_int_array (const float *in, int *out, int len) ;