#include #include #include #include "grain.h" #include "sbsms.h" #include "defs.h" #include "real.h" #include using namespace std; using namespace _sbsms_; map > > wwMap; map > > peakMap; map fftPlanMap; map ifftPlanMap; long grain :: count = 0; grain* grain :: create(int N,real pad,int wintype) { grain *g = new grain(N,pad,wintype); g->refCount = 0; g->time = (audio*) malloc(N*sizeof(audio)); g->freq = (audio*) malloc(N*sizeof(audio)); return g; } void grain :: referenced(grain *g) { g->refCount++; } void grain :: forget(grain *g) { g->refCount--; if(g->refCount <= 0) { destroy(g); } } void grain :: destroy(grain *g) { free_audio_buf(g->time); free_audio_buf(g->freq); delete g; } grain :: grain(int N, real pad, int type) { this->type = type; this->N = N; this->pad = pad; calc_plans(); calc_windows(); } void grain :: analyze() { for(int k=0;kfreq[k][c] = g->freq[k][c]; for(int k=N/2+1;k<=N/2+N;k++) g2->freq[k][c] = 0; for(int k=N/2+N+1;k<2*N;k++) g2->freq[k][c] = g->freq[k-N][c]; } return g2; } grain* grain :: downsample() { grain *g2 = grain::create(N/2,pad,type); grain *g = this; for(int c=0;c<2;c++) { for(int k=0;k<=N/4-1;k++) g2->freq[k][c] = g->freq[k][c]; g2->freq[N/4][c] = 0.5*(g->freq[N/4][c] + g->freq[N-N/4][c] ); for(int k=N/4+1;kfreq[k][c] = g->freq[k+N/2][c]; } return g2; } grain *grain :: lpfilter() { grain *g = this; for(int c=0;c<2;c++) { for(int k=N/4+1;k<=N-N/4-1;k++) g->freq[k][c] = 0; } return this; } //destructive grain *grain :: hpfilter() { grain *g = this; for(int c=0;c<2;c++) { for(int k=0;k<=N/4;k++) g->freq[k][c] = 0; for(int k=N-N/4;kfreq[k][c] = 0; } return this; }