120 *ptr++ = sinf(accum);
134 if ( ! mWavetable.mAreBuffersAllocated)
137 unsigned tableLength = mWavetable.mNumFrames;
138 float rateRecip = (float) tableLength / (
float)
mFrameRate;
139 float phase = mPhase;
140 unsigned numFrames = outputBuffer.mNumFrames;
144 logMsg(
"WavetableOscillator nextBuffer");
153 switch (mInterpolate) {
155 for (
unsigned i = 0; i < numFrames; i++) {
156 while (phase >= tableLength)
157 phase -= tableLength;
159 phase += tableLength;
160 index = (
unsigned int) floorf(phase);
161 samp1 = waveform[index];
162 *buffer++ = (samp1 * scaleValue) + offsetValue;
163 phase += (freqValue * rateRecip);
169 for (
unsigned i = 0; i < numFrames; i++) {
170 index = (
unsigned int) floorf(phase);
171 fraction = phase - (float) index;
172 samp1 = waveform[index];
173 if (index < (tableLength - 1))
174 samp2 = waveform[index+1];
177 samp1 += (samp2 - samp1) * fraction;
178 *buffer++ = (samp1 * scaleValue) + offsetValue;
179 phase += (freqValue * rateRecip);
180 while (phase >= tableLength)
181 phase -= tableLength;
187 throw LogicError(
"Unimplemented truncation policy");
214 outputBuffer.zeroBuffers();
216 this->nextWaveInto(buffer, outputBuffer.mNumFrames,
false);
223 Sine::Sine(
float frequency,
float ampl,
float offset,
float phase)
224 :
Oscillator(frequency, ampl, offset, phase) { }
231 unsigned numFrames = outputBuffer.mNumFrames;
232 float phase = mPhase;
236 logMsg(
"Sine nextBuffer");
242 for (
unsigned i = 0; i < numFrames; i++) {
243 *buffer++ = (sinf(phase) * scaleValue) + offsetValue;
244 phase += (freqValue * rateRecip);
258 :
Oscillator(frequency, ampl, offset, phase) { }
265 unsigned numFrames = outputBuffer.mNumFrames;
266 float phase = mPhase;
270 logMsg(
"Sine nextBuffer");
276 for (
unsigned i = 0; i < numFrames; i++) {
277 *buffer++ = (sinf(phase) * scaleValue) + offsetValue;
278 phase += (freqValue * rateRecip);
292 :
Oscillator(frequency, ampl, offset, phase) { }
297 unsigned numFrames = outputBuffer.mNumFrames;
298 float phase = mPhase;
302 logMsg(
"Sine nextBuffer");
307 for (
unsigned i = 0; i < numFrames; i++) {
308 *buffer++ = phase * scaleValue + offsetValue;
309 phase += (freqValue * rateRecip);
323 :
Oscillator(frequency, ampl, offset, phase) { }
328 unsigned numFrames = outputBuffer.mNumFrames;
329 float phase = mPhase;
333 logMsg(
"Sine nextBuffer");
338 for (
unsigned i = 0; i < numFrames; i++) {
339 *buffer++ = ((phase > 0.0) ? 1.0f : -1.0f) * scaleValue + offsetValue;
340 phase += (freqValue * rateRecip);
368 unsigned numFrames = outputBuffer.mNumFrames;
370 int count = mCounter;
374 logMsg(
"Sine nextBuffer");
380 for (i = 0; i < numFrames; i++)
382 }
else if (count < numFrames) {
383 for (i = 0; i < count; i++)
385 *buffer++ = scaleValue;
386 for (j = count+1; j < numFrames; j++)
389 for (i = 0; i < numFrames; i++)
392 mCounter = count - numFrames;
404 float num=0, amp=0, pha=0;
407 va_start(ap, partialCount);
408 for (
unsigned i = 0; i < partialCount; i++) {
411 num = (float) (i + 1);
412 amp = va_arg(ap,
double);
416 num = va_arg(ap,
double);
417 amp = va_arg(ap,
double);
421 num = va_arg(ap,
double);
422 amp = va_arg(ap,
double);
423 pha = va_arg(ap,
double);
451 for (
unsigned i = 0; i < numHarms; i++) {
452 float ampl =
fRandV(noise) / (float) (i + 2);
462 for (
unsigned i = 0; i < numHarms; i++) {
492 for (
unsigned i = 0; i < num_p; i++)
498 float ** v_ptr = (
float ** ) argv;
502 part->
number = * v_ptr[i++];
515 float incr, t_incr, phase, ampl;
517 unsigned numFrames = count;
528 for (
unsigned i = 0; i <
mPartials.size(); i++) {
532 t_incr = incr * p->
number;
536 for (
unsigned j = 0; j < numFrames; j++) {
537 *out_ptr++ += (sinf(phase) * ampl);
541 for (
unsigned j = 0; j < numFrames; j++) {
542 *out_ptr++ += (sinf(phase) * ampl * scaleValue) + offsetValue;
543 phase += (t_incr * freqValue);
550 freqPort->resetPtr();
551 scalePort->resetPtr();
552 offsetPort->resetPtr();
553 freqValue = freqPort->nextValue();
554 scaleValue = scalePort->nextValue();
555 offsetValue = offsetPort->nextValue();
565 logMsg(
"a SumOfSines: %d partials", siz);
566 for (
unsigned i = 0; i < siz; i++)
sample * SampleBuffer
1-channel buffer data type, vector of (sample)
bool mAreBuffersZero
have the buffers been zeroed out?
#define UPDATE_SCALABLE_CONTROLS
void logMsg(const char *format,...)
These are the public logging messages.
void nextWaveInto(SampleBuffer dest, unsigned count, bool oneHz)
#define kFrequency
Enum for SumOfSines description formats.
float fRandV(float val)
0 - v (val)
static Buffer * sSineTable
void nextBuffer(Buffer &outputBuffer, unsigned outBufNum)
really compute the next buffer given an offset base channel; this is called by nextBuffer, possibly multiple times
#define DECLARE_PHASED_CONTROLS
Macros for all the Phased UnitGenerators (note that these don't end with ";") These make some assumpt...
unsigned mNumFrames
num frames used in each buffer
void nextBuffer(Buffer &outputBuffer, unsigned outBufNum)
really compute the next buffer given an offset base channel; this is called by nextBuffer, possibly multiple times
virtual void setBuffer(unsigned bufNum, SampleBuffer sPtr)
FSine(float frequency=220, float ampl=1.0, float offset=0.0, float phase=0.0)
static unsigned mFrameRate
default sample rate (tested up to 96000)
bool mAreBuffersAllocated
are the buffers allocated?
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
virtual void nextBuffer(Buffer &outputBuffer, unsigned outBufNum)
really compute the next buffer given an offset base channel; this is called by nextBuffer, possibly multiple times
WavetableOscillator – Oscillator with a stored wave table that does table look-up. The default wave table is an 8192-sample sine. (perhaps accept a vector of freqs and a multichannel buffer?)
WavetableOscillator(Buffer &wave)
Destructor.
unsigned mFrameRate
trigger ignored here
Phased – a mix-in for objects with phase accumulators (local float) and frequency controls (an input...
void nextBuffer(Buffer &outputBuffer, unsigned outBufNum)
really compute the next buffer given an offset base channel; this is called by nextBuffer, possibly multiple times
virtual SampleBuffer buffer(unsigned bufNum)
convenience accessors for sample buffers
virtual void nextBuffer(Buffer &outputBuffer, unsigned outBufNum)
really compute the next buffer given an offset base channel; this is called by nextBuffer, possibly multiple times
#define DEFAULT_WTABLE_SIZE
selected hardware interface at startup time
std::vector< Partial * > mPartials
void dump()
print the receiver for debugging
void addPartials(unsigned num_p, Partial **pt)
void freeBuffers()
fcn to free them
Square(float frequency=220, float ampl=1.0, float offset=0.0, float phase=0.0)
void setSize(unsigned numChannels, unsigned numFrames)
unsigned mMonoBufferByteSize
size of each buffer in bytes
void nextBuffer(Buffer &outputBuffer, unsigned outBufNum)
really compute the next buffer given an offset base channel; this is called by nextBuffer, possibly multiple times
Scalable – mix-in class with scale and offset control inputs (may be constants or generators)...
virtual void setBuffers(SampleBuffer *sPtr)
Set the buffer pointer (rare; used in joiners)
unsigned mNumChannels
num channels in buffer (num mono buffers)
Cacheable – a mix-in for caching streams.
float fRandM(float minV, float maxV)
min - max (min/max)
float sample
(could be changed to int, or double)
unsigned mNumChannels
my "expected" number of output channels
void fillSine()
fill the shared wavetable with 1 cycle of a sine wave
#define UPDATE_PHASED_CONTROLS
Update the freq-related value in the loop.
~WavetableOscillator()
Destructor.
Struct for partial overtones.
int PartialDescriptionMode
unsigned mNumAlloc
num frames in each buffer
bool mUseCache
whether I'm to cache (vs. compute)
virtual ~Oscillator()
Destructor.
void addPartial(Partial *pt)
given a SHARC spectrum
void setWaveform(Buffer &wave, bool freeBufs=true)
plug in waveforms set the interpolation flag
#define DEFAULT_WAVETABLE_SIZE
Buffer mWavetable
the stored wave form
CompOrCacheOscillator(bool whether=false, float frequency=220, float phase=0.0)
#define LOAD_PHASED_CONTROLS
Load the freq-related values at the start of the callback; if the frequency is a dynamic UGen input...
#define LOAD_SCALABLE_CONTROLS
Load the scale/offset-related values at the start.
virtual void nextWaveInto(SampleBuffer dest, unsigned count, bool oneHz)=0
bool mDidIAllocateBuffers
who allocated my data buffers?
Buffer – the multi-channel sample buffer class (passed around between generators and IO guys)...
void allocateBuffers()
fcn to malloc storage buffers
Oscillator – Abstract oscillator class; inherits from UnitGenerator, Phased, and Scalable and provid...
Oscillator(float frequency=220.0, float ampl=1.0, float offset=0.0, float phase=0.0)
Constructor: parameters are optional.
CompOrCacheOscillator – Abstract oscillator class for those who can compute of cache their wavetable...
void nextBuffer(Buffer &outputBuffer, unsigned outBufNum)
really compute the next buffer given an offset base channel; this is called by nextBuffer, possibly multiple times
InterpolationPolicy mInterpolate
whether/how I should interpolate between samples
Sine(float frequency=220, float ampl=1.0, float offset=0.0, float phase=0.0)
virtual SampleBuffer * buffers()
virtual void dump()
pretty-print the receiver's input/controls map
bool mIsPopulated
does the buffer have data?
void dump()
print the receiver for debugging
Base class of CSL exceptions (written upper-case). Has a string message.
Sawtooth(float frequency=220, float ampl=1.0, float offset=0.0, float phase=0.0)
#define DECLARE_SCALABLE_CONTROLS
Macros for all the Scalable UnitGenerators (note that these don't end with ";")