// ------------------------------------------------------------------ process -- void SpectacleBase::process(const float *buf, const int) { DPRINT("SpectacleBase::process"); if (_reading_input) { prepare_input(buf); _fft->r2c(); } modify_analysis(_reading_input); _fft->c2r(); prepare_output(); }
// ------------------------------------------------------------------ process -- void SPECTACLE2_BASE::process(const float *buf, const int) { DPRINT("SPECTACLE2_BASE::process\n"); const bool reading_input = (currentFrame() < _input_end_frame); if (reading_input) { DPRINT1("taking input...currentFrame()=%d\n", currentFrame()); prepare_input(buf); _fft->r2c(); cartesian_to_polar(); } modify_analysis(reading_input); polar_to_cartesian(); _fft->c2r(); prepare_output(); }
/* ------------------------------------------------------------------- run -- */ int SPECTACLE_BASE :: run() { if (first_time) { /* create segmented input buffer */ int num_segments = (window_len / RTBUFSAMPS) + 2; int extrasamps = RTBUFSAMPS - framesToRun(); if (extrasamps) num_segments++; int inbuf_samps = num_segments * RTBUFSAMPS * inputChannels(); inbuf = new float [inbuf_samps]; for (int i = 0; i < inbuf_samps; i++) inbuf[i] = 0.0; /* Read ptr chases write ptr by <window_len>. Set read ptr to a position <window_len> frames from right end of input buffer. Set write ptr to beginning of buffer, or, if framesToRun() is not the same as the RTcmix buffer size, set it so that the next run invocation after this one will find the write ptr at the start of the second buffer segment. */ inbuf_readptr = inbuf + (inbuf_samps - (window_len * inputChannels())); inbuf_startptr = inbuf + (extrasamps * inputChannels()); inbuf_writeptr = inbuf_startptr; inbuf_endptr = inbuf + inbuf_samps; int outbuf_samps = num_segments * RTBUFSAMPS * outputChannels(); outbuf = new float [outbuf_samps]; for (int i = 0; i < outbuf_samps; i++) outbuf[i] = 0.0; outbuf_readptr = outbuf + (outbuf_samps - (framesToRun() * outputChannels())); outbuf_writeptr = outbuf_readptr; outbuf_endptr = outbuf + outbuf_samps; first_time = 0; DPRINT3("framesToRun()=%d, extrasamps=%d, num_segments=%d\n", framesToRun(), extrasamps, num_segments); DPRINT3("inbuf_samps=%d, inbuf_readptr=%p, inbuf_writeptr=%p\n", inbuf_samps, inbuf_readptr, inbuf_writeptr); DPRINT3("outbuf_samps=%d, outbuf_readptr=%p, outbuf_writeptr=%p\n", outbuf_samps, outbuf_readptr, outbuf_writeptr); } const int insamps = framesToRun() * inputChannels(); if (currentFrame() < total_insamps) rtgetin(inbuf_writeptr, this, insamps); int iterations = framesToRun() / decimation; if (framesToRun() < RTBUFSAMPS) iterations++; DPRINT1("iterations=%d\n", iterations); for (int i = 0; i < iterations; i++) { if (currentFrame() < input_end_frame) { DPRINT1("taking input...cursamp=%d\n", currentFrame()); shiftin(); fold(currentFrame()); JGrfft(fft_buf, half_fft_len, FORWARD); leanconvert(); } else flush_dry_delay(); modify_analysis(); leanunconvert(); JGrfft(fft_buf, half_fft_len, INVERSE); overlapadd(currentFrame()); shiftout(); increment(decimation); } if (currentFrame() < input_end_frame) { inbuf_writeptr += insamps; if (inbuf_writeptr >= inbuf_endptr) inbuf_writeptr = inbuf; } rtbaddout(outbuf_readptr, framesToRun()); outbuf_readptr += framesToRun() * outputChannels(); if (outbuf_readptr >= outbuf_endptr) outbuf_readptr = outbuf; return framesToRun(); }