Nsound
0.9.4
|
A class the provides draw utilities and a wavetable oscillator. More...
#include <Nsound/Generator.h>
Public Member Functions | |
Generator (const float64 &sample_rate) | |
Creates a generator with the specified sample rate. More... | |
Generator (const float64 &sample_rate, const Buffer &waveform) | |
Creates a generator with the specified sample rate and waveform. More... | |
Generator (const std::string &wave_filename) | |
Creates a generator using the waveform stored in wave_filename. More... | |
Generator (const Nsound::Generator &gen) | |
Copy constructor. More... | |
virtual | ~Generator () |
Deletes the baseclass part of the object. More... | |
void | setRealtime (bool flag) |
Sets realtime mode, disables automatic reset() if set. More... | |
void | addSlaveSync (Generator &slave) |
Adds a generator as a slave to this instance for syncing. More... | |
void | buzzInit (const uint32 &max_harmonics) |
Initaializes Buzz settings for real-time calls. More... | |
float64 | buzz (const float64 &frequency, const float64 &n_harmonics, const float64 &delay) |
Returns sample from a set of harmonics. Based on the Csound buzz opcode. More... | |
Buffer | buzz (const float64 &duration, const float64 &frequency, const float64 &n_harmonics, const float64 &delay) |
Returns a set of harmonics. Based on the Csound buzz opcode. More... | |
Buffer | buzz (const float64 &duration, const Buffer &frequency, const Buffer &n_harmonics, const Buffer &delay) |
Returns a set of harmonics. Based on the Csound buzz opcode. More... | |
void | setChorus (const uint32 n_voices, const float64 &sigma=0.02) |
Chorus or Unison. More... | |
Buffer | drawDecay (const float64 &duration, const float64 &alpha=2.0 *M_PI) const |
This method draws an exponential curve that decays from 1.0 to 0.0 over the duration. More... | |
Buffer | drawGaussian (const float64 &duration, const float64 &mu, const float64 &sigma, const boolean &normalize=true) const |
This method draws a Gaussian curve over duration seconds. More... | |
Buffer | drawFatGaussian (const float64 &duration, const float64 &pass_band_percent=0.01) const |
This method draws a standard Gaussian curve over duration seconds, with a specified pass band. More... | |
Buffer | drawLine (const float64 &duration, const float64 &litude_start, const float64 &litude_finish) const |
This method draws a linear line beteween 2 points. More... | |
Buffer | drawParabola (const float64 &duration, const float64 &y1, const float64 &x2, const float64 &y2, const float64 &y3) const |
This method draws a parabola between three points, intersecting the middle point. More... | |
Buffer | drawSine (const float64 &duration, const float64 &frequency) |
This method draws a static sine wave. More... | |
Buffer | drawSine (const float64 &duration, const Buffer &frequency) |
This method draws a dynamic sine wave. More... | |
Buffer | drawSine2 (const float64 &duration, const float64 &frequency, const float64 &phase) |
This method draws a static sine wave. More... | |
Buffer | drawSine2 (const float64 &duration, const Buffer &frequency, const Buffer &phase) |
This method draws a dynamic sine wave. More... | |
Buffer | drawSine2 (const float64 &duration, const Buffer &frequency, const float64 &phase=0.0) |
This method draws a dynamic sine wave. More... | |
Buffer | drawSine2 (const float64 &duration, const float64 &frequency, const Buffer &phase) |
This method draws a dynamic sine wave. More... | |
float64 | drawSine (const float64 &frequency) |
This method draws one sample of a sine wave in real-time. More... | |
float64 | drawSine2 (const float64 &frequency, const float64 &phase) |
This method draws one sample of a sine wave in real-time. More... | |
Buffer | drawWindow (const float64 &duration, WindowType type) const |
Draws a window of the specified type. More... | |
Buffer | drawWindowBartlett (const float64 &duration) const |
Draws a Bartlett window. More... | |
Buffer | drawWindowBlackman (const float64 &duration) const |
Draws a Blackman window. More... | |
Buffer | drawWindowBlackmanHarris (const float64 &duration) const |
Draws a Blackman-Harris window. More... | |
Buffer | drawWindowHamming (const float64 &duration) const |
Draws a Hamming window. More... | |
Buffer | drawWindowHanning (const float64 &duration) const |
Draws a Hanning window. More... | |
Buffer | drawWindowKaiser (const float64 &duration, const float64 &beta=5.0) const |
Draws a Kaiser window. More... | |
Buffer | drawWindowNuttall (const float64 &duration) const |
Draws a Nuttall window. More... | |
Buffer | drawWindowParzen (const float64 &duration) const |
Draws a Parzen window. More... | |
Buffer | drawWindowRectangular (const float64 &duration) const |
Draws a rectangular window. More... | |
virtual float64 | generate (const float64 &frequency) |
This is a real-time method for the wavetable oscillator. More... | |
virtual float64 | generate2 (const float64 &frequency, const float64 &phase) |
This is a real-time method for the wavetable oscillator. More... | |
virtual Buffer | generate (const float64 &duration, const float64 &frequency) |
This method oscillates the waveform stored in this generator. More... | |
virtual Buffer | generate2 (const float64 &duration, const float64 &frequency, const float64 &phase) |
This method oscillates the waveform stored in this generator. More... | |
virtual Buffer | generate (const float64 &duration, const Buffer &frequencies) |
This method oscillates the waveform stored in this generator. More... | |
virtual Buffer | generate2 (const float64 &duration, const float64 &frequencies, const Buffer &phase) |
This method oscillates the waveform stored in this generator. More... | |
virtual Buffer | generate2 (const float64 &duration, const Buffer &frequencies, const float64 &phase) |
This method oscillates the waveform stored in this generator. More... | |
virtual Buffer | generate2 (const float64 &duration, const Buffer &frequencies, const Buffer &phase) |
This method oscillates the waveform stored in this generator. More... | |
Nsound::Generator & | operator= (const Nsound::Generator &rhs) |
Assignment operator. More... | |
void | removeSlaveSync (Generator &slave) |
Removes the generator from the sync list. More... | |
virtual void | reset () |
Resets the position pointer back to the begging of the waveform. More... | |
RandomNumberGenerator & | getRandomNumberGenerator () |
void | setSeed (const uint32 seed) |
Sets the seed for the Generator's random number generator (rng). More... | |
Buffer | silence (const float64 &duration) const |
This method generates silence. More... | |
float64 | tell () const |
Returns the current position pointer, values are between 0.0 to 1.0. More... | |
Buffer | whiteNoise (const float64 &duration) const |
This method generates noise from a uniform distribution. More... | |
Buffer | gaussianNoise (const float64 &duration, const float64 &mu, const float64 &sigma) const |
This method generates noise from a Gaussian distribution. More... | |
Buffer | tanh (const float64 &duration) const |
This method draws the tanh function accross duration samples. More... | |
Protected Member Functions | |
Generator () | |
DOXME. More... | |
virtual void | ctor (const float64 &sample_rate) |
DOXME. More... | |
virtual void | ctor (const float64 &sample_rate, const Buffer &wavetable) |
DOXME. More... | |
Protected Attributes | |
bool | is_realtime_ |
float64 | last_frequency_ |
float64 | position_ |
Used for phase offset adjustment. More... | |
float64 | sync_pos_ |
The number of samples into the wavefrom. More... | |
float64 | sample_rate_ |
Used to determine when to create a sync sample. More... | |
float64 | sample_time_ |
The number of samples per second to generate. More... | |
float64 | t_ |
The time step between samples in seconds. More... | |
Buffer * | waveform_ |
The current time (for real time draw functions.) More... | |
RandomNumberGenerator * | rng_ |
The waveform to ossicialate. More... | |
uint32 | buzz_max_harmonics_ |
The random number generator. More... | |
std::vector< float64 > | buzz_position_ |
boolean | chorus_is_on_ |
uint32 | chorus_n_voices_ |
std::vector< float64 > | chorus_position_ |
std::vector< float64 > | chorus_factor_ |
boolean | sync_is_master_ |
boolean | sync_is_slave_ |
Indicates if this generator is the master. More... | |
uint32 | sync_count_ |
Indicates if this generator is a slave. More... | |
std::vector< uint32 > | sync_vector_ |
Indicates the number of samples since reset. More... | |
std::set< Generator * > | sync_slaves_ |
Stores sample counts when synced. More... | |
A class the provides draw utilities and a wavetable oscillator.
Definition at line 50 of file Generator.h.
Generator::Generator | ( | const float64 & | sample_rate | ) |
Creates a generator with the specified sample rate.
Definition at line 78 of file Generator.cc.
References ctor().
Creates a generator with the specified sample rate and waveform.
Definition at line 135 of file Generator.cc.
References ctor().
Generator::Generator | ( | const std::string & | wave_filename | ) |
Creates a generator using the waveform stored in wave_filename.
The sample rate of the generator will be the length of the waveform.
Definition at line 106 of file Generator.cc.
References ctor(), and Nsound::Buffer::getLength().
Generator::Generator | ( | const Nsound::Generator & | gen | ) |
Copy constructor.
Definition at line 163 of file Generator.cc.
|
virtual |
Deletes the baseclass part of the object.
Definition at line 192 of file Generator.cc.
References rng_, and waveform_.
|
protected |
DOXME.
Definition at line 52 of file Generator.cc.
|
inline |
Sets realtime mode, disables automatic reset() if set.
Definition at line 72 of file Generator.h.
References is_realtime_.
void Generator::addSlaveSync | ( | Generator & | slave | ) |
Adds a generator as a slave to this instance for syncing.
Definition at line 237 of file Generator.cc.
References reset(), sync_is_master_, sync_is_slave_, and sync_slaves_.
Referenced by main().
void Generator::buzzInit | ( | const uint32 & | max_harmonics | ) |
Initaializes Buzz settings for real-time calls.
Definition at line 252 of file Generator.cc.
References buzz_max_harmonics_, and reset().
Referenced by buzz().
float64 Generator::buzz | ( | const float64 & | frequency, |
const float64 & | n_harmonics, | ||
const float64 & | delay | ||
) |
Returns sample from a set of harmonics. Based on the Csound buzz opcode.
Chorus can not be used with this function.
Definition at line 260 of file Generator.cc.
References last_frequency_, position_, and sample_rate_.
Referenced by buzz(), FFTransform_UnitTest(), and Generator_UnitTest().
Buffer Generator::buzz | ( | const float64 & | duration, |
const float64 & | frequency, | ||
const float64 & | n_harmonics, | ||
const float64 & | delay | ||
) |
Returns a set of harmonics. Based on the Csound buzz opcode.
Definition at line 313 of file Generator.cc.
References buzz(), buzzInit(), and sample_rate_.
Buffer Generator::buzz | ( | const float64 & | duration, |
const Buffer & | frequency, | ||
const Buffer & | n_harmonics, | ||
const Buffer & | delay | ||
) |
Returns a set of harmonics. Based on the Csound buzz opcode.
Definition at line 335 of file Generator.cc.
References buzz(), buzzInit(), Nsound::Buffer::cbegin(), Nsound::Buffer::getMax(), and sample_rate_.
Chorus or Unison.
When chorus is not enabled, samples are generated using one frequency indexing into the wave table. However, when chorus is turned on, the output sample will be the average of N frequencies indexing into the wavetable. A set of scalar is randomally selected, each frequncy in the set is calculated by
where is a random scalar selected inside .
Definition at line 361 of file Generator.cc.
References chorus_factor_, chorus_is_on_, chorus_n_voices_, chorus_position_, Nsound::RandomNumberGenerator::get(), reset(), and rng_.
Referenced by Generator_UnitTest(), and Sine_UnitTest().
This method draws an exponential curve that decays from 1.0 to 0.0 over the duration.
where the default value for is and is the sample time.
Definition at line 388 of file Generator.cc.
References drawLine(), and Nsound::Buffer::exp().
Referenced by Nsound::Granulator::Granulator(), main(), Nsound::DrumBD01::play(), Nsound::DrumKickBass::play(), and Nsound::Hat::play().
Buffer Generator::drawGaussian | ( | const float64 & | duration, |
const float64 & | mu, | ||
const float64 & | sigma, | ||
const boolean & | normalize = true |
||
) | const |
This method draws a Gaussian curve over duration seconds.
This method draws a Gaussian curve over duration seconds.
duration | the number of seconds to draw |
mu | the location of the peak in seconds |
sigma | the width of the Gaussian in seconds |
normalize | a flag to normalize the Gaussian so the peak is 1.0 |
The generatl equation for a discrete Gaussian is given by
where is the sample time.
Definition at line 403 of file Generator.cc.
References drawLine(), Nsound::Buffer::exp(), M_2PI, and Nsound::Buffer::normalize().
Referenced by drawFatGaussian(), drawWindow(), Nsound::Granulator::Granulator(), and main().
Buffer Generator::drawFatGaussian | ( | const float64 & | duration, |
const float64 & | pass_band_percent = 0.01 |
||
) | const |
This method draws a standard Gaussian curve over duration seconds, with a specified pass band.
duration | the number of seconds to draw |
pass_band_percent | the width of the pass band in percent of duraiton |
sigma | the standard deviation of the gaussian curve |
The curve is always normaized so the peak is 1.0.
Definition at line 434 of file Generator.cc.
References drawGaussian(), drawLine(), and M_ASSERT_VALUE.
Referenced by drawWindow(), Nsound::Granulator::Granulator(), main(), and softTones().
Buffer Generator::drawLine | ( | const float64 & | duration, |
const float64 & | amplitude_start, | ||
const float64 & | amplitude_finish | ||
) | const |
This method draws a linear line beteween 2 points.
duration | the number of seconds to draw |
amplitude_start | the starting amplitude value |
amplitude_finish | the finishing amplitude value |
The two points are located at (x1,y1) = (0.0, amplitude_1) and (x2,y2) = (duration, amplitude_2).
Definition at line 464 of file Generator.cc.
References M_ASSERT_VALUE, and sample_rate_.
Referenced by Buffer_UnitTest(), DelayLine_UnitTest(), drawDecay(), drawFatGaussian(), drawGaussian(), drawParabola(), drawSquare(), drawTriangle(), drawWindowBartlett(), drawWindowBlackman(), drawWindowBlackmanHarris(), drawWindowHamming(), drawWindowHanning(), drawWindowKaiser(), drawWindowNuttall(), drawWindowParzen(), drawWindowRectangular(), drum(), FilterCombLowPassFeedback_UnitTest(), FilterParametricEqualizer_UnitTest(), Nsound::Pluck::generate(), Generator_UnitTest(), Nsound::FFTChunk::getFrequencyAxis(), main(), Nsound::FilterLeastSquaresFIR::makeKernel(), my_main(), Nsound::AudioStream::ones(), Nsound::Buffer::ones(), Nsound::Stretcher::overlapAdd(), Nsound::GuitarBass::play(), Nsound::Clarinet::play(), Nsound::DrumBD01::play(), Nsound::FluteSlide::play(), Nsound::DrumKickBass::play(), Nsound::OrganPipe::play(), Nsound::Hat::play(), Nsound::AudioStream::plot(), silence(), Sine_UnitTest(), Nsound::Square::Square(), Nsound::Mesh2D::strike(), testAutioStream(), Nsound::Triangle::Triangle(), Triangle_UnitTest(), Nsound::AudioStream::zeros(), and Nsound::Buffer::zeros().
Buffer Generator::drawParabola | ( | const float64 & | duration, |
const float64 & | y1, | ||
const float64 & | x2, | ||
const float64 & | y2, | ||
const float64 & | y3 | ||
) | const |
This method draws a parabola between three points, intersecting the middle point.
duration | the number of seconds to draw |
y1 | the y1 amplitude |
x2 | the x2 time |
y2 | the y2 amplitude |
y3 | the y3 amplitude |
The general equation for a discrete parabola is:
where is the sample time. The three points are located at (x1,y1), (x2,y2), (x3,y3) with x1 = 0.0 and x3 = duration.
Definition at line 490 of file Generator.cc.
References drawLine(), and M_ASSERT_VALUE.
Referenced by drum().
This method draws a static sine wave.
duration | the number of seconds to draw |
frequency | the frequency in Hz |
This is a special case of drawSine2(const float64 & duration, const float64 & frequency, const float64 & phase) with phase set to 0.0.
Definition at line 544 of file Generator.cc.
References drawSine2(), M_ASSERT_VALUE, sample_rate_, and t_.
Referenced by Generator_UnitTest(), Nsound::Sawtooth::Sawtooth(), Nsound::Sine::Sine(), and Nsound::Square::Square().
This method draws a dynamic sine wave.
duration | the number of seconds to draw |
frequency | the frequency in Hz |
This is a special case of drawSine2(const float64 & duration, const Buffer & frequency, const Buffer & phase) with the phase set to 0.0.
Definition at line 566 of file Generator.cc.
References Nsound::Buffer::cbegin(), drawSine2(), M_ASSERT_VALUE, sample_rate_, and t_.
Buffer Generator::drawSine2 | ( | const float64 & | duration, |
const float64 & | frequency, | ||
const float64 & | phase | ||
) |
This method draws a static sine wave.
duration | the number of seconds to draw |
frequency | the frequency in Hz |
phase | the natural phase (0.0 to 1.0) |
The general discrete sine wave is given by
where is the sample time. This function will produce a cosine wave if is 0.5.
Definition at line 591 of file Generator.cc.
References M_ASSERT_VALUE, sample_rate_, and t_.
Referenced by Nsound::Cosine::Cosine(), drawSine(), drawSine2(), and Generator_UnitTest().
Buffer Generator::drawSine2 | ( | const float64 & | duration, |
const Buffer & | frequency, | ||
const Buffer & | phase | ||
) |
This method draws a dynamic sine wave.
duration | the number of seconds to draw |
frequency | the frequency in Hz |
phase | the natural phase (0.0 to 1.0) |
The general dynamic discrete sine wave is given by
where is given by
and when and is the sample time.
This function will produce a cosine wave if is 0.5.
Definition at line 614 of file Generator.cc.
References Nsound::Buffer::cbegin(), drawSine2(), M_ASSERT_VALUE, sample_rate_, and t_.
Buffer Generator::drawSine2 | ( | const float64 & | duration, |
const Buffer & | frequency, | ||
const float64 & | phase = 0.0 |
||
) |
This method draws a dynamic sine wave.
duration | the number of seconds to draw |
frequency | the frequency in Hz |
phase | the natural phase (0.0 to 1.0) |
This is a special case of drawSine2(const float64 & duration, const Buffer & frequency, const Buffer & phase) with the phase set to a constant value.
Definition at line 642 of file Generator.cc.
References drawSine2().
Buffer Generator::drawSine2 | ( | const float64 & | duration, |
const float64 & | frequency, | ||
const Buffer & | phase | ||
) |
This method draws a dynamic sine wave.
duration | the number of seconds to draw |
frequency | the frequency in Hz |
phase | the natural phase (0.0 to 1.0) |
This is a special case of drawSine2(const float64 & duration, const Buffer & frequency, const Buffer & phase) with the frequency set to a constant value.
Definition at line 655 of file Generator.cc.
References drawSine2().
This method draws one sample of a sine wave in real-time.
frequency | the frequency in Hz |
This is a special case of drawSine2(const float64 & frequency, const float64 & phase) with the phase = 0.0.
Definition at line 694 of file Generator.cc.
References drawSine2().
This method draws one sample of a sine wave in real-time.
frequency | the frequency in Hz |
phase | the natural phase (0.0 to 1.0) |
Definition at line 668 of file Generator.cc.
References chorus_factor_, chorus_is_on_, chorus_n_voices_, chorus_position_, M_2PI, M_PI, sample_time_, and t_.
Buffer Generator::drawWindow | ( | const float64 & | duration, |
WindowType | type | ||
) | const |
Draws a window of the specified type.
Definition at line 702 of file Generator.cc.
References Nsound::BARTLETT, Nsound::BLACKMAN, Nsound::BLACKMAN_HARRIS, drawFatGaussian(), drawGaussian(), drawWindowBartlett(), drawWindowBlackman(), drawWindowBlackmanHarris(), drawWindowHamming(), drawWindowHanning(), drawWindowKaiser(), drawWindowNuttall(), drawWindowParzen(), drawWindowRectangular(), Nsound::GAUSSIAN, Nsound::GAUSSIAN_05, Nsound::GAUSSIAN_10, Nsound::GAUSSIAN_15, Nsound::GAUSSIAN_20, Nsound::GAUSSIAN_25, Nsound::GAUSSIAN_30, Nsound::GAUSSIAN_33, Nsound::GAUSSIAN_35, Nsound::GAUSSIAN_40, Nsound::GAUSSIAN_45, Nsound::GAUSSIAN_50, Nsound::GAUSSIAN_55, Nsound::GAUSSIAN_60, Nsound::GAUSSIAN_65, Nsound::GAUSSIAN_66, Nsound::GAUSSIAN_70, Nsound::GAUSSIAN_75, Nsound::GAUSSIAN_80, Nsound::GAUSSIAN_85, Nsound::GAUSSIAN_90, Nsound::GAUSSIAN_95, Nsound::GAUSSIAN_99, Nsound::HAMMING, Nsound::HANNING, Nsound::KAISER, M_THROW, Nsound::NUTTALL, Nsound::PARZEN, and Nsound::RECTANGULAR.
Referenced by Nsound::FFTransform::fft(), Nsound::FilterLeastSquaresFIR::setWindow(), and Nsound::Spectrogram::Spectrogram().
Draws a Bartlett window.
Definition at line 765 of file Generator.cc.
References drawLine(), and sample_rate_.
Referenced by drawWindow().
Draws a Blackman window.
The general discrete cosine window is given by
where is the sample time. The Blackman window is a special case of the cosesine window with = 0.42, = 0.50, = 0.08, = 0.00.
Definition at line 785 of file Generator.cc.
References cosinewindow(), and drawLine().
Referenced by drawWindow().
Draws a Blackman-Harris window.
The general discrete cosine window is given by
where is the sample time. The Blackman-Harris window is a special case of the cosesine window with = 0.35875, = 0.48829, = 0.14128, = 0.01168.
Definition at line 796 of file Generator.cc.
References cosinewindow(), and drawLine().
Referenced by drawWindow().
Draws a Hamming window.
The general discrete cosine window is given by
where is the sample time. The Hamming window is a special case of the cosesine window with = 0.54, = 0.46, = 0.00, = 0.00.
Definition at line 808 of file Generator.cc.
References cosinewindow(), and drawLine().
Referenced by drawWindow().
Draws a Hanning window.
The general discrete cosine window is given by
where is the sample time. The Hanning window is a special case of the cosesine window with = 0.50, = 0.50, = 0.00, = 0.00.
Definition at line 819 of file Generator.cc.
References cosinewindow(), and drawLine().
Referenced by drawWindow(), my_main(), and Nsound::Stretcher::Stretcher().
Draws a Kaiser window.
Definition at line 879 of file Generator.cc.
References bessel_i0(), drawLine(), and Nsound::Buffer::getLength().
Referenced by drawWindow(), Nsound::FilterLeastSquaresFIR::FilterLeastSquaresFIR(), and Nsound::FilterLeastSquaresFIR::setKernel().
Draws a Nuttall window.
The general discrete cosine window is given by
where is the sample time. The Nuttall window is a special case of the cosesine window with = 0.3635819, = 0.4891775, = 0.1365995, = 0.0106411.
Definition at line 921 of file Generator.cc.
References cosinewindow(), and drawLine().
Referenced by drawWindow().
Draws a Parzen window.
Definition at line 932 of file Generator.cc.
References drawLine(), and sample_rate_.
Referenced by drawWindow().
Draws a rectangular window.
Definition at line 965 of file Generator.cc.
References drawLine().
Referenced by drawWindow().
This is a real-time method for the wavetable oscillator.
frequency | the frequency in Hz |
This is a special case of generate2(const float64 & frequency, const float64 & phase) with phase = 0.0.
Reimplemented in Nsound::Pulse, Nsound::GeneratorDecay, and Nsound::Pluck.
Definition at line 972 of file Generator.cc.
References generate2().
Referenced by Buffer_UnitTest(), BufferResample_UnitTest(), DelayLine_UnitTest(), drum(), Nsound::FilterFlanger::filter(), FilterDelay_UnitTest(), Nsound::FilterFlanger::FilterFlanger(), Nsound::FilterPhaser::FilterPhaser(), Nsound::Granulator::generate(), generate(), Generator_UnitTest(), main(), Nsound::GuitarBass::play(), Nsound::Clarinet::play(), Nsound::DrumBD01::play(), Nsound::DrumKickBass::play(), Nsound::OrganPipe::play(), Nsound::Hat::play(), Sine_UnitTest(), softTones(), testAutioStream(), Triangle_UnitTest(), and Wavefile_UnitTest().
This is a real-time method for the wavetable oscillator.
frequency | the frequency in Hz |
phase | the natural phase (0.0 to 1.0) |
The general wavetable oscillator equation is given by
where the index into the table, is given by the recursive function
where is the modulus operator, is the wavetable length, when , . In Nsound, the wavetable size, , is equal to the sample rate.
Reimplemented in Nsound::Pulse, Nsound::GeneratorDecay, and Nsound::Pluck.
Definition at line 979 of file Generator.cc.
References chorus_factor_, chorus_is_on_, chorus_n_voices_, chorus_position_, M_CHECK_PTR, position_, sample_rate_, sync_count_, sync_is_master_, sync_is_slave_, sync_pos_, sync_slaves_, sync_vector_, and waveform_.
Referenced by generate(), Nsound::GeneratorDecay::generate2(), Nsound::Pulse::generate2(), generate2(), and Sine_UnitTest().
This method oscillates the waveform stored in this generator.
duration | the number of seconds to oscillate the waveform |
frequency | the frequency in Hz |
Reimplemented in Nsound::Pluck.
Definition at line 1065 of file Generator.cc.
References generate(), is_realtime_, M_ASSERT_VALUE, reset(), and sample_rate_.
|
virtual |
This method oscillates the waveform stored in this generator.
duration | the number of seconds to oscillate the waveform |
frequency | the frequency in Hz |
phase | the natural phase (0.0 to 1.0) |
Reimplemented in Nsound::Pulse, Nsound::GeneratorDecay, and Nsound::Pluck.
Definition at line 1087 of file Generator.cc.
References generate2(), is_realtime_, M_ASSERT_VALUE, reset(), and sample_rate_.
This method oscillates the waveform stored in this generator.
duration | the number of seconds to oscillate the waveform |
frequency | the frequency in Hz |
This is a special case of generate2(const float64 & duration, const Buffer & frequencies, const Buffer & phase) with phase = 0.0.
Reimplemented in Nsound::Pluck.
Definition at line 1110 of file Generator.cc.
References Nsound::Buffer::cbegin(), generate(), is_realtime_, M_ASSERT_VALUE, reset(), and sample_rate_.
|
virtual |
This method oscillates the waveform stored in this generator.
duration | the number of seconds to oscillate the waveform |
frequency | the frequency in Hz |
phase | the natural phase (0.0 to 1.0) |
This is a special case of generate2(const float64 & duration, const Buffer & frequencies, const Buffer & phase) with constant frequency.
Reimplemented in Nsound::Pulse, Nsound::GeneratorDecay, and Nsound::Pluck.
Definition at line 1134 of file Generator.cc.
References Nsound::Buffer::cbegin(), generate2(), is_realtime_, M_ASSERT_VALUE, reset(), and sample_rate_.
|
virtual |
This method oscillates the waveform stored in this generator.
duration | the number of seconds to oscillate the waveform |
frequency | the frequency in Hz |
phase | the natural phase (0.0 to 1.0) |
This is a special case of generate2(const float64 & duration, const Buffer & frequencies, const Buffer & phase) with constant phase.
Reimplemented in Nsound::Pulse, Nsound::GeneratorDecay, and Nsound::Pluck.
Definition at line 1159 of file Generator.cc.
References Nsound::Buffer::cbegin(), generate2(), is_realtime_, M_ASSERT_VALUE, reset(), and sample_rate_.
|
virtual |
This method oscillates the waveform stored in this generator.
duration | the number of seconds to oscillate the waveform |
frequency | the frequency in Hz |
phase | the natural phase (0.0 to 1.0) |
Reimplemented in Nsound::GeneratorDecay, Nsound::Pulse, and Nsound::Pluck.
Definition at line 1184 of file Generator.cc.
References Nsound::Buffer::cbegin(), generate2(), is_realtime_, M_ASSERT_VALUE, reset(), and sample_rate_.
Generator & Generator::operator= | ( | const Nsound::Generator & | rhs | ) |
Assignment operator.
Definition at line 1210 of file Generator.cc.
References buzz_max_harmonics_, buzz_position_, chorus_factor_, chorus_is_on_, chorus_n_voices_, chorus_position_, last_frequency_, position_, rng_, sample_rate_, sample_time_, sync_count_, sync_is_master_, sync_is_slave_, sync_slaves_, sync_vector_, t_, and waveform_.
void Generator::removeSlaveSync | ( | Generator & | slave | ) |
Removes the generator from the sync list.
Definition at line 1259 of file Generator.cc.
References reset(), sync_is_slave_, and sync_slaves_.
|
virtual |
Resets the position pointer back to the begging of the waveform.
Reimplemented in Nsound::Pulse.
Definition at line 1272 of file Generator.cc.
References buzz_max_harmonics_, buzz_position_, chorus_n_voices_, chorus_position_, last_frequency_, position_, sync_count_, sync_pos_, sync_slaves_, and t_.
Referenced by addSlaveSync(), buzzInit(), generate(), generate2(), removeSlaveSync(), Nsound::FilterFlanger::reset(), and setChorus().
|
inline |
Definition at line 562 of file Generator.h.
References rng_.
void Generator::setSeed | ( | const uint32 | seed | ) |
Sets the seed for the Generator's random number generator (rng).
Definition at line 1303 of file Generator.cc.
References rng_, and Nsound::RandomNumberGenerator::setSeed().
Referenced by Generator_UnitTest(), and Sine_UnitTest().
This method generates silence.
This is a special coase of drawLine(const float64 & duration, const float64 & amplitude_start, const float64 & amplitude_finish) const where the start and stopping amplitudes are 0.0.
Definition at line 1310 of file Generator.cc.
References drawLine().
Referenced by Nsound::FFTransform::fft(), FilterDelay_UnitTest(), main(), my_main(), Nsound::Hat::play(), and Nsound::Spectrogram::Spectrogram().
float64 Generator::tell | ( | ) | const |
Returns the current position pointer, values are between 0.0 to 1.0.
Definition at line 1317 of file Generator.cc.
References position_, and sample_rate_.
This method generates noise from a uniform distribution.
Definition at line 1325 of file Generator.cc.
References Nsound::RandomNumberGenerator::get(), M_ASSERT_VALUE, rng_, and sample_rate_.
Referenced by Nsound::Pluck::generate(), Nsound::Granulator::Granulator(), main(), Nsound::DrumBD01::play(), Nsound::FluteSlide::play(), Nsound::AudioStream::rand(), and Nsound::Buffer::rand().
Buffer Generator::gaussianNoise | ( | const float64 & | duration, |
const float64 & | mu, | ||
const float64 & | sigma | ||
) | const |
This method generates noise from a Gaussian distribution.
Definition at line 1343 of file Generator.cc.
References Nsound::RandomNumberGenerator::get(), M_ASSERT_VALUE, rng_, and sample_rate_.
This method draws the tanh function accross duration samples.
Definition at line 1397 of file Generator.cc.
References M_ASSERT_VALUE, M_PI, and sample_rate_.
|
protectedvirtual |
DOXME.
Definition at line 201 of file Generator.cc.
References rng_, sample_rate_, sample_time_, and waveform_.
Referenced by Nsound::Cosine::Cosine(), ctor(), Generator(), Nsound::Sawtooth::Sawtooth(), Nsound::Sine::Sine(), Nsound::Square::Square(), and Nsound::Triangle::Triangle().
DOXME.
Definition at line 212 of file Generator.cc.
References ctor(), Nsound::Buffer::getLength(), M_THROW, rng_, sample_rate_, sample_time_, and waveform_.
|
protected |
Definition at line 611 of file Generator.h.
Referenced by generate(), generate2(), and setRealtime().
|
protected |
Definition at line 613 of file Generator.h.
Referenced by buzz(), operator=(), and reset().
|
protected |
Used for phase offset adjustment.
Definition at line 614 of file Generator.h.
Referenced by buzz(), Nsound::GeneratorDecay::generate2(), generate2(), operator=(), reset(), and tell().
|
protected |
The number of samples into the wavefrom.
Definition at line 615 of file Generator.h.
Referenced by Nsound::GeneratorDecay::generate2(), generate2(), and reset().
|
protected |
Used to determine when to create a sync sample.
Definition at line 616 of file Generator.h.
Referenced by buzz(), ctor(), drawLine(), drawSine(), drawSine2(), drawWindowBartlett(), drawWindowParzen(), gaussianNoise(), Nsound::Pluck::generate(), generate(), Nsound::GeneratorDecay::generate2(), generate2(), operator=(), Nsound::Sawtooth::Sawtooth(), Nsound::Square::Square(), tanh(), tell(), and whiteNoise().
|
protected |
The number of samples per second to generate.
Definition at line 617 of file Generator.h.
Referenced by ctor(), drawSine2(), Nsound::Pulse::generate2(), and operator=().
|
protected |
The time step between samples in seconds.
Definition at line 618 of file Generator.h.
Referenced by drawSine(), drawSine2(), Nsound::Pulse::generate2(), operator=(), Nsound::Pulse::reset(), and reset().
|
protected |
The current time (for real time draw functions.)
Definition at line 619 of file Generator.h.
Referenced by ctor(), generate2(), operator=(), and ~Generator().
|
protected |
The waveform to ossicialate.
Definition at line 621 of file Generator.h.
Referenced by ctor(), gaussianNoise(), getRandomNumberGenerator(), operator=(), setChorus(), setSeed(), whiteNoise(), and ~Generator().
|
protected |
The random number generator.
Definition at line 624 of file Generator.h.
Referenced by buzzInit(), operator=(), and reset().
|
protected |
Definition at line 625 of file Generator.h.
Referenced by operator=(), and reset().
|
protected |
Definition at line 628 of file Generator.h.
Referenced by drawSine2(), generate2(), operator=(), and setChorus().
|
protected |
Definition at line 629 of file Generator.h.
Referenced by drawSine2(), generate2(), operator=(), reset(), and setChorus().
|
protected |
Definition at line 630 of file Generator.h.
Referenced by drawSine2(), generate2(), operator=(), reset(), and setChorus().
|
protected |
Definition at line 631 of file Generator.h.
Referenced by drawSine2(), generate2(), operator=(), and setChorus().
|
protected |
Definition at line 634 of file Generator.h.
Referenced by addSlaveSync(), Nsound::GeneratorDecay::generate2(), generate2(), and operator=().
|
protected |
Indicates if this generator is the master.
Definition at line 635 of file Generator.h.
Referenced by addSlaveSync(), Nsound::GeneratorDecay::generate2(), generate2(), operator=(), and removeSlaveSync().
|
protected |
Indicates if this generator is a slave.
Definition at line 636 of file Generator.h.
Referenced by Nsound::GeneratorDecay::generate2(), generate2(), operator=(), and reset().
|
protected |
Indicates the number of samples since reset.
Definition at line 637 of file Generator.h.
Referenced by Nsound::GeneratorDecay::generate2(), generate2(), and operator=().
|
protected |
Stores sample counts when synced.
Definition at line 638 of file Generator.h.
Referenced by addSlaveSync(), Nsound::GeneratorDecay::generate2(), generate2(), operator=(), removeSlaveSync(), and reset().