Version 4.4.0

This commit is contained in:
Gary Scavone
2013-09-29 23:11:39 +02:00
committed by Stephen Sinclair
parent d199342e86
commit eccd8c9981
287 changed files with 11712 additions and 7676 deletions

View File

@@ -1,79 +1,98 @@
#ifndef STK_SINGWAVE_H
#define STK_SINGWAVE_H
#include "FileLoop.h"
#include "Modulate.h"
#include "Envelope.h"
namespace stk {
/***************************************************/
/*! \class SingWave
\brief STK "singing" looped soundfile class.
This class contains all that is needed to make
a pitched musical sound, like a simple voice
or violin. In general, it will not be used
alone because of munchkinification effects
from pitch shifting. It will be used as an
excitation source for other instruments.
This class loops a specified soundfile and modulates it both
periodically and randomly to produce a pitched musical sound, like
a simple voice or violin. In general, it is not be used alone
because of "munchkinification" effects from pitch shifting.
Within STK, it is used as an excitation source for other
instruments.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_SINGWAVE_H
#define STK_SINGWAVE_H
#include "WaveLoop.h"
#include "Modulate.h"
#include "Envelope.h"
class SingWave : public Generator
{
public:
//! Class constructor taking filename argument.
/*!
An StkError will be thrown if the file is not found, its format is
unknown, a read error occurs, or the rawwave path is incorrectly set.
An StkError will be thrown if the file is not found, its format
is unknown, or a read error occurs. If the soundfile has no
header, the second argument should be \e true and the file data
will be assumed to consist of 16-bit signed integers in big-endian
byte order at a sample rate of 22050 Hz.
*/
SingWave( std::string fileName, bool raw = false);
SingWave( std::string fileName, bool raw = false );
//! Class destructor.
~SingWave();
~SingWave( void );
//! Reset file to beginning.
void reset();
void reset( void ) { wave_.reset(); lastFrame_[0] = 0.0; };
//! Normalize the file to a maximum of +-1.0.
void normalize();
void normalize( void ) { wave_.normalize(); };
//! Normalize the file to a maximum of \e +- peak.
void normalize(StkFloat peak);
void normalize( StkFloat peak ) { wave_.normalize( peak ); };
//! Set instrument parameters for a particular frequency.
void setFrequency(StkFloat frequency);
//! Set looping parameters for a particular frequency.
void setFrequency( StkFloat frequency );
//! Set the vibrato frequency in Hz.
void setVibratoRate(StkFloat rate);
void setVibratoRate( StkFloat rate ) { modulator_.setVibratoRate( rate ); };
//! Set the vibrato gain.
void setVibratoGain(StkFloat gain);
void setVibratoGain( StkFloat gain ) { modulator_.setVibratoGain( gain ); };
//! Set the random-ness amount.
void setRandomGain(StkFloat gain);
void setRandomGain( StkFloat gain ) { modulator_.setRandomGain( gain ); };
//! Set the sweep rate.
void setSweepRate(StkFloat rate);
void setSweepRate( StkFloat rate ) { sweepRate_ = rate; };
//! Set the gain rate.
void setGainRate(StkFloat rate);
void setGainRate( StkFloat rate ) { envelope_.setRate( rate ); };
//! Set the gain target value.
void setGainTarget(StkFloat target);
void setGainTarget( StkFloat target ) { envelope_.setTarget( target ); };
//! Start a note.
void noteOn();
void noteOn( void ) { envelope_.keyOn(); };
//! Stop a note.
void noteOff();
void noteOff( void ) { envelope_.keyOff(); };
//! Return the last computed output value.
StkFloat lastOut( void ) const { return lastFrame_[0]; };
//! Compute and return one output sample.
StkFloat tick( void );
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument must be less than the number of
channels in the StkFrames argument (the first channel is specified
by 0). However, range checking is only performed if _STK_DEBUG_
is defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
protected:
StkFloat computeSample( void );
WaveLoop *wave_;
FileLoop wave_;
Modulate modulator_;
Envelope envelope_;
Envelope pitchEnvelope_;
@@ -82,4 +101,36 @@ class SingWave : public Generator
};
inline StkFloat SingWave :: tick( void )
{
// Set the wave rate.
StkFloat newRate = pitchEnvelope_.tick();
newRate += newRate * modulator_.tick();
wave_.setRate( newRate );
lastFrame_[0] = wave_.tick();
lastFrame_[0] *= envelope_.tick();
return lastFrame_[0];
}
inline StkFrames& SingWave :: tick( StkFrames& frames, unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel >= frames.channels() ) {
errorString_ << "SingWave::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *samples = &frames[channel];
unsigned int hop = frames.channels();
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
*samples = SingWave::tick();
return frames;
}
} // stk namespace
#endif