mirror of
https://github.com/thestk/stk
synced 2026-01-13 04:51:53 +00:00
Version 4.2.0
This commit is contained in:
committed by
Stephen Sinclair
parent
cf06b7598b
commit
a6381b9d38
@@ -2,10 +2,10 @@
|
||||
/*! \class Sampler
|
||||
\brief STK sampling synthesis abstract base class.
|
||||
|
||||
This instrument contains up to 5 attack waves,
|
||||
5 looped waves, and an ADSR envelope.
|
||||
This instrument provides an ADSR envelope, a one-pole filter, and
|
||||
structures for an arbitrary number of attack and loop waves.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
@@ -15,45 +15,40 @@ Sampler :: Sampler()
|
||||
{
|
||||
// We don't make the waves here yet, because
|
||||
// we don't know what they will be.
|
||||
adsr = new ADSR;
|
||||
baseFrequency = 440.0;
|
||||
filter = new OnePole;
|
||||
attackGain = 0.25;
|
||||
loopGain = 0.25;
|
||||
whichOne = 0;
|
||||
baseFrequency_ = 440.0;
|
||||
attackGain_ = 0.25;
|
||||
loopGain_ = 0.25;
|
||||
}
|
||||
|
||||
Sampler :: ~Sampler()
|
||||
{
|
||||
delete adsr;
|
||||
delete filter;
|
||||
unsigned int i;
|
||||
for ( i=0; i<attacks_.size(); i++ ) delete attacks_[i];
|
||||
for ( i=0; i<loops_.size(); i++ ) delete loops_[i];
|
||||
}
|
||||
|
||||
void Sampler :: keyOn()
|
||||
{
|
||||
adsr->keyOn();
|
||||
attacks[0]->reset();
|
||||
// Reset all attack waves.
|
||||
for ( unsigned int i=0; i<attacks_.size(); i++ )
|
||||
attacks_[i]->reset();
|
||||
|
||||
// Start the envelope.
|
||||
adsr_.keyOn();
|
||||
|
||||
}
|
||||
|
||||
void Sampler :: keyOff()
|
||||
{
|
||||
adsr->keyOff();
|
||||
adsr_.keyOff();
|
||||
}
|
||||
|
||||
void Sampler :: noteOff(MY_FLOAT amplitude)
|
||||
void Sampler :: noteOff(StkFloat amplitude)
|
||||
{
|
||||
this->keyOff();
|
||||
|
||||
#if defined(_STK_DEBUG_)
|
||||
cerr << "Sampler: NoteOff amplitude = " << amplitude << endl;
|
||||
errorString_ << "Sampler::NoteOff: amplitude = " << amplitude << ".";
|
||||
handleError( StkError::DEBUG_WARNING );
|
||||
#endif
|
||||
}
|
||||
|
||||
MY_FLOAT Sampler :: tick()
|
||||
{
|
||||
lastOutput = attackGain * attacks[whichOne]->tick();
|
||||
lastOutput += loopGain * loops[whichOne]->tick();
|
||||
lastOutput = filter->tick(lastOutput);
|
||||
lastOutput *= adsr->tick();
|
||||
return lastOutput;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user