CSL  6.0
Oscillator.cpp
Go to the documentation of this file.
1 //
2 // Oscillator.cpp -- implementation of the base oscillator class and most simple waveform generators
3 // See the copyright notice and acknowledgment of authors in the file COPYRIGHT
4 //
5 
6 #include "Oscillator.h"
7 //#include "SHARC.h"
8 #include <math.h>
9 
10 using namespace csl;
11 
12 // Generic Oscillator implementation
13 
14 // Constructor: Parameters are optional. Defaults to freq 220, amp 1 and phase & offset of 0
15 
16 Oscillator::Oscillator(float frequency, float ampl, float offset, float phase)
17  : UnitGenerator(),
18  Phased(frequency, phase),
19  Scalable(ampl, offset) { /* no-op */ }
20 
21 Oscillator::Oscillator(UnitGenerator & frequency, float ampl, float offset, float phase)
22  : UnitGenerator(),
23  Phased(frequency, phase),
24  Scalable(ampl, offset) { /* no-op */ }
25 
26 Oscillator::Oscillator(UnitGenerator & frequency, UnitGenerator & ampl, float offset, float phase)
27  : UnitGenerator(),
28  Phased(frequency, phase),
29  Scalable(ampl, offset) { /* no-op */ }
30 
32 
34  logMsg("an Oscillator");
36 }
37 
38 // Wavetable oscillator methods
39 // Constructors -- default creates a sine wave table
40 
41 //WavetableOscillator::WavetableOscillator() : Oscillator() {
42 // mWavetable.setSize(1, DEFAULT_WAVETABLE_SIZE);
43 // mInterpolate = kTruncate;
44 //// mWavetable.allocateBuffers();
45 //// fillSine();
46 //}
47 
48 WavetableOscillator::WavetableOscillator(float frequency, float ampl, float offset, float phase)
49  : Oscillator(frequency, ampl, offset, phase) {
51 // mWavetable.allocateBuffers();
53 // fillSine();
54 }
55 
56 //WavetableOscillator::WavetableOscillator(SampleBuffer samps, unsigned size) : Oscillator() {
57 // mWavetable.setSize(1, size);
58 // mInterpolate = kTruncate;
59 // setWaveform(samps, size);
60 //}
61 
63  mWavetable.setSize(1, wave.mNumFrames);
65  setWaveform(wave);
66 }
67 
68 ///< Destructor
69 
72 }
73 
74 // Plug in a waveform from a buffer or a simple sample array
75 
76 void WavetableOscillator::setWaveform(Buffer & wave, bool freBufs) {
77  if (freBufs)
81  if (mWavetable.buffers() == NULL)
83  for (unsigned i = 0; i < mWavetable.mNumChannels; i++)
84  mWavetable.setBuffer(i, wave.buffer(i));
92  mWavetable.mIsPopulated = true;
93 }
94 
95 //void WavetableOscillator::setWaveform(SampleBuffer samps, unsigned size) {
96 // mWavetable.freeBuffers();
97 // mWavetable.setSize(1, size);
98 // mWavetable.setBuffer(0, samps);
99 // mWavetable.mMonoBufferByteSize = size * sizeof(sample);
100 // mWavetable.mIsPopulated = true;
101 // mWavetable.mAreBuffersZero = false;
102 // mWavetable.mAreBuffersAllocated = true;
103 // mWavetable.mDidIAllocateBuffers = false;
104 //}
105 
106 //// Shared buffer with a sine of length CGestalt::maxBufferFrames()
107 
108 static Buffer * sSineTable = 0;
109 
110 // Create the default wavetable -- 1 cycle of a sine
111 
113  if ( ! sSineTable) { // create shared sine table lazily
114  sSineTable = new Buffer(1, DEFAULT_WTABLE_SIZE);
115  sSineTable->allocateBuffers(); // make space
116  SampleBuffer ptr = sSineTable->buffer(0);
117  float incr = CSL_TWOPI / DEFAULT_WTABLE_SIZE;
118  float accum = 0; // sine fill loop
119  for (unsigned i = 0; i < DEFAULT_WTABLE_SIZE; i++) {
120  *ptr++ = sinf(accum);
121  accum += incr;
122  }
123  }
125  mWavetable.setBuffer(0, sSineTable->buffer(0)); // point to the shared sine waveform
126  mWavetable.mAreBuffersAllocated = true; // fib a bit
128 }
129 
130 // Oscillate a buffer-full of the stored waveform
131 
132 void WavetableOscillator::nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw (CException) {
133  SampleBuffer buffer = outputBuffer.buffer(outBufNum); // get pointer to the selected output channel
134  if ( ! mWavetable.mAreBuffersAllocated) // lazy sine init
135  fillSine();
136  SampleBuffer waveform = mWavetable.buffer(0);
137  unsigned tableLength = mWavetable.mNumFrames;
138  float rateRecip = (float) tableLength / (float) mFrameRate;
139  float phase = mPhase; // get a local copy of the phase
140  unsigned numFrames = outputBuffer.mNumFrames; // the number of frames to fill
141  DECLARE_PHASED_CONTROLS; // declare the frequency buffer and value
142  DECLARE_SCALABLE_CONTROLS; // declare the scale/offset buffers and values
143 #ifdef CSL_DEBUG
144  logMsg("WavetableOscillator nextBuffer");
145 #endif
146  if ( ! waveform)
147  return;
148  LOAD_PHASED_CONTROLS; // load the freqC from the constant or dynamic value
149  LOAD_SCALABLE_CONTROLS; // load the scaleC and offsetC from the constant or dynamic value
150  unsigned int index;
151  sample samp1, samp2;
152  float fraction;
153  switch (mInterpolate) {
154  case kTruncate: // truncating wavetable lookup
155  for (unsigned i = 0; i < numFrames; i++) { // sample loop
156  while (phase >= tableLength) // wrap-around phase
157  phase -= tableLength;
158  while (phase < 0) // wrap-around phase
159  phase += tableLength;
160  index = (unsigned int) floorf(phase); // truncate phase to an integer
161  samp1 = waveform[index]; //// WAVE TABLE ACCESS ////
162  *buffer++ = (samp1 * scaleValue) + offsetValue; // get and scale the table item (truncating look-up)
163  phase += (freqValue * rateRecip);
164  UPDATE_PHASED_CONTROLS; // update the dynamic frequency
165  UPDATE_SCALABLE_CONTROLS; // update the dynamic scale/offset
166  }
167  break;
168  case kLinear:
169  for (unsigned i = 0; i < numFrames; i++) { // sample loop
170  index = (unsigned int) floorf(phase);
171  fraction = phase - (float) index;
172  samp1 = waveform[index]; // get sample
173  if (index < (tableLength - 1))
174  samp2 = waveform[index+1]; // and next sample
175  else
176  samp2 = waveform[0];
177  samp1 += (samp2 - samp1) * fraction; // and interpolate linear-wise
178  *buffer++ = (samp1 * scaleValue) + offsetValue; // get and scale the table item (truncating look-up)
179  phase += (freqValue * rateRecip);
180  while (phase >= tableLength) // wrap-around phase
181  phase -= tableLength;
182  UPDATE_PHASED_CONTROLS; // update the dynamic frequency
183  UPDATE_SCALABLE_CONTROLS; // update the dynamic scale/offset
184  }
185  break;
186  default:
187  throw LogicError("Unimplemented truncation policy");
188  }
189  mPhase = phase; // store the temp phase back to the member variable
190 }
191 
192 // CompOrCacheOscillator implementation
193 
194 // Arguments are optional. Defaults to: Cache = false, freq = 220, phase = 0.0.
195 
196 CompOrCacheOscillator::CompOrCacheOscillator(bool whether, float frequency, float phase)
197  : WavetableOscillator(frequency, 1.0f, 0.0f, phase),
198  Cacheable(whether) { }
199 
200 // Create the default wavetable cache
201 
203  mUseCache = true;
206 }
207 
208 // nextBuffer either calls the inherited wavetable method, or does the computation on-demand here
209 
210 void CompOrCacheOscillator::nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw (CException) {
211  if (mUseCache) // if we cache -- use the wavetable
212  return WavetableOscillator::nextBuffer(outputBuffer, outBufNum);
213  // otherwise do the synthesis on demand
214  outputBuffer.zeroBuffers();
215  SampleBuffer buffer = outputBuffer.buffer(outBufNum);
216  this->nextWaveInto(buffer, outputBuffer.mNumFrames, false);
217 }
218 
219 // Sine methods
220 
221 // Constructor with variable number of arguments. Defaults to f = 220, amp = 1, offset & phase = 0.
222 
223 Sine::Sine(float frequency, float ampl, float offset, float phase)
224  : Oscillator(frequency, ampl, offset, phase) { }
225 
226 // the computed sine's nextBuffer
227 
228 void Sine::nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw (CException) {
229  SampleBuffer buffer = outputBuffer.buffer(outBufNum); // get pointer to the selected output channel
230  float rateRecip = CSL_TWOPI / mFrameRate;
231  unsigned numFrames = outputBuffer.mNumFrames; // the number of frames to fill
232  float phase = mPhase;
233  DECLARE_PHASED_CONTROLS; // declare the frequency buffer and value
234  DECLARE_SCALABLE_CONTROLS; // declare the scale/offset buffers and values
235 #ifdef CSL_DEBUG
236  logMsg("Sine nextBuffer");
237 #endif
238  LOAD_PHASED_CONTROLS; // load the freqC from the constant or dynamic value
239  LOAD_SCALABLE_CONTROLS; // load the scaleC and offsetC from the constant or dynamic value
240 
241 // fprintf(stderr, " :%d: %5.3f", numFrames, scaleValue);
242  for (unsigned i = 0; i < numFrames; i++) { // sample loop
243  *buffer++ = (sinf(phase) * scaleValue) + offsetValue; // compute and store (scaled and offset) sine value
244  phase += (freqValue * rateRecip); // increment phase
245  UPDATE_PHASED_CONTROLS; // update the dynamic frequency
246  UPDATE_SCALABLE_CONTROLS; // update the dynamic scale/offset
247  }
248  while (phase >= CSL_TWOPI) // wraparound after 2pi radians
249  phase -= CSL_TWOPI;
250  mPhase = phase;
251 }
252 
253 // FSine methods
254 
255 // Constructor with variable number of arguments. Defaults to f = 220, amp = 1, offset & phase = 0.
256 
257 FSine::FSine(float frequency, float ampl, float offset, float phase)
258  : Oscillator(frequency, ampl, offset, phase) { }
259 
260 // the computed sine's nextBuffer
261 
262 void FSine::nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw (CException) {
263  SampleBuffer buffer = outputBuffer.buffer(outBufNum); // get pointer to the selected output channel
264  float rateRecip = CSL_TWOPI / mFrameRate;
265  unsigned numFrames = outputBuffer.mNumFrames; // the number of frames to fill
266  float phase = mPhase;
267  DECLARE_PHASED_CONTROLS; // declare the frequency buffer and value
268  DECLARE_SCALABLE_CONTROLS; // declare the scale/offset buffers and values
269 #ifdef CSL_DEBUG
270  logMsg("Sine nextBuffer");
271 #endif
272  LOAD_PHASED_CONTROLS; // load the freqC from the constant or dynamic value
273  LOAD_SCALABLE_CONTROLS; // load the scaleC and offsetC from the constant or dynamic value
274 
275 // fprintf(stderr, " :%d: %5.3f", numFrames, scaleValue);
276  for (unsigned i = 0; i < numFrames; i++) { // sample loop
277  *buffer++ = (sinf(phase) * scaleValue) + offsetValue; // compute and store (scaled and offset) sine value
278  phase += (freqValue * rateRecip); // increment phase
279  UPDATE_PHASED_CONTROLS; // update the dynamic frequency
280  UPDATE_SCALABLE_CONTROLS; // update the dynamic scale/offset
281  }
282  while (phase >= CSL_TWOPI) // wraparound after 2pi radians
283  phase -= CSL_TWOPI;
284  mPhase = phase;
285 }
286 
287 // Sawtooth methods
288 
289 // Constructor with variable number of arguments. Defaults to f = 220, amp = 1, offset & phase = 0
290 
291 Sawtooth::Sawtooth(float frequency, float ampl, float offset, float phase)
292  : Oscillator(frequency, ampl, offset, phase) { }
293 
294 void Sawtooth::nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw (CException) {
295  SampleBuffer buffer = outputBuffer.buffer(outBufNum); // get pointer to the selected output channel
296  float rateRecip = 1.0f / mFrameRate;
297  unsigned numFrames = outputBuffer.mNumFrames; // the number of frames to fill
298  float phase = mPhase;
299  DECLARE_PHASED_CONTROLS; // declare the frequency buffer and value
300  DECLARE_SCALABLE_CONTROLS; // declare the scale/offset buffers and values
301 #ifdef CSL_DEBUG
302  logMsg("Sine nextBuffer");
303 #endif
304  LOAD_PHASED_CONTROLS; // load the freqC from the constant or dynamic value
305  LOAD_SCALABLE_CONTROLS; // load the scaleC and offsetC from the constant or dynamic value
306 
307  for (unsigned i = 0; i < numFrames; i++) { // sample loop
308  *buffer++ = phase * scaleValue + offsetValue; // store the scaled and offset phase value
309  phase += (freqValue * rateRecip); // increment phase
310  if (phase >= 1.0f)
311  phase -= 2.0f;
312  UPDATE_PHASED_CONTROLS; // update the dynamic frequency
313  UPDATE_SCALABLE_CONTROLS; // update the dynamic scale/offset
314  }
315  mPhase = phase;
316 }
317 
318 // SquareSquare methods
319 
320 // Constructor with variable number of arguments. Defaults to f = 220, amp = 1, offset & phase = 0
321 
322 Square::Square(float frequency, float ampl, float offset, float phase)
323  : Oscillator(frequency, ampl, offset, phase) { }
324 
325 void Square::nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw (CException) {
326  SampleBuffer buffer = outputBuffer.buffer(outBufNum); // get pointer to the selected output channel
327  float rateRecip = 1.0f / mFrameRate;
328  unsigned numFrames = outputBuffer.mNumFrames; // the number of frames to fill
329  float phase = mPhase;
330  DECLARE_PHASED_CONTROLS; // declare the frequency buffer and value
331  DECLARE_SCALABLE_CONTROLS; // declare the scale/offset buffers and values
332 #ifdef CSL_DEBUG
333  logMsg("Sine nextBuffer");
334 #endif
335  LOAD_PHASED_CONTROLS; // load the freqC from the constant or dynamic value
336  LOAD_SCALABLE_CONTROLS; // load the scaleC and offsetC from the constant or dynamic value
337 
338  for (unsigned i = 0; i < numFrames; i++) { // sample loop
339  *buffer++ = ((phase > 0.0) ? 1.0f : -1.0f) * scaleValue + offsetValue; // store +- 1
340  phase += (freqValue * rateRecip); // increment phase
341  if (phase >= 1.0f)
342  phase -= 2.0f;
343  UPDATE_PHASED_CONTROLS; // update the dynamic frequency
344  UPDATE_SCALABLE_CONTROLS; // update the dynamic scale/offset
345  }
346  mPhase = phase;
347 }
348 
349 // Impulse methods
350 
352 
353 Impulse::Impulse(float delay) : Oscillator() { mCounter = (int) delay; }
354 
355 Impulse::Impulse(float frequency, float ampl)
356  : Oscillator(frequency, ampl) { mCounter = 0; }
357 
358 Impulse::Impulse(float frequency, float ampl, float offset)
359  : Oscillator(frequency, ampl, offset) { mCounter = 0; }
360 
361 Impulse::Impulse(float frequency, float ampl, float offset, float phase)
362  : Oscillator(frequency, ampl, offset, phase) { mCounter = 0; }
363 
364 // the computed Impulse's next_buffer
365 
366 void Impulse::nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw (CException) {
367  SampleBuffer buffer = outputBuffer.buffer(outBufNum); // get pointer to the selected output channel
368  unsigned numFrames = outputBuffer.mNumFrames; // the number of frames to fill
369  unsigned i, j;
370  int count = mCounter;
371  DECLARE_PHASED_CONTROLS; // declare the frequency buffer and value as above
372  DECLARE_SCALABLE_CONTROLS; // declare the scale/offset buffers and values as above
373 #ifdef CSL_DEBUG
374  logMsg("Sine nextBuffer");
375 #endif
376  LOAD_PHASED_CONTROLS; // load the freqC from the constant or dynamic value
377  LOAD_SCALABLE_CONTROLS; // load the scaleC and offsetC from the constant or dynamic value
378 
379  if (count < 0) { // Impulse is done. Output only zeros.
380  for (i = 0; i < numFrames; i++)
381  *buffer++ = 0;
382  } else if (count < numFrames) {
383  for (i = 0; i < count; i++)
384  *buffer++ = 0;
385  *buffer++ = scaleValue;
386  for (j = count+1; j < numFrames; j++)
387  *buffer++ = 0;
388  } else {
389  for (i = 0; i < numFrames; i++)
390  *buffer++ = 0;
391  }
392  mCounter = count - numFrames;
393 }
394 
395 // SumOfSines
396 
398 
399 SumOfSines::SumOfSines(float frequency)
400  : CompOrCacheOscillator(false, frequency) { }
401 
402 SumOfSines::SumOfSines(PartialDescriptionMode format, unsigned partialCount, ...)
403  : CompOrCacheOscillator(false) {
404  float num=0, amp=0, pha=0;
405  Partial * p;
406  va_list ap;
407  va_start(ap, partialCount);
408  for (unsigned i = 0; i < partialCount; i++) {
409  switch (format) {
410  case kFrequency: // if 1 term per partial, it's the amplitude
411  num = (float) (i + 1);
412  amp = va_arg(ap, double);
413  pha = 0.0;
414  break;
415  case kFreqAmp: // if 2 terms per partial, they're num, ampl
416  num = va_arg(ap, double);
417  amp = va_arg(ap, double);
418  pha = 0.0;
419  break;
420  case kFreqAmpPhase: // if 3 terms per partial, they're num, ampl
421  num = va_arg(ap, double);
422  amp = va_arg(ap, double);
423  pha = va_arg(ap, double);
424  break;
425  }
426  p = new Partial;
427  p->number = num;
428  p->amplitude = amp;
429  p->phase = pha;
430  mPartials.push_back(p);
431  }
432  va_end(ap);
433 }
434 
435 // given a SHARC spectrum
436 #include "SHARC.h"
437 
439  Partial * harm;
440  for (unsigned i = 0; i < spect._num_partials; i++) {
441  harm = spect._partials[i];
442 // fprintf(stderr, "\t%g @ %.5f @ %.5f\n", harm->number, harm->amplitude, harm->phase);
443  this->addPartial(harm->number, harm->amplitude, harm->phase);
444  }
445  this->createCache(); // make the cached wavetable
446 }
447 
448 // 1/f spectrum + noise
449 
450 SumOfSines::SumOfSines(unsigned numHarms, float noise) {
451  for (unsigned i = 0; i < numHarms; i++) {
452  float ampl = fRandV(noise) / (float) (i + 2);
453  float phas = fRandV(CSL_PI);
454 // fprintf(stderr, "\t%d @ %.5f @ %.5f\n", i, ampl, phas);
455  this->addPartial(i, ampl, phas);
456  }
457  this->createCache(); // make the cached wavetable
458 }
459 
460 SumOfSines::SumOfSines(float frequency, unsigned numHarms, float noise)
461  : CompOrCacheOscillator(false, frequency) {
462  for (unsigned i = 0; i < numHarms; i++) {
463  this->addPartial(i, fRandM(0.5f, 1.3f) / (float) i, fRandV(CSL_PI));
464  }
465  this->createCache(); // make the cached wavetable
466 }
467 
468 // Methods to add partials
469 
470 void SumOfSines::addPartial(float nu, float amp) {
471  Partial * p = new Partial;
472  p->number = nu;
473  p->amplitude = amp;
474  p->phase = 0.0;
475  mPartials.push_back(p);
476 }
477 
478 void SumOfSines::addPartial(float nu, float amp, float phase) {
479  Partial * p = new Partial;
480  p->number = nu;
481  p->amplitude = amp;
482  p->phase = phase;
483  mPartials.push_back(p);
484 }
485 
487  mPartials.push_back(pt);
488 }
489 
490 void SumOfSines::addPartials(unsigned num_p, Partial ** pt) {
491  Partial ** pt_ptr = pt;
492  for (unsigned i = 0; i < num_p; i++)
493  mPartials.push_back(*pt_ptr++);
494 }
495 
496 
497 void SumOfSines::addPartials(int argc, void ** argv) {
498  float ** v_ptr = (float ** ) argv;
499  int i = 0;
500  while (i < argc) {
501  Partial * part = new Partial;
502  part->number = * v_ptr[i++];
503  part->amplitude = * v_ptr[i++];
504  mPartials.push_back(part);
505  }
506 }
507 
509  mPartials.clear();
510 }
511 
512 // Do sum-of-sines additive synthesis into the given buffer
513 
514 void SumOfSines::nextWaveInto(SampleBuffer dest, unsigned count, bool oneHz) {
515  float incr, t_incr, phase, ampl;
516  SampleBuffer out_ptr;
517  unsigned numFrames = count; // the number of frames to fill
518  DECLARE_PHASED_CONTROLS; // declare the frequency buffer and value
519  DECLARE_SCALABLE_CONTROLS; // declare the scale/offset buffers and values
520 
521  if (oneHz) { // if we're creating a wavetable
522  incr = CSL_TWOPI / (float) count;
523  } else { // otherwise compute phase increment scale
524  incr = CSL_TWOPI / (float) mFrameRate;
525  LOAD_PHASED_CONTROLS; // load the freqC from the constant or dynamic value
526  LOAD_SCALABLE_CONTROLS; // load the scaleC and offsetC from the constant or dynamic value
527  }
528  for (unsigned i = 0; i < mPartials.size(); i++) { // partials loop
529  Partial * p = mPartials[i];
530  out_ptr = dest;
531  phase = p->phase;
532  t_incr = incr * p->number;
533  ampl = p->amplitude;
534 // fprintf(stderr, "\t\tp%d = i %g : a %g : p %g\n", i, t_incr, ampl, phase);
535  if (oneHz) {
536  for (unsigned j = 0; j < numFrames; j++) { // sample loop
537  *out_ptr++ += (sinf(phase) * ampl);
538  phase += t_incr;
539  }
540  } else {
541  for (unsigned j = 0; j < numFrames; j++) { // sample loop
542  *out_ptr++ += (sinf(phase) * ampl * scaleValue) + offsetValue;
543  phase += (t_incr * freqValue);
544  UPDATE_PHASED_CONTROLS; // update the dynamic frequency
545  UPDATE_SCALABLE_CONTROLS; // update the dynamic scale/offset
546 // if (j == 1) fprintf(stderr, "\t\t\t%g : %g : %g\n", freqValue, scaleValue, offsetValue);
547  }
548  }
549  if ( ! oneHz) {
550  freqPort->resetPtr(); // reset control pointers after each loop through a partial
551  scalePort->resetPtr();
552  offsetPort->resetPtr();
553  freqValue = freqPort->nextValue();
554  scaleValue = scalePort->nextValue();
555  offsetValue = offsetPort->nextValue();
556  }
557  while (phase > CSL_TWOPI) // wrap phase here
558  phase -= CSL_TWOPI;
559  p->phase = phase;
560  }
561 }
562 
564  unsigned siz = mPartials.size();
565  logMsg("a SumOfSines: %d partials", siz);
566  for (unsigned i = 0; i < siz; i++)
567  fprintf(stderr, "\tP: %g, %g, %g\n", mPartials[i]->number, mPartials[i]->amplitude, mPartials[i]->phase);
568  Scalable::dump();
569 }
sample * SampleBuffer
1-channel buffer data type, vector of (sample)
Definition: CSL_Types.h:194
bool mAreBuffersZero
have the buffers been zeroed out?
Definition: CSL_Core.h:123
#define UPDATE_SCALABLE_CONTROLS
Definition: CSL_Core.h:444
void logMsg(const char *format,...)
These are the public logging messages.
Definition: CGestalt.cpp:292
void nextWaveInto(SampleBuffer dest, unsigned count, bool oneHz)
Definition: Oscillator.cpp:514
#define kFrequency
Enum for SumOfSines description formats.
Definition: Oscillator.h:181
float fRandV(float val)
0 - v (val)
Definition: CGestalt.cpp:444
static Buffer * sSineTable
Definition: Oscillator.cpp:108
void nextBuffer(Buffer &outputBuffer, unsigned outBufNum)
really compute the next buffer given an offset base channel; this is called by nextBuffer, possibly multiple times
Definition: Oscillator.cpp:228
#define DECLARE_PHASED_CONTROLS
Macros for all the Phased UnitGenerators (note that these don't end with ";") These make some assumpt...
Definition: CSL_Core.h:520
unsigned mNumFrames
num frames used in each buffer
Definition: CSL_Core.h:113
#define kFreqAmpPhase
Definition: Oscillator.h:183
void nextBuffer(Buffer &outputBuffer, unsigned outBufNum)
really compute the next buffer given an offset base channel; this is called by nextBuffer, possibly multiple times
Definition: Oscillator.cpp:262
virtual void setBuffer(unsigned bufNum, SampleBuffer sPtr)
Definition: CSL_Core.h:158
FSine(float frequency=220, float ampl=1.0, float offset=0.0, float phase=0.0)
Definition: Oscillator.cpp:257
static unsigned mFrameRate
default sample rate (tested up to 96000)
Definition: CGestalt.cpp:32
bool mAreBuffersAllocated
are the buffers allocated?
Definition: CSL_Core.h:120
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
Definition: Accessor.h:17
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
Definition: Oscillator.cpp:210
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?)
Definition: Oscillator.h:66
WavetableOscillator(Buffer &wave)
Destructor.
Definition: Oscillator.cpp:62
unsigned mFrameRate
trigger ignored here
Definition: CSL_Core.h:288
Phased – a mix-in for objects with phase accumulators (local float) and frequency controls (an input...
Definition: CSL_Core.h:497
void nextBuffer(Buffer &outputBuffer, unsigned outBufNum)
really compute the next buffer given an offset base channel; this is called by nextBuffer, possibly multiple times
Definition: Oscillator.cpp:366
virtual SampleBuffer buffer(unsigned bufNum)
convenience accessors for sample buffers
Definition: CSL_Core.cpp:66
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
Definition: Oscillator.cpp:132
Partial ** _partials
Definition: SHARC.h:85
#define DEFAULT_WTABLE_SIZE
selected hardware interface at startup time
Definition: CSL_Types.h:108
std::vector< Partial * > mPartials
Definition: Oscillator.h:227
void dump()
print the receiver for debugging
Definition: Oscillator.cpp:33
void addPartials(unsigned num_p, Partial **pt)
Definition: Oscillator.cpp:490
void freeBuffers()
fcn to free them
Definition: CSL_Core.cpp:141
Impossible operation.
Square(float frequency=220, float ampl=1.0, float offset=0.0, float phase=0.0)
Definition: Oscillator.cpp:322
void setSize(unsigned numChannels, unsigned numFrames)
Definition: CSL_Core.cpp:75
unsigned mMonoBufferByteSize
size of each buffer in bytes
Definition: CSL_Core.h:115
void nextBuffer(Buffer &outputBuffer, unsigned outBufNum)
really compute the next buffer given an offset base channel; this is called by nextBuffer, possibly multiple times
Definition: Oscillator.cpp:294
Scalable – mix-in class with scale and offset control inputs (may be constants or generators)...
Definition: CSL_Core.h:403
#define CSL_PI
Definition: CSL_Types.h:334
virtual void setBuffers(SampleBuffer *sPtr)
Set the buffer pointer (rare; used in joiners)
Definition: CSL_Core.h:157
unsigned mNumChannels
num channels in buffer (num mono buffers)
Definition: CSL_Core.h:112
Cacheable – a mix-in for caching streams.
Definition: CSL_Core.h:595
void clearPartials()
Definition: Oscillator.cpp:508
float fRandM(float minV, float maxV)
min - max (min/max)
Definition: CGestalt.cpp:426
float sample
(could be changed to int, or double)
Definition: CSL_Types.h:191
unsigned mNumChannels
my "expected" number of output channels
Definition: CSL_Core.h:292
void fillSine()
fill the shared wavetable with 1 cycle of a sine wave
Definition: Oscillator.cpp:112
#define UPDATE_PHASED_CONTROLS
Update the freq-related value in the loop.
Definition: CSL_Core.h:534
~WavetableOscillator()
Destructor.
Definition: Oscillator.cpp:70
Struct for partial overtones.
Definition: Oscillator.h:164
int PartialDescriptionMode
Definition: Oscillator.h:184
unsigned mNumAlloc
num frames in each buffer
Definition: CSL_Core.h:114
bool mUseCache
whether I'm to cache (vs. compute)
Definition: CSL_Core.h:598
virtual ~Oscillator()
Destructor.
Definition: Oscillator.cpp:31
void addPartial(Partial *pt)
given a SHARC spectrum
Definition: Oscillator.cpp:486
unsigned _num_partials
Definition: SHARC.h:84
void setWaveform(Buffer &wave, bool freeBufs=true)
plug in waveforms set the interpolation flag
Definition: Oscillator.cpp:76
#define DEFAULT_WAVETABLE_SIZE
Definition: Oscillator.h:22
Buffer mWavetable
the stored wave form
Definition: Oscillator.h:84
#define kFreqAmp
Definition: Oscillator.h:182
CompOrCacheOscillator(bool whether=false, float frequency=220, float phase=0.0)
Definition: Oscillator.cpp:196
float amplitude
Definition: Oscillator.h:166
#define CSL_TWOPI
Definition: CSL_Types.h:336
#define LOAD_PHASED_CONTROLS
Load the freq-related values at the start of the callback; if the frequency is a dynamic UGen input...
Definition: CSL_Core.h:528
#define LOAD_SCALABLE_CONTROLS
Load the scale/offset-related values at the start.
Definition: CSL_Core.h:436
virtual void nextWaveInto(SampleBuffer dest, unsigned count, bool oneHz)=0
bool mDidIAllocateBuffers
who allocated my data buffers?
Definition: CSL_Core.h:121
Buffer – the multi-channel sample buffer class (passed around between generators and IO guys)...
Definition: CSL_Core.h:106
void allocateBuffers()
fcn to malloc storage buffers
Definition: CSL_Core.cpp:122
forward declaration
Definition: CSL_Core.h:241
Oscillator – Abstract oscillator class; inherits from UnitGenerator, Phased, and Scalable and provid...
Definition: Oscillator.h:31
Oscillator(float frequency=220.0, float ampl=1.0, float offset=0.0, float phase=0.0)
Constructor: parameters are optional.
Definition: Oscillator.cpp:16
CompOrCacheOscillator – Abstract oscillator class for those who can compute of cache their wavetable...
Definition: Oscillator.h:94
void nextBuffer(Buffer &outputBuffer, unsigned outBufNum)
really compute the next buffer given an offset base channel; this is called by nextBuffer, possibly multiple times
Definition: Oscillator.cpp:325
InterpolationPolicy mInterpolate
whether/how I should interpolate between samples
Definition: Oscillator.h:83
Sine(float frequency=220, float ampl=1.0, float offset=0.0, float phase=0.0)
Definition: Oscillator.cpp:223
virtual SampleBuffer * buffers()
Definition: CSL_Core.h:155
float number
Definition: Oscillator.h:165
virtual void dump()
pretty-print the receiver's input/controls map
Definition: CSL_Core.cpp:926
bool mIsPopulated
does the buffer have data?
Definition: CSL_Core.h:122
SHARC spectrum class.
Definition: SHARC.h:76
void dump()
print the receiver for debugging
Definition: Oscillator.cpp:563
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)
Definition: Oscillator.cpp:291
#define DECLARE_SCALABLE_CONTROLS
Macros for all the Scalable UnitGenerators (note that these don't end with ";")
Definition: CSL_Core.h:429