Skip to content

Commit

Permalink
improvements to Demand UGens:
Browse files Browse the repository at this point in the history
- TDuty outputs first level immediately
- added Dbufwr
- made Dbufrd audio rate compatible

git-svn-id: https://supercollider.svn.sourceforge.net/svnroot/supercollider/trunk@7120 a380766d-ff14-0410-b294-a243070f3f08
  • Loading branch information
Julian Rohrhuber committed Jan 27, 2008
1 parent 2e70ba4 commit 08ee87e
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 14 deletions.
89 changes: 76 additions & 13 deletions Source/plugins/DemandUGens.cpp
Expand Up @@ -126,6 +126,13 @@ struct Dbufrd : public Unit
SndBuf *m_buf;
};

struct Dbufwr : public Unit
{
float m_fbufnum;
float m_pos;
SndBuf *m_buf;
};

struct Dser : public Dseq
{
};
Expand Down Expand Up @@ -195,6 +202,9 @@ void Dseq_next(Dseq *unit, int inNumSamples);
void Dbufrd_Ctor(Dbufrd *unit);
void Dbufrd_next(Dbufrd *unit, int inNumSamples);

void Dbufwr_Ctor(Dbufwr *unit);
void Dbufwr_next(Dbufwr *unit, int inNumSamples);

void Dser_Ctor(Dser *unit);
void Dser_next(Dser *unit, int inNumSamples);

Expand Down Expand Up @@ -1280,8 +1290,12 @@ void TDuty_Ctor(TDuty *unit)
unit->m_prevreset = 0.f;
}
}

unit->m_count = DEMANDINPUT(duty_dur) * SAMPLERATE;
// support for gap-first.
if(IN0(4)) {
unit->m_count = DEMANDINPUT(duty_dur) * SAMPLERATE;
} else {
unit->m_count = 0.f;
}
OUT0(0) = 0.f;
}

Expand Down Expand Up @@ -1746,7 +1760,7 @@ void Dswitch_next(Dswitch *unit, int inNumSamples)
val = DEMANDINPUT_A(unit->m_index, inNumSamples);

RESETINPUT(unit->m_index);
printf("resetting index: %i\n", unit->m_index);
// printf("resetting index: %i\n", unit->m_index);
unit->m_index = index;
}
OUT0(0) = val;
Expand Down Expand Up @@ -1828,7 +1842,6 @@ inline double sc_loop(Unit *unit, double in, double hi, int loop)

void Dbufrd_next(Dbufrd *unit, int inNumSamples)
{
// float *phasein = ZIN(1);
int32 loop = (int32)IN0(2);

GET_BUF
Expand All @@ -1839,16 +1852,12 @@ void Dbufrd_next(Dbufrd *unit, int inNumSamples)
double phase;
if (inNumSamples)
{
if (ISDEMANDINPUT(1))
{
float x = DEMANDINPUT_A(1, inNumSamples);
if (sc_isnan(x)) {
float x = DEMANDINPUT_A(1, inNumSamples);
if (sc_isnan(x)) {
OUT0(0) = NAN;
return; //x = 0.0;
}
phase = x;
} else
phase = IN0(1);
return;
}
phase = x;

phase = sc_loop((Unit*)unit, phase, loopMax, loop);
int32 iphase = (int32)phase;
Expand All @@ -1872,6 +1881,59 @@ void Dbufrd_Ctor(Dbufrd *unit)
OUT0(0) = 0.f;
}

////////////////////////////////////

void Dbufwr_next(Dbufwr *unit, int inNumSamples)
{

int32 loop = (int32)IN0(3);

GET_BUF
CHECK_BUF

double loopMax = (double)(loop ? bufFrames : bufFrames - 1);

double phase;
float val;
if (inNumSamples)
{
float x = DEMANDINPUT_A(1, inNumSamples);
if (sc_isnan(x)) {
OUT0(0) = NAN;
return;
}
phase = x;
float val = DEMANDINPUT_A(2, inNumSamples);
if (sc_isnan(val)) {
OUT0(0) = NAN;
return;
}

phase = sc_loop((Unit*)unit, phase, loopMax, loop);
int32 iphase = (int32)phase;
float* table0 = bufData + iphase * bufChannels;
table0[0] = val;
}
else
{
RESETINPUT(1);
RESETINPUT(2);
}
}

void Dbufwr_Ctor(Dbufwr *unit)
{

SETCALC(Dbufwr_next);

unit->m_fbufnum = -1e9f;

Dbufwr_next(unit, 0);
ClearUnitOutputs(unit, 1);

}


//////////////////////////////////////////////////////


Expand All @@ -1893,6 +1955,7 @@ void load(InterfaceTable *inTable)
DefineSimpleUnit(Dseq);
DefineSimpleUnit(Dser);
DefineSimpleUnit(Dbufrd);
DefineSimpleUnit(Dbufwr);
DefineSimpleUnit(Drand);
DefineSimpleUnit(Dxrand);
DefineSimpleUnit(Dswitch1);
Expand Down
25 changes: 24 additions & 1 deletion build/SCClassLibrary/Common/Audio/Demand.sc
Expand Up @@ -32,7 +32,24 @@ Duty : UGen {
}
}

TDuty : Duty {}
TDuty : Duty {
*ar { arg dur=1.0, reset=0.0, level=1.0, doneAction=0, gapFirst=0;
^this.multiNew('audio', dur, reset, doneAction, level, gapFirst)
}
*kr { arg dur=1.0, reset=0.0, level=1.0, doneAction=0, gapFirst=0;
^this.multiNew('control', dur, reset, doneAction, level, gapFirst)
}
}

// old version with gap first
TDuty_old {
*ar { arg dur=1.0, reset=0.0, level=1.0, doneAction=0;
^TDuty.ar(dur, reset, level, doneAction, 1)
}
*kr { arg dur=1.0, reset=0.0, level=1.0, doneAction=0;
^TDuty.kr(dur, reset, level, doneAction, 1)
}
}

DemandEnvGen : UGen {

Expand Down Expand Up @@ -80,6 +97,12 @@ Dbufrd : DUGen {
}
}

Dbufwr : DUGen {
*new { arg input=0.0, bufnum=0, phase=0.0, loop=1.0;
^this.multiNew('demand', bufnum, phase, input, loop)
}
}

ListDUGen : DUGen {
*new { arg list, repeats=1;
^this.multiNewList(['demand', repeats] ++ list)
Expand Down

0 comments on commit 08ee87e

Please sign in to comment.