1 #define PERL_NO_GET_CONTEXT
8 #include <samplerate.h>
10 struct generic_callback_data {
16 long _generic_callback(void *cb_data, float **data){
17 struct generic_callback_data gc_data;
20 gc_data = *(struct generic_callback_data*)cb_data;
24 XPUSHs(gc_data.cb_data);
26 nr = call_sv(gc_data.func, G_ARRAY);
34 callback_new(pkg, func, converter_type = 0, channels = 2, cb_data = &PL_sv_undef)
44 state = src_new(converter_type, channels, &error);
46 croak("src_new failed with error %d (%s)\n", error, src_strerror(error));
48 RETVAL = sv_setref_iv(newSV(0), pkg, PTR2IV(state));
53 #define cerror(func) croak("%s failed with error %d (%s)\n", func, error, src_strerror(error))
54 #define SELF INT2PTR(SRC_STATE*, SvIV(SvRV(self)))
56 MODULE = Audio::LibSampleRate PACKAGE = Audio::LibSampleRate
60 src_simple(data_in, src_ratio, converter_type = 0, channels = 2)
71 data.input_frames = (av_len(data_in) + 1) / channels;
72 data.output_frames = data.input_frames * src_ratio + 10;
73 Newx(in, data.input_frames * channels, float);
74 Newx(out, data.output_frames * channels, float);
75 for(i = 0 ; i <= av_len(data_in) ; i++)
76 if(av_exists(data_in, i))
77 in[i] = SvNV(*av_fetch(data_in, i, 0));
80 data.src_ratio = src_ratio;
81 if (error = src_simple(&data, converter_type, channels))
83 EXTEND(SP, data.output_frames_gen);
84 for(i = 0 ; i < data.output_frames_gen ; i++)
85 PUSHs(sv_2mortal(newSVnv(data.data_out[i])));
90 new(pkg, converter_type = 0, channels = 2)
98 state = src_new(converter_type, channels, &error);
101 RETVAL = sv_setref_iv(newSV(0), pkg, PTR2IV(state));
112 process(self, data_in, src_ratio, end_of_input = 0)
123 data.input_frames = av_len(data_in) + 1;
124 data.output_frames = data.input_frames * src_ratio + 10;
125 Newx(in, data.input_frames, float);
126 Newx(out, data.output_frames, float);
127 for(i = 0 ; i <= av_len(data_in) ; i++)
128 if(av_exists(data_in, i))
129 in[i] = SvNV(*av_fetch(data_in, i, 0));
132 data.src_ratio = src_ratio;
133 data.end_of_input = end_of_input;
134 if(error = src_process(SELF, &data))
135 cerror("src_process");
136 EXTEND(SP, data.output_frames_gen);
137 for(i = 0 ; i < data.output_frames_gen ; i++)
138 PUSHs(sv_2mortal(newSVnv(data.data_out[i])));
146 if(error = src_reset(SELF))
150 set_ratio(self, new_ratio)
156 if(error = src_set_ratio(SELF, new_ratio))
157 cerror("src_set_ratio");
160 src_get_name(converter_type)
164 src_get_description(converter_type)