Пример #1
0
int DISTORT::run()
{
   const int insamps = framesToRun() * inputChannels();
   rtgetin(in, this, insamps);

   for (int i = 0; i < insamps; i += inputChannels()) {
      if (--branch <= 0) {
         doupdate();
         branch = getSkip();
      }
      float sig = in[i + inchan];
      if (!bypass) {
         sig *= (gain / 32768.0f);  // apply gain, convert range
         sig = distort->next(sig, param);
         sig *= 32768.0f;
         if (usefilt)
            sig = filt->tick(sig);
      }
      sig *= amp;
      float out[2];
      if (outputChannels() == 2) {
         out[0] = sig * pctleft;
         out[1] = sig * (1.0f - pctleft);
      }
      else
         out[0] = sig;

      rtaddout(out);
      increment();
   }

   return framesToRun();
}
Пример #2
0
int SHAPE :: run()
{
   const int samps = framesToRun() * inputChannels();
   rtgetin(in, this, samps);

   for (int i = 0; i < samps; i += inputChannels()) {
      if (--branch <= 0) {
         doupdate();
         branch = skip;
      }

      // NB: WavShape deals with samples in range [-1, 1].
      float insig = in[i + inchan] * (1.0 / 32768.0);
      float outsig = shaper->tick(insig * index);
      if (outsig) {
         if (ampnorm)
            outsig = dcblocker->tick(outsig) * ampnorm->tick(norm_index);
         else
            outsig = dcblocker->tick(outsig);
      }
      float out[2];
      out[0] = outsig * amp * 32768.0;

      if (outputChannels() == 2) {
         out[1] = out[0] * (1.0 - pctleft);
         out[0] *= pctleft;
      }

      rtaddout(out);
      increment();
   }

   return framesToRun();
}
Пример #3
0
int JFIR :: run()
{
   const int samps = framesToRun() * inputChannels();

   rtgetin(in, this, samps);

   for (int i = 0; i < samps; i += inputChannels()) {
      if (--branch <= 0) {
         doupdate();
         branch = getSkip();
      }

      float insig;
      if (currentFrame() < insamps)          // still taking input
         insig = in[i + inchan] * amp;
      else                                   // in ring-down phase
         insig = 0.0;

      float out[2];
      if (bypass)
         out[0] = insig;
      else
         out[0] = filt->tick(insig);

      if (outputchans == 2) {
         out[1] = out[0] * (1.0 - pctleft);
         out[0] *= pctleft;
      }

      rtaddout(out);
      increment();
   }

   return framesToRun();
}
Пример #4
0
int GVERB::run()
{
	const int samps = framesToRun() * inputChannels();
	int i;
	float out[2];

	rtgetin(in, this, samps);
	
	for (i = 0; i < samps; i += inputChannels()) {
		if (--branch <= 0) {
			doupdate();
			branch = getSkip();
		}

		if (currentFrame() > inputframes) in[i+inputchan] = 0.0;
		gverb_do(p, in[i+inputchan], out, out+1);

		out[0] = (out[0] * amp) + (in[i+inputchan] * p->drylevel);
		out[1] = (out[1] * amp) + (in[i+inputchan] * p->drylevel);

		rtaddout(out);

		increment();
	}
	return i;
}
Пример #5
0
int AM::run()
{
	const int samps = framesToRun() * inputChannels();

	rtgetin(in, this, samps);

	for (int i = 0; i < samps; i += inputChannels())  {
		if (--branch <= 0) {
			double p[7];
			update(p, 7, kAmp | kFreq | kPan);
			amp = p[3];
			if (amptable)
				amp *= tablei(currentFrame(), amptable, amptabs);
			if (freqtable)
				modfreq = tablei(currentFrame(), freqtable, freqtabs);
			else
				modfreq = p[4];
			modosc->setfreq(modfreq);
			spread = p[6];
			branch = skip;
		}

		float out[2];
		out[0] = in[i + inchan] * modosc->next() * amp;

		if (outputChannels() == 2) {
			out[1] = out[0] * (1.0 - spread);
			out[0] *= spread;
		}

		rtaddout(out);
		increment();
	}
	return framesToRun();
}
Пример #6
0
int STEREO::run()
{
	const int inchans = inputChannels();
	const int samps = framesToRun() * inchans;

	rtgetin(in, this, samps);

	for (int i = 0; i < samps; i += inchans)  {
		if (--branch <= 0) {
			if (fastUpdate) {
				if (amptable)
					amp = ampmult * tablei(currentFrame(), amptable, amptabs);
			}
			else
				doupdate();
			branch = getSkip();
		}

		float out[2];
		out[0] = out[1] = 0.0;
		for (int j = 0; j < inchans; j++) {
			if (outPan[j] >= 0.0) {
				out[0] += in[i+j] * outPan[j] * amp;
				out[1] += in[i+j] * (1.0 - outPan[j]) * amp;
			}
		}

		rtaddout(out);
		increment();
	}
	return framesToRun();
}
int REVMIX::run()
{
   int samps = framesToRun() * inputChannels();

   rtinrepos(this, -framesToRun(), SEEK_CUR);

   rtgetin(in, this, samps);

   for (int i = samps - inputChannels(); i >=  0; i -= inputChannels())  {
      if (--branch <= 0) {
         double p[nargs];
         update(p, nargs);
         amp = p[3];
         if (amparray)
            amp *= tablei(currentFrame(), amparray, amptabs);
         pctleft = nargs > 5 ? p[5] : 0.5;         // default is .5
         branch = skip;
      }

      float out[2];
      out[0] = in[i + inchan] * amp;

      if (outputChannels() == 2) {
         out[1] = out[0] * (1.0 - pctleft);
         out[0] *= pctleft;
      }

      rtaddout(out);
      increment();
   }
   rtinrepos(this, -framesToRun(), SEEK_CUR);

   return framesToRun();
}
int TRANS3::run()
{
   const int outframes = framesToRun();
   const int inchans = inputChannels();
   float *outp = outbuf;     // point to inst private out buffer
   double frac;

   for (int i = 0; i < outframes; i++) {
      if (--branch <= 0) {
         doupdate();
         branch = getSkip();
      }
      while (getframe) {
         if (inframe >= RTBUFSAMPS) {
            rtgetin(in, this, RTBUFSAMPS * inchans);
            inframe = 0;
         }
         oldersig = oldsig;
         oldsig = newsig;
         newsig = newestsig;

         newestsig = in[(inframe * inchans) + inchan];

         inframe++;
         incount++;

         if (counter - (double) incount < 0.0)
            getframe = false;
      }

//      const double frac = (counter - (double) incount) + 2.0;
      const double frac = (counter - (double) incount) + 1.0;
      outp[0] = interp3rdOrder(oldersig, oldsig, newsig, newestsig, frac) * amp;

#ifdef DEBUG_FULL
      printf("i: %d counter: %g incount: %d frac: %g inframe: %d cursamp: %d\n",
             i, counter, incount, frac, inframe, currentFrame());
      printf("interping %g, %g, %g, %g => %g\n", oldersig, oldsig, newsig, newestsig, outp[0]);
#endif

      if (outputChannels() == 2) {
         outp[1] = outp[0] * (1.0 - pctleft);
         outp[0] *= pctleft;
      }

      outp += outputChannels();
      increment();

      counter += _increment;         // keeps track of interp pointer
      if (counter - (double) incount >= 0.0)
         getframe = true;
   }

#ifdef DEBUG
   printf("OUT %d frames\n\n", i);
#endif

   return framesToRun();
}
Пример #9
0
int MYINST::run()
{
	// framesToRun() gives the number of sample frames -- 1 sample for each
	// channel -- that we have to write during this scheduler time slice.

	const int samps = framesToRun() * inputChannels();

	// Read <samps> samples from the input file (or audio input device).

	rtgetin(_in, this, samps);

	// Each loop iteration processes 1 sample frame. */

	for (int i = 0; i < samps; i += inputChannels()) {

		// This block updates certain parameters at the control rate -- the
		// rate set by the user with the control_rate() or reset() script
		// functions.  The Instrument base class holds this value as a number
		// of sample frames to skip between updates.  Get this value using
		// getSkip() to reset the <_branch> counter.

		if (--_branch <= 0) {
			doupdate();
			_branch = getSkip();
		}

		// Grab the current input sample, scaled by the amplitude multiplier.

		float insig = _in[i + _inchan] * _amp;

		float out[2];		// Space for only 2 output chans!

		// Just copy it to the output array with no processing.

		out[0] = insig;

		// If we have stereo output, use the pan pfield.

		if (outputChannels() == 2) {
			out[1] = out[0] * (1.0f - _pan);
			out[0] *= _pan;
		}

		// Write this sample frame to the output buffer.

		rtaddout(out);

		// Increment the count of sample frames this instrument has written.

		increment();
	}

	// Return the number of frames we processed.

	return framesToRun();
}
int REVERBIT::run()
{
    int samps = framesToRun() * inputChannels();

    if (currentFrame() < insamps)
        rtgetin(in, this, samps);

    for (int i = 0; i < samps; i += inputChannels()) {
        if (--branch <= 0) {
            doupdate();
            branch = getSkip();
        }

        float insig[2], out[2];

        if (currentFrame() < insamps) {        // still taking input from file
            insig[0] = in[i] * amp;
            insig[1] = (inputChannels() == 2) ? in[i + 1] * amp : insig[0];
        }
        else                                   // in ring-down phase
            insig[0] = insig[1] = 0.0;

        float rvbsig = -reverbpct * reverb(insig[0] + insig[1], rvbarray);

        if (usefilt)
            rvbsig = tone(rvbsig, tonedata);

        delput(rvbsig, delarray, deltabs);
        float delsig = delget(delarray, rtchan_delaytime, deltabs);

        out[0] = insig[0] + rvbsig;
        out[1] = insig[1] + delsig;

        if (dcblock) {
            float tmp_in[2];

            tmp_in[0] = out[0];
            tmp_in[1] = out[1];

            out[0] = tmp_in[0] - prev_in[0] + (0.99 * prev_out[0]);
            prev_in[0] = tmp_in[0];
            prev_out[0] = out[0];

            out[1] = tmp_in[1] - prev_in[1] + (0.99 * prev_out[1]);
            prev_in[1] = tmp_in[1];
            prev_out[1] = out[1];
        }

        rtaddout(out);
        increment();
    }

    return framesToRun();
}
Пример #11
0
int HOLO::run()
{
    int i, j;
    float output[2];

    int rsamps = framesToRun()*inputChannels();
    rtgetin(in, this, rsamps);

    for (i = 0; i < rsamps; i += 2) {
        if (--count <= 0) {
            double p[5];
            update(p, 5);
            amp = p[3];
            xtalkAmp = (p[4] != 0.0) ? p[4] : 1.0;
            count = skip;
        }
        for (int n = 0; n < 2; n++) {
            int c;
            output[n] = 0.0;
            pastsamps[n][intap] = in[i+n];

            // sum all past samples * coefficients
            // two loops to avoid bounds checking

            for (j = intap, c = 0; j < ncoefs; j++, c++)
                output[n] += (pastsamps[n][j] * sameSideCoeffs[c]);

            const int remaining = ncoefs - c;

            for (j = 0; j < remaining; j++, c++)
                output[n] += (pastsamps[n][j] * sameSideCoeffs[c]);

            // feed signal to opposite side
            pastsamps2[n][intap] = in[i + 1 - n];

            // add this into output for each side

            for (j = intap, c = 0; j < ncoefs; j++, c++)
                output[n] += xtalkAmp * (pastsamps2[n][j] * oppositeSideCoeffs[c]);

            const int remaining2 = ncoefs - c;

            for (j = 0; j < remaining2; j++, c++)
                output[n] += xtalkAmp * (pastsamps2[n][j] * oppositeSideCoeffs[c]);

            output[n] *= amp;
        }
        rtaddout(output);
        increment();
        if (--intap < 0)
            intap = ncoefs - 1;
    }
    return(i);
}
Пример #12
0
int ROOM::run()
{
   const int samps = framesToRun() * inputChannels();

   rtgetin(in, this, samps);

   for (int i = 0; i < samps; i += inputChannels()) {
      if (--branch <= 0) {
         if (amparray)
            aamp = tablei(currentFrame(), amparray, amptabs) * amp;
         branch = skip;
      }

      float insig;
      if (currentFrame() < insamps) {        /* still taking input */
         if (inchan == AVERAGE_CHANS) {
            insig = 0.0;
            for (int n = 0; n < inputChannels(); n++)
               insig += in[i + n];
            insig /= (float) inputChannels();
         }
         else
            insig = in[i + inchan];
      }
      else                                   /* in ring-down phase */
         insig = 0.0;

      echo[jpoint++] = insig;
      if (jpoint >= nmax)
         jpoint -= nmax;

      float out[2];
      out[0] = out[1] = 0.0;
      for (int j = 0; j < NTAPS; j++) {
         float e = echo[ipoint[j]];
         out[0] += e * lamp[j];
         out[1] += e * ramp[j];
         ipoint[j]++;
         if (ipoint[j] >= nmax)
            ipoint[j] -= nmax;
      }

      if (aamp != 1.0) {
         out[0] *= aamp;
         out[1] *= aamp;
      }

      rtaddout(out);
      increment();
   }

   return framesToRun();
}
Пример #13
0
int MBASE::getInput(int currentFrame, int frames)
{
    // number of samples to process this time through
	const int inChans = inputChannels();

    int rsamps = frames * inChans;

    rtgetin(in, this, rsamps);
	
    int n = 0;
    int lCurSamp;	// local copy for inner loops
    float insig;
#ifdef LOOP_DEBUG
    int nsig = 0, nzeros = 0;
#endif
	float scale = 1.0/inChans;
    // apply curve to input signal and mix down to mono if necessary

    for (int s = 0, curFrm = currentFrame; s < rsamps; s += inChans, curFrm++)
    {
		if (curFrm < insamps) {	/* processing input signal */
#ifdef LOOP_DEBUG
			nsig++;
#endif
			if (--m_branch < 0) {
			   inamp = update(3, insamps, curFrm);
			   if (amparray)
    			  inamp *= tablei(curFrm, amparray, amptabs);
			   m_branch = getSkip();
			}
			if (m_inchan == AVERAGE_CHANS) {
			   insig = 0.0;
			   for (int c = 0; c < inChans; c++)
    			  insig += in[s + c];
			   insig *= scale;
			}
			else
			   insig = in[s + m_inchan];
			insig *= inamp;
		}
		else  {                               /* flushing delays & reverb */
#ifdef LOOP_DEBUG
			nzeros++;
#endif
 			insig = 0.0;
		}
	    in[n++] = insig;	// write back into input array to save space
    }
#ifdef LOOP_DEBUG
	DBG1(printf("getInput(): %d signal, %d zero padded\n", nsig, nzeros));
#endif
	return 0;
}
Пример #14
0
int COMBIT::run()
{
	int samps = framesToRun() * inputChannels();

	if (currentFrame() < insamps)
		rtgetin(in, this, samps);

	for (int i = 0; i < samps; i += inputChannels())  {
		if (--branch <= 0) {
			double p[8];
			update(p, 8);
			amp = p[3];
			if (amptable) {
#ifdef EMBEDDED
				amp *= rtcmix_table(currentFrame(), amptable, tabs);
#else
				amp *= table(currentFrame(), amptable, tabs);
#endif
			}
			if (p[4] != frequency) {
				frequency = p[4];
				delsamps = (int) ((1.0 / frequency) * SR + 0.5);
			}
			if (p[5] != rvbtime) {
				rvbtime = p[5];
				comb->setReverbTime(rvbtime);
			}
			pctleft = p[7];
			branch = skip;
		}

		float insig, out[2];

		if (currentFrame() < insamps)
			insig = in[i + inchan];
		else
			insig = 0.0;
		out[0] = comb->next(insig, delsamps) * amp;
		if (outputChannels() == 2) {
			out[1] = out[0] * (1.0 - pctleft);
			out[0] *= pctleft;
		}

		rtaddout(out);
		increment();
	}

	return framesToRun();
}
Пример #15
0
/* ------------------------------------------------------------------ run --- */
int RVB::run()
{
	double rvbsig[2][8192];

	// number of samples to process this time through

	const int frames = framesToRun();
    const int rsamps = frames * 2;

    rtgetin(in, this, rsamps);

	register float *outptr = &this->outbuf[0];
	/* run summed 1st and 2nd generation paths through reverberator */
 	for (int n = 0; n < frames; n++) {
		if (--_branch <= 0) {
			double p[4];
			update(p, 4);
			m_amp = p[3];
			_branch = _skip;
		}
		if (m_amp != 0.0) {
			double rmPair[2];
			double rvbPair[2];
			rmPair[0] = globalReverbInput[0][n];
			rmPair[1] = globalReverbInput[1][n];
			doRun(rmPair, rvbPair, currentFrame() + n);
			rvbsig[0][n] = rvbPair[0] * m_amp;
			rvbsig[1][n] = rvbPair[1] * m_amp;
		}
		else
			rvbsig[0][n] = rvbsig[1][n] = 0.0;
		/* sum the direct signal, early response & reverbed sigs  */
		*outptr++ = in[n*2] + globalEarlyResponse[0][n] + rvbsig[0][n];
		*outptr++ = in[n*2+1] + globalEarlyResponse[1][n] + rvbsig[1][n];
	}
	increment(frames);
	
	// Zero out global buffers for next cycle.
	for (int c = 0; c < 2; ++c) {
		memset(globalReverbInput[c], 0, sizeof(double) * RTBUFSAMPS);
		memset(globalEarlyResponse[c], 0, sizeof(double) * RTBUFSAMPS);
	}
	
	DBG(printf("FINAL MIX:\n"));
	DBG(PrintInput(&this->outbuf[i], bufsamps));
	
	return frames;
}
Пример #16
0
int FREEVERB :: run()
{
   float *inL, *inR, *outL, *outR;

   inL = in;
   inR = inputChannels() > 1 ? in + 1 : in;
   outL = outbuf;
   outR = outputChannels() > 1 ? outbuf + 1 : outbuf;

   int samps = framesToRun() * inputChannels();

   if (currentFrame() < insamps)
      rtgetin(in, this, samps);

   // Scale input signal by amplitude multiplier and setline curve.
   for (int i = 0; i < samps; i += inputChannels()) {
      if (--branch <= 0) {
         double p[11];
         update(p, 11, kRoomSize | kPreDelay | kDamp | kDry | kWet | kWidth);
         if (currentFrame() < insamps) {  // amp is pre-effect
            amp = update(3, insamps);
            if (amparray)
               amp *= tablei(currentFrame(), amparray, amptabs);
         }
         updateRvb(p);
         branch = getSkip();
      }
      if (currentFrame() < insamps) {     // still taking input from file
         in[i] *= amp;
         if (inputChannels() == 2)
            in[i + 1] *= amp;
      }
      else {                              // in ringdown phase
         in[i] = 0.0;
         if (inputChannels() == 2)
            in[i + 1] = 0.0;
      }
      increment();
   }

   // Hand off to Freeverb to do the actual work.
   rvb->processreplace(inL, inR, outL, outR, framesToRun(), inputChannels(),
                                                         outputChannels());

   return framesToRun();
}
Пример #17
0
int PANECHO::run()
{
	int samps = framesToRun() * inputChannels();

	if (currentFrame() < insamps)
		rtgetin(in, this, samps);

	for (int i = 0; i < samps; i += inputChannels())  {
		if (--branch <= 0) {
			double p[7];
			update(p, 7, kDelTime0 | kDelTime1 | kDelRegen);
			amp = update(3, insamps);
			if (amptable)
				amp *= tablei(currentFrame(), amptable, amptabs);
			float thisdeltime = p[4];
			if (thisdeltime != prevdeltime0) {
				delsamps0 = getdelsamps(thisdeltime);
				prevdeltime0 = thisdeltime;
			}
			thisdeltime = p[5];
			if (thisdeltime != prevdeltime1) {
				delsamps1 = getdelsamps(thisdeltime);
				prevdeltime1 = thisdeltime;
			}
			regen = p[6];
			branch = getSkip();
		}

		float sig, out[2];

		if (currentFrame() < insamps)
			sig = in[i + inchan] * amp;
		else
			sig = 0.0;

		out[0] = sig + (delay1->getsamp(delsamps1) * regen);
		out[1] = delay0->getsamp(delsamps0);

		delay0->putsamp(out[0]);
		delay1->putsamp(out[1]);

		rtaddout(out);
		increment();
	}
	return framesToRun();
}
Пример #18
0
int CONVOLVE1::run()
{
	const int inchans = inputChannels();
	const int outchans = outputChannels();
	const int nframes = framesToRun();

	if (currentFrame() < _inframes) {
		const int insamps = nframes * inchans;
		rtgetin(_inbuf, this, insamps);
		for (int i = _inchan; i < insamps; i += inchans)
			_bucket->drop(_inbuf[i]);
	}
	else {
		for (int i = 0; i < nframes; i++)
			_bucket->drop(0.0f);
	}
	// If in last run invocation, make sure everything in bucket is processed.
	if (currentFrame() + nframes >= nSamps())
		_bucket->flush();

	float drypct = 1.0 - _wetpct;

	for (int i = 0; i < nframes; i++) {
		if (--_branch <= 0) {
			doupdate();
			drypct = 1.0 - _wetpct;
			_branch = getSkip();
		}

		float out[2];
		out[0] = (_wet[_outReadIndex] * _wetpct) + (_dry[_outReadIndex] * drypct);
		incrementOutReadIndex();
		out[0] *= _amp;

		if (outchans == 2) {
			out[1] = out[0] * (1.0 - _pan);
			out[0] *= _pan;
		}

		rtaddout(out);
		increment();
	}

	return framesToRun();
}
Пример #19
0
// ---------------------------------------------------------------------- run --
int SPECTACLE2_BASE::run()
{
	const int nframes = framesToRun();
	const int inchans = inputChannels();
	const int outchans = outputChannels();

	// If still taking input, store framesToRun() frames into <_inbuf>.
	const bool input_avail = (currentFrame() < _input_frames);
	const int insamps = nframes * inchans;
	if (input_avail)
		rtgetin(_inbuf, this, insamps);

	for (int i = 0; i < nframes; i++) {
		if (--_branch <= 0) {
			doupdate();
			subupdate();
			_branch = getSkip();
		}

		float insig;
		if (input_avail)
			insig = _inbuf[(i * inchans) + _inchan] * _iamp;
		else
			insig = 0.0f;
		_bucket->drop(insig);	// may process <_decimation> input frames

		float outsig = _outbuf[_out_read_index] * _wet;
		increment_out_read_index();

		float drysig = _dry_delay->next(insig);
		outsig += drysig * _dry;

		float out[outchans];
		out[0] = outsig * _oamp;
		if (outchans == 2) {
			out[1] = out[0] * (1.0f - _pan);
			out[0] *= _pan;
		}

		rtaddout(out);
		increment();
	}

	return nframes;
}
Пример #20
0
int MULTEQ :: run()
{
   const int samps = framesToRun() * inputChannels();
   if (currentFrame() < insamps)
      rtgetin(in, this, samps);

   for (int i = 0; i < samps; i += inputChannels()) {
      if (--branch <= 0) {
         doupdate();
         branch = skip;
      }

      float insig[MAXCHAN];
      if (currentFrame() < insamps) {
         for (int c = 0; c < inputChannels(); c++)
            insig[c] = in[i + c];
      }
      else {
         for (int c = 0; c < inputChannels(); c++)
            insig[c] = 0.0;
      }

      float out[MAXCHAN];
      if (bypass) {
         for (int c = 0; c < inputChannels(); c++)
            out[c] = insig[c] * amp;
      }
      else {
         for (int c = 0; c < inputChannels(); c++) {
            for (int b = 0; b < numbands; b++) {
               int index = (b * MAXCHAN) + c;
               insig[c] = eq[index]->next(insig[c]);
            }
            out[c] = insig[c] * amp;
         }
      }

      rtaddout(out);
      increment();
   }

   return framesToRun();
}
Пример #21
0
int VOCODE3::run()
{
	const int inchans = inputChannels();
	const int samps = framesToRun() * inchans;
	rtgetin(_in, this, samps);

	for (int i = 0; i < samps; i += inchans) {
		if (--_branch <= 0) {
			doupdate();
			_branch = getSkip();
		}
		const float carsig = _in[i];
		const float modsig = _in[i + 1];

		float out[2];
		out[0] = 0.0f;
		for (int j = 0; j < _numfilts; j++) {
			float mod;
			if (_hold)
				mod = _lastmod[j];
			else
				mod = _modulator_filt[j]->next(modsig);
			float car = _carrier_filt[_maptable[j]]->next(carsig);
			float balsig = _balancer[j]->next(car, mod);
			if (_scaletable != NULL)
				balsig *= _scaletable[j];
			out[0] += balsig;
		}

		out[0] *= _amp;
		if (outputChannels() == 2) {
			out[1] = out[0] * (1.0f - _pan);
			out[0] *= _pan;
		}

		rtaddout(out);
		increment();
	}

	return framesToRun();
}
Пример #22
0
int DELAY::run()
{
	int samps = framesToRun() * inputChannels();

	if (currentFrame() < insamps)
		rtgetin(in, this, samps);

	for (int i = 0; i < samps; i += inputChannels())  {
		if (--branch <= 0) {
			double p[9];
			update(p, 9, kDelTime | kDelRegen | kPan);
			amp = update(3, insamps);
			if (amptable)
				amp *= tablei(cursamp, amptable, amptabs);
			float deltime = p[4];
			delsamps = deltime * SR;
			regen = p[5];
			pctleft = p[8];
			branch = getSkip();
		}

		float sig, out[2];

		if (currentFrame() < insamps)
			sig = in[i + inchan] * amp;
		else
			sig = 0.0;

		out[0] = sig + (delay->getsamp(delsamps) * regen);
		delay->putsamp(out[0]);

		if (outputChannels() == 2) {
			out[1] = out[0] * (1.0 - pctleft);
			out[0] *= pctleft;
		}

		rtaddout(out);
		increment();
	}
	return framesToRun();
}
Пример #23
0
/* ------------------------------------------------------------------ run --- */
int RVB::run()
{
	double rvbsig[2][8192];
	const int frames = framesToRun();
	const int inChans = inputChannels();

    rtgetin(in, this, frames * inChans);

	register float *outptr = &this->outbuf[0];
	/* run summed 1st and 2nd generation paths through reverberator */
 	for (int n = 0; n < frames; n++) {
		if (--_branch <= 0) {
			double p[4];
			update(p, 4);
			m_amp = p[3];
			_branch = getSkip();
		}
		if (m_amp != 0.0) {
			double rmPair[2];
			double rvbPair[2];
			rmPair[0] = in[n*inChans+2];
			rmPair[1] = in[n*inChans+3];
			doRun(rmPair, rvbPair, currentFrame() + n);
			rvbsig[0][n] = rvbPair[0] * m_amp;
			rvbsig[1][n] = rvbPair[1] * m_amp;
		}
		else
			rvbsig[0][n] = rvbsig[1][n] = 0.0;
		/* sum the input signal (which includes early response) & reverbed sigs  */
		*outptr++ = in[n*inChans] + rvbsig[0][n];
		*outptr++ = in[n*inChans+1] + rvbsig[1][n];
	}
	increment(frames);
		
	DBG(printf("FINAL MIX:\n"));
	DBG(PrintInput(&this->outbuf[0], RTBUFSAMPS));
	DBG(PrintInput(&this->outbuf[1], RTBUFSAMPS));
	
	return frames;
}
Пример #24
0
int FILTSWEEP :: run()
{
   const int samps = framesToRun() * inputChannels();

   if (currentFrame() < insamps)
      rtgetin(in, this, samps);

   for (int i = 0; i < samps; i += inputChannels()) {
      if (--branch <= 0) {
         doupdate();
         branch = getSkip();
      }

      float insig;
      if (currentFrame() < insamps)
         insig = in[i + inchan];
      else
         insig = 0.0;

      float out[2];
      out[0] = insig;
      if (!bypass) {
         for (int j = 0; j < nfilts; j++)
            out[0] = filt[j]->tick(out[0]);
         if (do_balance)
            out[0] = balancer->tick(out[0], insig);
      }

		out[0] *= amp;
      if (outputChannels() == 2) {
         out[1] = out[0] * (1.0 - pctleft);
         out[0] *= pctleft;
      }

      rtaddout(out);
      increment();
   }

   return framesToRun();
}
int DCBLOCK::run()
{
	const int samps = framesToRun() * _chans;

	rtgetin(_in, this, samps);

	for (int i = 0; i < samps; i += _chans) {
		if (--_branch <= 0) {
			doupdate();
			_branch = getSkip();
		}

		float out[_chans];
		for (int n = 0; n < _chans; n++)
			out[n] = _blocker[n]->next(_in[i + n]) * _amp;

		rtaddout(out);
		increment();
	}

	return framesToRun();
}
Пример #26
0
int REV :: run()
{
   int samps = framesToRun() * inputChannels();

   if (currentFrame() < insamps)
      rtgetin(in, this, samps);

   for (int i = 0; i < samps; i += inputChannels()) {
      if (--branch <= 0) {
         amp = update(3, insamps);
         if (amparray)
            amp *= tablei(cursamp, amparray, amptabs);
         const double wetdrymix = update(6);
         reverb->setEffectMix(wetdrymix);
         branch = getSkip();
      }

      float insig;
      if (cursamp < insamps)                 // still taking input from file
         insig = in[i + inchan] * amp;
      else                                   // in ring-down phase
         insig = 0.0;

      reverb->tick(insig);

      float out[2];
      if (outputChannels() == 2) {
         out[0] = reverb->lastOutputL();
         out[1] = reverb->lastOutputR();
      }
      else
         out[0] = reverb->lastOutput();

      rtaddout(out);
      increment();
   }

   return framesToRun();
}
Пример #27
0
int MIX::run()
{
	const int inchans = inputChannels();
	const int samps = framesToRun() * inchans;

	rtgetin(in, this, samps);

	for (int i = 0; i < samps; i += inchans)  {
		if (--branch <= 0) {
			if (fastUpdate) {
				if (amptable)
					amp = ampmult * tablei(currentFrame(), amptable, amptabs);
			}
			else {
				double p[4];
				update(p, 4, 1 << 3);
				amp = p[3];
				if (amptable)		// legacy makegen
					amp *= tablei(currentFrame(), amptable, amptabs);
			}
			branch = getSkip();
		}

		float out[MAXBUS];
		const int ochans = outputChannels();
		for (int j = 0; j < ochans; j++) {
			out[j] = 0.0;
			for (int k = 0; k < inchans; k++) {
				if (outchan[k] == j)
					out[j] += in[i+k] * amp;
			}
		}

		rtaddout(out);
		increment();
	}
	return framesToRun();
}
Пример #28
0
int PAN :: run()
{
   const int samps = framesToRun() * inputChannels();

   rtgetin(in, this, samps);

   for (int i = 0; i < samps; i += inputChannels()) {
      if (--branch <= 0) {
         doupdate();
         branch = skip;
      }
      float insig = in[i + inchan] * amp;

      float out[2];
      out[0] = insig * pan[0];
      out[1] = insig * pan[1];

      rtaddout(out);
      increment();
   }

   return framesToRun();
}
Пример #29
0
int DEL1::run()
{
	int samps = framesToRun() * inputChannels();

	if (currentFrame() < insamps)
		rtgetin(in, this, samps);

	for (int i = 0; i < samps; i += inputChannels())  {
		if (--branch <= 0) {
			double p[6];
			update(p, 6);
			amp = p[3];
			if (amptable)
				amp *= tablei(cursamp, amptable, amptabs);
			float deltime = p[4];
			delsamps = deltime * SR;
			delamp = p[5];
			branch = skip;
		}

		float sig;
		if (currentFrame() < insamps)
			sig = in[i + inchan];
		else
			sig = 0.0;

		float out[2];
		out[0] = sig * amp;
		out[1] = delay->getsamp(delsamps) * delamp;
		delay->putsamp(sig);

		rtaddout(out);
		increment();
	}
	return framesToRun();
}
Пример #30
0
  /**
   * For Lua instruments, the run method also performs the Lua 
   * portion of the init method. That is because the init 
   * method is called from the main RTcmix thread whereas the 
   * run method is called from the traverse thread, but Lua 
   * is not thread-safe and our Lua state management code
   * creates a separate Lua state for each thread.
   */
  virtual int run()
  {
    //advise("LUAINST::run", "Began (thread %p)...", pthread_self());
    int result = 0;
    if (state.parameters[2] != 0.0) 
      {
	state.inputSampleCount = RTBUFSAMPS * inputChannels();
	rtgetin(state.input, this, state.inputSampleCount);
      }
    lua_State *L = manageLuaState();
    LuaInstrumentClass_t &luaInstrumentClass = manageLuaInstrumentClass(L, state.name);
    if (!luaInstrumentClass.initialized) 
      {
	const char *luacode = luaCodeForInstrumentNames[state.name].c_str();
	advise("LUAINST", "Defining Lua instrument code:\n\n%0.120s\n...\n", luacode);
	result = luaL_dostring(L, luacode);
	if (result == 0)
	  {
	    char init_function[0x100];
	    std::snprintf(init_function, 0x100, "%s_init", state.name);
	    lua_getglobal(L, init_function);
	    if (!lua_isnil(L, 1))
	      {
		luaInstrumentClass.init_key = luaL_ref(L, LUA_REGISTRYINDEX);
		lua_pop(L, 1);
	      }
	    else
	      {
		exit(die("LUAINST", "Failed to register: %s.", init_function));
	      }
	    char run_function[0x100];
	    std::snprintf(run_function, 0x100, "%s_run", state.name);
	    lua_getglobal(L, run_function);
	    if (!lua_isnil(L, 1))
	      {
		luaInstrumentClass.run_key = luaL_ref(L, LUA_REGISTRYINDEX);
		lua_pop(L, 1);
	      }
	    else
	      {
		exit(die("LUAINST", "Failed to register: %s.", run_function));
	      }
	  }
	else
	  {
	    warn("LUAINST", "Failed with: %d\n", result);
	  }
	luaInstrumentClass.initialized = true;
      }
    if (!state.initialized) 
      {
	lua_rawgeti(L, LUA_REGISTRYINDEX, luaInstrumentClass.init_key);
	lua_pushlightuserdata(L, &state);
	if (lua_pcall(L, 1, 1, 0) != 0)
	  {
	    rterror("LUAINST", "Lua error in \"%s_init\": %s.\n", state.name, lua_tostring(L, -1));
	  }
	result = lua_tonumber(L, -1);
	lua_pop(L, 1);
	state.initialized = true;
      }
    state.startFrame = state.endFrame;
    long frameCount = framesToRun();
    state.endFrame += frameCount;
    doupdate();
    lua_rawgeti(L, LUA_REGISTRYINDEX, luaInstrumentClass.run_key);
    lua_pushlightuserdata(L, &state);
    if (lua_pcall(L, 1, 1, 0) != 0)
      {
	die("LUAINST", "Lua error in \"%s_run\": %s with key %p frame %i.\n", state.name, lua_tostring(L, -1), luaInstrumentClass.run_key, state.currentFrame);
	exit(-1);
      }
    result = lua_tonumber(L, -1);
    lua_pop(L, 1);
    rtbaddout(state.output, frameCount);
    increment(frameCount);
    return framesToRun();
  }