void Dswitch_next(Dswitch *unit, int inNumSamples) { int index; float ival; if (inNumSamples) { float val = DEMANDINPUT_A(unit->m_index, inNumSamples); //printf("index: %i\n", (int) val); if(sc_isnan(val)) { ival = DEMANDINPUT_A(0, inNumSamples); if(sc_isnan(ival)) { OUT0(0) = ival; return; } index = (int32)floor(ival + 0.5f); index = sc_wrap(index, 0, unit->mNumInputs - 2) + 1; val = DEMANDINPUT_A(unit->m_index, inNumSamples); RESETINPUT(unit->m_index); // printf("resetting index: %i\n", unit->m_index); unit->m_index = index; } OUT0(0) = val; } else { printf("...\n"); for (int i=0; i<unit->mNumInputs; ++i) { RESETINPUT(i); } index = (int32)floor(DEMANDINPUT(0) + 0.5f); index = sc_wrap(index, 0, unit->mNumInputs - 1) + 1; unit->m_index = index; } }
PulseDPW2(): mFreq(std::numeric_limits<float>::quiet_NaN()), mLastVal0(0), mLastVal1(0) { const float width = in0(1); const float phase = in0(2); mPhase0 = sc_wrap(phase, -1.0f, 1.0f); mPhase1 = sc_wrap(phase + width + width, -1.0f, 1.0f); switch (inRate(0)) { case calc_ScalarRate: { float freq = in0(0); float scale; double phaseIncrement; updateFrequency<true>(freq, scale, phaseIncrement); set_calc_function<PulseDPW2, &PulseDPW2::next_i>(); break; } case calc_BufRate: set_calc_function<PulseDPW2, &PulseDPW2::next_k>(); break; case calc_FullRate: set_calc_function<PulseDPW2, &PulseDPW2::next_a>(); } }
void DbufTag_end(DbufTag *unit, int which_case, int inNumSamples) { int recycle = (int) DEMANDINPUT_A(dtag_recycle, inNumSamples); int mode = (int) IN0(dtag_mode); if(which_case == 0) { DbufTag_reset(unit, recycle, inNumSamples); if(mode == 4) { printf("tag system was reset externally.\n"); if(recycle) { printf("recycling. axiom length: %d\n", recycle); } } return; } if((mode == 0) || (mode == which_case)) { if(recycle) { DbufTag_reset(unit, recycle, inNumSamples); } else { OUT0(0) = NAN; } return; } if(mode >= 4) { printf("tag system halt: "); if(which_case == 1) { printf("divergence too large (buffer filled up).\n"); } else { printf("terminated (string empty)\n"); } if(recycle) { printf("recycling. axiom length: %d\n", recycle); //printf("new axiom:\n"); // todo. DbufTag_reset(unit, recycle, inNumSamples); GET_BUF printf("new axiom (index %ld..%ld): ", unit->m_read_pos, unit->m_write_pos); int32 n = unit->m_write_pos - unit->m_read_pos; if(n < 0) { n = sc_wrap(n, 0, bufFrames - 1); } for(int32 i=0; i < n; i++) { int32 j = sc_wrap(unit->m_read_pos + i, 0, bufFrames - 1); printf("%d ", (int)bufData[j]); } printf("\n"); } else { OUT0(0) = NAN; } return; } OUT0(0) = NAN; }
void LFDNoise1_ar::m_signal(int n, t_sample *const *in, t_sample *const *out) { t_sample *nout = *out; float prevLevel = m_prevlevel; float nextLevel = m_nextlevel; float phase = m_phase; RGET; if (m_ar) { t_sample *nin = *in; float smpdur = m_smpdur; for (int i = 0; i!= n; ++i) { phase -= ZXP(nin) * smpdur; if (phase <= 0) { phase = sc_wrap(phase, 0.f, 1.f); prevLevel = nextLevel; nextLevel = frand2(s1,s2,s3); } ZXP(nout) = nextLevel + ( phase * (prevLevel - nextLevel) ); } } else { float dphase = m_smpdur * m_freq; for (int i = 0; i!= n; ++i) { phase -= dphase; if (phase <= 0) { phase = sc_wrap(phase, 0.f, 1.f); prevLevel = nextLevel; nextLevel = frand2(s1,s2,s3); } ZXP(nout) = nextLevel + ( phase * (prevLevel - nextLevel) ); } } m_prevlevel = prevLevel; m_nextlevel = nextLevel; m_phase = phase; RPUT; }
void Dswitch_Ctor(Dswitch *unit) { SETCALC(Dswitch_next); int index = (int32)floor(DEMANDINPUT(0) + 0.5f); index = sc_wrap(index, 0, unit->mNumInputs - 1) + 1; unit->m_index = index; OUT0(0) = 0.f; }
void LFDNoise0_next(LFDNoise0 *unit, int inNumSamples) { float *out = ZOUT(0); float *freq = ZIN(0); float level = unit->mLevel; float phase = unit->mPhase; float smpdur = SAMPLEDUR; RGET LOOP1(inNumSamples, phase -= ZXP(freq) * smpdur; if (phase < 0) { phase = sc_wrap(phase, 0.f, 1.f); level = frand2(s1,s2,s3); } ZXP(out) = level; )
void Dswitch1_next(Dswitch1 *unit, int inNumSamples) { if (inNumSamples) { float x = DEMANDINPUT_A(0, inNumSamples); if (sc_isnan(x)) { OUT0(0) = x; return; } int index = (int32)floor(x + 0.5f); index = sc_wrap(index, 0, unit->mNumInputs - 2) + 1; OUT0(0) = DEMANDINPUT_A(index, inNumSamples); } else { for (int i=0; i<unit->mNumInputs; ++i) { RESETINPUT(i); } } }
void LFDClipNoise_next_k(LFDClipNoise *unit, int inNumSamples) { float *out = ZOUT(0); float freq = ZIN0(0); float level = unit->mLevel; float phase = unit->mPhase; float smpdur = SAMPLEDUR; float dphase = smpdur * freq; RGET LOOP1(inNumSamples, phase -= dphase; if (phase < 0) { phase = sc_wrap(phase, 0.f, 1.f); level = fcoin(s1,s2,s3); } ZXP(out) = level; )
void LFDNoise1_next(LFDNoise1 *unit, int inNumSamples) { float *out = ZOUT(0); float *freq = ZIN(0); float prevLevel = unit->mPrevLevel; float nextLevel = unit->mNextLevel; float phase = unit->mPhase; float smpdur = SAMPLEDUR; RGET LOOP1(inNumSamples, phase -= ZXP(freq) * smpdur; if (phase < 0) { phase = sc_wrap(phase, 0.f, 1.f); prevLevel = nextLevel; nextLevel = frand2(s1,s2,s3); } ZXP(out) = nextLevel + ( phase * (prevLevel - nextLevel) ); )
void Dtag_reset(Dtag *unit, int recycle, int inNumSamples) { RESETINPUT(dtag_deletion_number); // reset deletion number // other than in DbufTag, m_axiom_size doesn't have to be checked again here, since buffer is fix. if(recycle == 0) { // recycle = 0 - write axiom to buffer again. unit->m_read_pos = 0; unit->m_write_pos = (int32) unit->m_axiom_size; // write axiom to tape for(int i = 0; i < unit->m_axiom_size; i++) { unit->m_tape[i] = DEMANDINPUT_A(dtag_argoffset + i, inNumSamples); // printf("axiom[%ld] = %ld\n", i, unit->m_tape[i]); } } else if (recycle < 0) { // recycle < 0 - write_pos is left where it is, read_pos is offset by recycle value if(unit->m_write_pos >= unit->m_tape_size) { unit->m_write_pos = unit->m_write_pos % unit->m_tape_size; } unit->m_read_pos = unit->m_write_pos + recycle; if(unit->m_read_pos < 0) { unit->m_read_pos = sc_wrap(unit->m_read_pos, 0, unit->m_tape_size - 1); } } else { // recycle > 0 - read_pos is left where it is, write_pos is offset by recycle value if(unit->m_read_pos >= unit->m_tape_size) { unit->m_read_pos = unit->m_read_pos % unit->m_tape_size; } unit->m_write_pos = unit->m_read_pos + recycle; if(unit->m_write_pos >= unit->m_tape_size) { unit->m_write_pos = unit->m_write_pos % unit->m_tape_size; } } }
void LFDNoise3_next_k(LFDNoise3 *unit, int inNumSamples) { float *out = ZOUT(0); float freq = ZIN0(0); float a = unit->mLevelA; float b = unit->mLevelB; float c = unit->mLevelC; float d = unit->mLevelD; float phase = unit->mPhase; float dphase = freq * SAMPLEDUR; RGET LOOP1(inNumSamples, phase -= dphase; if (phase < 0) { phase = sc_wrap(phase, 0.f, 1.f); a = b; b = c; c = d; d = frand2(s1,s2,s3) * 0.8f; // limits max interpol. overshoot to 1. } ZXP(out) = cubicinterp(1.f - phase, a, b, c, d); )