MCPcopy Create free account
hub / github.com/LabSound/LabSound / sp_conv_init

Function sp_conv_init

src/core/_SoundPipe_FFT.cpp:343–429  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

341}
342
343int sp_conv_init(sp_data * sp, sp_conv * p, sp_ftbl * ft, SPFLOAT iPartLen)
344{
345 int i, j, k, n, nBytes, skipSamples;
346 SPFLOAT FFTscale;
347
348 p->iTotLen = ft->size;
349 p->iSkipSamples = 0;
350 p->iPartLen = iPartLen;
351
352 p->nChannels = 1;
353 /* partition length */
354 p->partSize = (int) lrintf(p->iPartLen);
355 if (p->partSize < 4 || (p->partSize & (p->partSize - 1)) != 0)
356 {
357 fprintf(stderr, "conv: invalid partition size.\n");
358 return SP_NOT_OK;
359 }
360
361 sp_fft_init(&p->fft, (int) log2(p->partSize << 1));
362 n = (int) ft->size / p->nChannels;
363 skipSamples = (int) lrintf(p->iSkipSamples);
364 n -= skipSamples;
365
366 if (lrintf(p->iTotLen) > 0 && n > lrintf(p->iTotLen))
367 {
368 n = (int) lrintf(p->iTotLen);
369 }
370
371 if (n <= 0)
372 {
373 fprintf(stderr, "uh oh.\n");
374 return SP_NOT_OK;
375 }
376
377 p->nPartitions = (n + (p->partSize - 1)) / p->partSize;
378 /* calculate the amount of aux space to allocate (in bytes) */
379 nBytes = buf_bytes_alloc(p->nChannels, p->partSize, p->nPartitions);
380 sp_auxdata_alloc(&p->auxData, nBytes);
381 /* if skipping samples: check for possible truncation of IR */
382 /* initialise buffer pointers */
383 set_buf_pointers(p, p->nChannels, p->partSize, p->nPartitions);
384 /* clear ring buffer to zero */
385 n = (p->partSize << 1) * p->nPartitions;
386 memset(p->ringBuf, 0, n * sizeof(SPFLOAT));
387 p->cnt = 0;
388 p->rbCnt = 0;
389 FFTscale = 1.0;
390 for (j = 0; j < p->nChannels; j++)
391 {
392 /* table read position */
393 i = (skipSamples * p->nChannels) + j;
394 /* IR write position */
395 n = (p->partSize << 1) * (p->nPartitions - 1);
396 do
397 {
398 for (k = 0; k < p->partSize; k++)
399 {
400 if (i >= 0 && i < (int) ft->size)

Callers 1

_activateNewImpulseMethod · 0.85

Calls 5

sp_fft_initFunction · 0.85
buf_bytes_allocFunction · 0.85
sp_auxdata_allocFunction · 0.85
set_buf_pointersFunction · 0.85
sp_fftrFunction · 0.85

Tested by

no test coverage detected