75 h->inChannels = inChannels;
76 h->outChannels = outChannels;
78 dsFactor = 1024/hopSize;
79 h->hLen = 10240/dsFactor;
84 h->protoFilter = (
float*)malloc(
sizeof(
float)*h->hLen);
85 h->protoFilterI = (
float*)malloc(
sizeof(
float)*h->hLen);
86 h->inBuffer = (
float**)malloc(
sizeof(
float*)*h->inChannels);
87 h->outBuffer = (
float**)malloc(
sizeof(
float*)*h->outChannels);
88 h->fftProcessFrameTD = (
float*)calloc(
sizeof(
float),h->hopSize*2);
89#ifdef AFSTFT_USE_SAF_UTILITIES
91 h->fftProcessFrameFD = calloc((h->hopSize+1),
sizeof(float_complex));
92 h->tempHopBuffer = malloc(h->hopSize*
sizeof(
float));
118 h->fftProcessFrameFD = (
float*)calloc(
sizeof(
float),(h->hopSize+1)*2);
119 vtInitFFT(&(h->vtFFT), h->fftProcessFrameTD, h->fftProcessFrameFD, h->log2n);
124#ifdef AFSTFT_USE_SAF_UTILITIES
125 eq = 2.0f/sqrtf(5.487604141f);
127 eq = 1.0f/sqrtf((
float)h->hopSize*5.487604141f);
129 for (k=0; k<h->hLen; k++) {
136#ifdef AFSTFT_USE_SAF_UTILITIES
137 eq = 2.0f/sqrtf(4.544559956f);
139 eq = 1.0f/sqrtf((
float)h->hopSize*4.544559956f);
141 for (k=0; k<h->hLen; k++) {
146 for(ch=0;ch<h->inChannels;ch++)
147 h->inBuffer[ch] = (
float*)calloc(h->hLen,
sizeof(
float));
149 for(ch=0;ch<h->outChannels;ch++)
150 h->outBuffer[ch] = (
float*)calloc(h->hLen,
sizeof(
float));
153 h->hybridMode=hybridMode;
155 afHybridInit(&(h->h_afHybrid), h->hopSize, h->inChannels,h->outChannels);
169 if(h->inChannels!=new_inChannels){
170 for(i=new_inChannels; i<h->inChannels; i++)
171 free(h->inBuffer[i]);
172 h->inBuffer = (
float**)realloc(h->inBuffer,
sizeof(
float*)*new_inChannels);
173 for(i=h->inChannels; i<new_inChannels; i++)
174 h->inBuffer[i] = (
float*)calloc(h->hLen,
sizeof(
float));
177 if(h->outChannels!=new_outChannels){
178 for(i=new_outChannels; i<h->outChannels; i++)
179 free(h->outBuffer[i]);
180 h->outBuffer = (
float**)realloc(h->outBuffer,
sizeof(
float*)*new_outChannels);
181 for(i=h->outChannels; i<new_outChannels; i++)
182 h->outBuffer[i] = (
float*)calloc(h->hLen,
sizeof(
float));
186 hyb_h = h->h_afHybrid;
187 if (hyb_h->inChannels != new_inChannels) {
188 for (ch = new_inChannels; ch < hyb_h->inChannels; ch++) {
189 for (sample = 0; sample < 7; sample++) {
190 free(hyb_h->analysisBuffer[ch][sample].re);
191 free(hyb_h->analysisBuffer[ch][sample].im);
193 free(hyb_h->analysisBuffer[ch]);
196 for (ch = hyb_h->inChannels; ch < new_inChannels; ch++) {
198 for (sample = 0; sample < 7; sample++) {
199 hyb_h->analysisBuffer[ch][sample].re = (
float*) calloc(
sizeof(
float), h->hopSize + 1);
200 hyb_h->analysisBuffer[ch][sample].im = (
float*) calloc(
sizeof(
float), h->hopSize + 1);
205 h->inChannels = new_inChannels;
206 h->outChannels = new_outChannels;
208 hyb_h->inChannels = new_inChannels;
209 hyb_h->outChannels = new_outChannels;
222 for(i=0; i<h->inChannels; i++)
223 memset(h->inBuffer[i], 0, h->hLen*
sizeof(
float));
224 for(i=0; i<h->outChannels; i++)
225 memset(h->outBuffer[i], 0, h->hLen*
sizeof(
float));
227 for(ch=0; ch<hyb_h->inChannels; ch++) {
228 for (sample=0;sample<7;sample++) {
229 memset(hyb_h->analysisBuffer[ch][sample].re, 0,
sizeof(
float)*(h->hopSize+1));
230 memset(hyb_h->analysisBuffer[ch][sample].im, 0,
sizeof(
float)*(h->hopSize+1));
245 int ch,k,hopIndex_this,hopIndex_this2;
247#ifndef AFSTFT_USE_SAF_UTILITIES
252 for (ch=0;ch<h->inChannels;ch++)
255 hopIndex_this2 = h->hopIndexIn;
256 p1=&(h->inBuffer[ch][hopIndex_this2*h->hopSize]);
259 cblas_scopy(h->hopSize, p2, 1, p1, 1);
262 if (hopIndex_this2 >= h->totalHops)
268 p1 = h->fftProcessFrameTD;
269#ifdef AFSTFT_USE_SAF_UTILITIES
270 memset(p1, 0, h->hopSize*2*
sizeof(
float));
272 vtClr(p1, h->hopSize*2);
275 hopIndex_this = hopIndex_this2;
276 for (k=0;k<h->totalHops;k++)
278 p1=&(h->inBuffer[ch][h->hopSize*hopIndex_this]);
279 p2=&(h->protoFilter[k*h->hopSize]);
282 p3=&(h->fftProcessFrameTD[h->hopSize]);
287 p3=&(h->fftProcessFrameTD[0]);
290#ifdef AFSTFT_USE_SAF_UTILITIES
292 cblas_saxpy(h->hopSize, 1.0f, h->tempHopBuffer, 1, p3, 1);
294 vtVma(p1, p2, p3, h->hopSize);
297 if (hopIndex_this >= h->totalHops)
304#ifdef AFSTFT_USE_SAF_UTILITIES
306 cblas_scopy(h->hopSize+1, (
float*)h->fftProcessFrameFD, 2, outFD[ch].re, 1);
307 cblas_scopy(h->hopSize+1, (
float*)h->fftProcessFrameFD + 1, 2, outFD[ch].im, 1);
309 vtRunFFT(h->vtFFT,1);
310 outFD[ch].re[0]=h->fftProcessFrameFD[0];
311 outFD[ch].im[0]=0.0f;
312 outFD[ch].re[h->hopSize]=h->fftProcessFrameFD[h->hopSize];
313 outFD[ch].im[h->hopSize]=0.0f;
314 p1 = outFD[ch].re + 1;
315 p2 = outFD[ch].im + 1;
316 p3 = h->fftProcessFrameFD + 1;
317 p4 = h->fftProcessFrameFD + 1 + h->hopSize;
318 memcpy((
void*)p1,(
void*)p3,
sizeof(
float)*(h->hopSize - 1));
319 memcpy((
void*)p2,(
void*)p4,
sizeof(
float)*(h->hopSize - 1));
323 if (h->hopIndexIn >= h->totalHops)
343 int ch,k,hopIndex_this,hopIndex_this2;
345#ifndef AFSTFT_USE_SAF_UTILITIES
356 for (ch=0;ch<h->outChannels;ch++)
359 hopIndex_this2 = h->hopIndexOut;
362#ifdef AFSTFT_USE_SAF_UTILITIES
363 cblas_scopy(h->hopSize+1, inFD[ch].re, 1, (
float*)h->fftProcessFrameFD, 2);
364 cblas_scopy(h->hopSize+1, inFD[ch].im, 1, (
float*)h->fftProcessFrameFD + 1, 2);
368 for (k=1; k<h->hopSize; k+=2)
369 h->fftProcessFrameFD[k] = crmulf(h->fftProcessFrameFD[k], -1.0f);
373 h->fftProcessFrameFD[0] = inFD[ch].re[0];
374 h->fftProcessFrameFD[h->hopSize] = inFD[ch].re[h->hopSize];
375 p1 = inFD[ch].re + 1;
376 p2 = inFD[ch].im + 1;
377 p3 = h->fftProcessFrameFD + 1;
378 p4 = h->fftProcessFrameFD + 1 + h->hopSize;
379 memcpy((
void*)p3,(
void*)p1,
sizeof(
float)*(h->hopSize - 1));
380 memcpy((
void*)p4,(
void*)p2,
sizeof(
float)*(h->hopSize - 1));
383 if (h->LDmode == 1) {
384 for (k=1;k<h->hopSize;k+=2) {
392 vtRunFFT(h->vtFFT, -1);
396 p1 = &(h->outBuffer[ch][hopIndex_this2*h->hopSize]);
397#ifdef AFSTFT_USE_SAF_UTILITIES
398 memset(p1, 0, h->hopSize*
sizeof(
float));
400 vtClr(p1,h->hopSize);
403 if (hopIndex_this2 >= h->totalHops)
407 hopIndex_this = hopIndex_this2;
410 for (k=0;k<h->totalHops;k++)
413 p1=&(h->outBuffer[ch][h->hopSize*hopIndex_this]);
414 p2=&(h->protoFilterI[k*h->hopSize]);
418 p3=&(h->fftProcessFrameTD[h->hopSize]);
423 p3=&(h->fftProcessFrameTD[0]);
428#ifdef AFSTFT_USE_SAF_UTILITIES
430 cblas_saxpy(h->hopSize, 1.0f, h->tempHopBuffer, 1, p1, 1);
432 vtVma(p2, p3, p1, h->hopSize);
435 if (hopIndex_this >= h->totalHops)
443 p2 = &(h->outBuffer[ch][h->hopSize*hopIndex_this]);
444 memcpy((
void*)p1,(
void*)p2,
sizeof(
float)*(h->hopSize));
448 if (h->hopIndexOut >= h->totalHops)
466 for(ch=0;ch<h->inChannels;ch++)
468 free(h->inBuffer[ch]);
471 for(ch=0;ch<h->outChannels;ch++)
473 free(h->outBuffer[ch]);
475 free(h->protoFilter);
476 free(h->protoFilterI);
479 free(h->fftProcessFrameTD);
480 free(h->fftProcessFrameFD);
481#ifdef AFSTFT_USE_SAF_UTILITIES
483 free(h->tempHopBuffer);
507 h->inChannels = inChannels;
508 h->hopSize = hopSize;
509 h->outChannels = outChannels;
512 for (ch=0;ch<h->inChannels;ch++)
515 for (sample=0;sample<7;sample++)
517 h->analysisBuffer[ch][sample].re=(
float*)calloc(
sizeof(
float),h->hopSize+1);
518 h->analysisBuffer[ch][sample].im=(
float*)calloc(
sizeof(
float),h->hopSize+1);
530 int ch,band,sample,realImag;
531 float *pr1, *pr2, *pi1, *pi2;
533 int sampleIndices[7];
536 if( h->loopPointer == 7)
541 for (ch=0;ch<h->inChannels;ch++)
546 pr2 = h->analysisBuffer[ch][h->loopPointer].re;
547 pi2 = h->analysisBuffer[ch][h->loopPointer].im;
550 cblas_scopy(h->hopSize+1, pr1, 1, pr2, 1);
551 cblas_scopy(h->hopSize+1, pi1, 1, pi2, 1);
554 loopPointerThis = h->loopPointer - 3;
555 if( loopPointerThis < 0)
557 loopPointerThis += 7;
560 pr2 = h->analysisBuffer[ch][loopPointerThis].re;
561 for (realImag=0;realImag<2;realImag++)
565 *(pr1+1) = *(pr2+1)*0.5f;
567 *(pr1+3) = *(pr2+2)*0.5f;
569 *(pr1+5) = *(pr2+3)*0.5f;
571 *(pr1+7) = *(pr2+4)*0.5f;
576 cblas_scopy(h->hopSize-4, pr2+5, 1, pr1+9, 1);
580 pr2 = h->analysisBuffer[ch][loopPointerThis].im;
583 for (sample=0;sample<7;sample++)
585 sampleIndices[sample]=h->loopPointer+1+sample;
586 if(sampleIndices[sample] > 6)
588 sampleIndices[sample]-=7;
592 for (band=1; band<5; band++)
595 re = -
COEFF1*h->analysisBuffer[ch][sampleIndices[6]].im[band];
596 im =
COEFF1*h->analysisBuffer[ch][sampleIndices[6]].re[band];
597 re -=
COEFF2*h->analysisBuffer[ch][sampleIndices[4]].im[band];
598 im +=
COEFF2*h->analysisBuffer[ch][sampleIndices[4]].re[band];
599 re +=
COEFF2*h->analysisBuffer[ch][sampleIndices[2]].im[band];
600 im -=
COEFF2*h->analysisBuffer[ch][sampleIndices[2]].re[band];
601 re +=
COEFF1*h->analysisBuffer[ch][sampleIndices[0]].im[band];
602 im -=
COEFF1*h->analysisBuffer[ch][sampleIndices[0]].re[band];
606 if (band == 1 || band== 3)
608 FD[ch].re[band*2-1] -= re;
609 FD[ch].im[band*2-1] -= im;
610 FD[ch].re[band*2] += re;
611 FD[ch].im[band*2] += im;
615 FD[ch].re[band*2-1] += re;
616 FD[ch].im[band*2-1] += im;
617 FD[ch].re[band*2] -= re;
618 FD[ch].im[band*2] -= im;
635 for (ch=0;ch<h->outChannels;ch++)
638 for (realImag=0;realImag<2;realImag++)
641 *(pr+1) = *(pr+1) + *(pr+2);
642 *(pr+2) = *(pr+3) + *(pr+4);
643 *(pr+3) = *(pr+5) + *(pr+6);
644 *(pr+4) = *(pr+7) + *(pr+8);
647 memmove((
void*)(pr+5),(
void*)(pr+9),
sizeof(
float)*(h->hopSize-4));
662 for (ch=0;ch<h->inChannels;ch++)
664 for (sample=0;sample<7;sample++)
666 free(h->analysisBuffer[ch][sample].re);
667 free(h->analysisBuffer[ch][sample].im);
669 free(h->analysisBuffer[ch]);
672 free(h->analysisBuffer);
void afSTFTlib_channelChange(void *handle, int new_inChannels, int new_outChannels)
Re-allocates memory to support a change in the number of input/output channels.
void afSTFTlib_clearBuffers(void *handle)
Flushes time-domain buffers with zeros.
void afHybridForward(void *handle, complexVector *FD)
Forward hybrid-filtering transform.
void afHybridInverse(void *handle, complexVector *FD)
Inverse hybrid-filtering transform.
void afHybridInit(void **handle, int hopSize, int inChannels, int outChannels)
Creates and initialises an instance of the afHybrid filtering structure.
void afSTFTlib_forward(void *handle, float **inTD, complexVector *outFD)
Applies the forward afSTFT transform.
void afSTFTlib_inverse(void *handle, complexVector *inFD, float **outTD)
Applies the backward afSTFT transform.
void afSTFTlib_free(void *handle)
Destroys an instance of afSTFTlib.
void afSTFTlib_init(void **handle, int hopSize, int inChannels, int outChannels, int LDmode, int hybridMode)
Initialises an instance of afSTFTlib [1].
void afHybridFree(void *handle)
Frees an instnce of the afHybrid filtering structure.
A modified version of afSTFTlib.
#define COEFF2
Filter coefficient 1 for hybrid filtering.
#define COEFF1
Filter coefficient 0 for hybrid filtering.
Prototype filter used by afSTFTlib.
const float __afSTFT_protoFilter1024[10240]
Prototype filter used by afSTFTlib.
const float __afSTFT_protoFilter1024LD[10240]
Prototype filter used by afSTFTlib (low-delay mode)
void utility_svvmul(const float *a, const float *b, const int len, float *c)
Single-precision, element-wise vector-vector multiplication i.e.
void saf_rfft_create(void **const phFFT, int N)
Creates an instance of saf_rfft; real<->half-complex (conjugate-symmetric) FFT.
void saf_rfft_forward(void *const hFFT, float *inputTD, float_complex *outputFD)
Performs the forward-FFT operation; use for real to complex (conjugate symmetric) transformations.
void saf_rfft_backward(void *const hFFT, float_complex *inputFD, float *outputTD)
Performs the backward-FFT operation; use for complex (conjugate symmetric) to real transformations.
void saf_rfft_destroy(void **const phFFT)
Destroys an instance of saf_rfft.
Data structure for the hybrid filtering employed by afSTFTlib.
Main data structure for afSTFTlib.
Complex data type used by afSTFTlib.