199 | 199 |
** GxConvolver
|
200 | 200 |
*/
|
201 | 201 |
|
|
202 |
/*
|
|
203 |
** GxConvolver::read_sndfile()
|
|
204 |
**
|
|
205 |
** read samples from soundfile into convolver
|
|
206 |
** the convolver is working at rate samplerate, the audio file has audio.rate
|
|
207 |
**
|
|
208 |
** offset, length, points are based on audio.rate, delay and the count of
|
|
209 |
** samples written into the convolver are based on samplerate.
|
|
210 |
**
|
|
211 |
** Arguments:
|
|
212 |
** Audiofile& audio already opened, will be converted to samplerate
|
|
213 |
** on the fly
|
|
214 |
** int nchan channel count for convolver (can be less
|
|
215 |
** or more than audio.chan())
|
|
216 |
** int samplerate current engine samplerate
|
|
217 |
** const float *gain array[nchan] of gains to be applied
|
|
218 |
** unsigned int *delay array[nchan], starting sample index for values
|
|
219 |
** stored into convolver
|
|
220 |
** unsigned int offset offset into audio file
|
|
221 |
** unsigned int length number of samples to be read from audio
|
|
222 |
** const Gainline& points gain line to be applied
|
|
223 |
**
|
|
224 |
** returns false if some error occurred, else true
|
|
225 |
*/
|
202 | 226 |
bool GxConvolver::read_sndfile(
|
203 | 227 |
Audiofile& audio, int nchan, int samplerate, const float *gain,
|
204 | 228 |
unsigned int *delay, unsigned int offset, unsigned int length,
|
|
218 | 242 |
return false;
|
219 | 243 |
}
|
220 | 244 |
try {
|
221 | |
buff = new float[BSIZE * nchan];
|
|
245 |
buff = new float[BSIZE * audio.chan()];
|
222 | 246 |
} catch(...) {
|
223 | 247 |
audio.close();
|
224 | 248 |
gx_system::gx_print_error("convolver", "out of memory");
|
225 | 249 |
return false;
|
226 | 250 |
}
|
227 | 251 |
if (samplerate != audio.rate()) {
|
228 | |
ostringstream buf;
|
229 | |
buf << "resampling from " << audio.rate() << " to " << samplerate;
|
230 | |
gx_system::gx_print_info("convolver", buf.str());
|
231 | |
if (!resamp.setup(audio.rate(), samplerate, nchan)) {
|
|
252 |
gx_system::gx_print_info(
|
|
253 |
"convolver", Glib::ustring::compose(
|
|
254 |
_("resampling from %1 to %2"), audio.rate(), samplerate));
|
|
255 |
if (!resamp.setup(audio.rate(), samplerate, audio.chan())) {
|
|
256 |
gx_system::gx_print_error("convolver", "resample failure");
|
232 | 257 |
assert(false);
|
|
258 |
return false;
|
233 | 259 |
}
|
234 | 260 |
try {
|
235 | |
rbuff = new float[resamp.get_max_out_size(BSIZE)*nchan];
|
|
261 |
rbuff = new float[resamp.get_max_out_size(BSIZE)*audio.chan()];
|
236 | 262 |
} catch(...) {
|
237 | 263 |
audio.close();
|
238 | 264 |
gx_system::gx_print_error("convolver", "out of memory");
|
|
273 | 299 |
compute_interpolation(fct, gp, idx, points, offset);
|
274 | 300 |
}
|
275 | 301 |
|
276 | |
for (int ichan = 0; ichan < nchan; ichan++) {
|
277 | |
buff[ix*nchan+ichan] *= pow(10, gp + ix*fct) * gain[ichan];
|
|
302 |
for (int ichan = 0; ichan < min(audio.chan(), nchan); ichan++) {
|
|
303 |
buff[ix*audio.chan()+ichan] *= pow(10, gp + ix*fct) * gain[ichan];
|
278 | 304 |
}
|
279 | 305 |
}
|
280 | 306 |
offset += nfram;
|
|
352 | 378 |
<< ", lgain" << lgain << endl;
|
353 | 379 |
*/
|
354 | 380 |
|
|
381 |
if (samplerate != static_cast<unsigned int>(audio.rate())) {
|
|
382 |
float f = float(samplerate) / audio.rate();
|
|
383 |
size = round(size * f) + 2; // 2 is safety margin for rounding differences
|
|
384 |
delay = round(delay * f);
|
|
385 |
ldelay = round(ldelay * f);
|
|
386 |
}
|
355 | 387 |
if (Convproc::configure(2, 2, size, buffersize, bufsize, Convproc::MAXPART)) {
|
356 | 388 |
gx_system::gx_print_error("convolver", "error in Convproc::configure ");
|
357 | 389 |
return false;
|