Nsound
0.9.4
|
A Buffer for storing audio samples. More...
#include <Nsound/Buffer.h>
Public Types | |
typedef Nsound::circular_iterator | circular_iterator |
typedef Nsound::const_circular_iterator | const_circular_iterator |
typedef FloatVector::iterator | iterator |
typedef FloatVector::const_iterator | const_iterator |
Public Member Functions | |
Buffer () | |
Creates an empty Buffer that also calss std::vector::reserve() to preallocate memory for samples. More... | |
Buffer (uint32 chunk_size) | |
Buffer (const FloatVector &list) | |
Creates a Buffer and fills it with the contents of list. More... | |
Buffer (const std::string &filename, uint32 chunk_size=4096) | |
Creates an Buffer from a Wavefile, also specifies the chunk size. More... | |
~Buffer () | |
Destroys the Buffer. More... | |
Buffer (const Buffer &rhs) | |
Copy constructor, must be used in Python to copy Buffers. More... | |
Buffer (Buffer &&move) | |
void | abs () |
Modifies the Buffer by making any negative value positive. More... | |
Buffer | getAbs () const |
Modifies a copy of the Buffer by making any negative value positive. More... | |
void | add (const Buffer &buffer, uint32 offset=0, uint32 n_samples=0) |
This method adds buffer to *this. More... | |
uint32 | argmax () const |
Retruns the index of the maximum value in the Buffer. More... | |
uint32 | argmin () const |
Retruns the index of the minimum value in the Buffer. More... | |
iterator | begin () |
Retruns the itreator at the start of the Buffer. More... | |
const_iterator | begin () const |
Retruns the itreator at the start of the Buffer. More... | |
circular_iterator | cbegin () |
Retruns the itreator at the start of the Buffer. More... | |
const_circular_iterator | cbegin () const |
Retruns the itreator at the start of the Buffer. More... | |
iterator | end () |
Retruns the itreator at the end of the Buffer. More... | |
const_iterator | end () const |
Retruns the itreator at the end of the Buffer. More... | |
uint32 | getNBytes () const |
Retruns the number of bytes held in the Buffer array. More... | |
void | exp () |
Each sample in the Buffer becomes the power e^x. More... | |
Buffer | getExp () const |
Each sample in the Buffer becomes the power e^x. More... | |
void | convolve (const Buffer &H) |
Convolves the Buffer with another Buffer. More... | |
Buffer | getConvolve (const Buffer &H) const |
Convolves a copy of the Buffer with another Buffer. More... | |
void | dB () |
Modifies the Buffer so each sample is converted to dB, 20 * log10(sample). More... | |
Buffer | getdB () const |
Returns the Buffer in dB. More... | |
void | derivative (uint32 n) |
Calculates the nth derivative of the Buffer. More... | |
Buffer | getDerivative (uint32 n) const |
Returns the nth derivative of the Buffer. More... | |
void | downSample (uint32 n) |
Downsample this Buffer by a integral factor. N must be > 1. More... | |
Buffer | getDownSample (uint32 n) const |
Returns a copy of this Buffer downsampled by a integral factor. N must be > 1. More... | |
Uint32Vector | findPeaks (uint32 window_size=0, float64 min_height=0.0) const |
Find the peaks in the Buffer and return a vector of indicies. More... | |
uint32 | getLength () const |
Returns the number of samples in the Buffer. More... | |
void | limit (float64 min, float64 max) |
Limits the Buffer to min and max. More... | |
void | limit (const Buffer &min, const Buffer &max) |
Limits the Buffer to min and max. More... | |
Buffer | getLimit (float64 min, float64 max) const |
Returns a copy of the Buffer with min and max limits. More... | |
Buffer | getLimit (const Buffer &min, const Buffer &max) const |
Returns a copy of the Buffer with min and max limits. More... | |
void | log () |
Sets each sample in the Buffer to the natural log. More... | |
Buffer | getLog () const |
Returns the the Buffer where each sample is the natural log. More... | |
void | log10 () |
Sets each sample in the Buffer to log base 10. More... | |
Buffer | getLog10 () const |
Returns the the Buffer where each sample is the natural log. More... | |
float64 | getMax () const |
Returns the maximum sample value in the Buffer. More... | |
float64 | getMaxMagnitude () const |
Returns the maximum magnitude value in the Buffer, i.e. max(abs(samples)). More... | |
float64 | getMean () const |
Returns the mean sample value in the Buffer. More... | |
float64 | getMin () const |
Returns the minimum sample value in the Buffer. More... | |
void | mul (const Buffer &buffer, uint32 offset=0, uint32 n_samples=0) |
This method multiplies a Buffer to *this over a sub range. More... | |
void | normalize () |
Multiplies the Buffer by a constant gain so the peak sample has magnitude 1.0. More... | |
Buffer | getNormalize () const |
Returns a copy of the Buffer normalized. More... | |
Buffer | getSignalEnergy (uint32 window_size) const |
Returns the signal energy: E = 1 / N * sum(|x(i)|) over the window of N samples. More... | |
float64 | getStd () const |
Returns the standard deviation of the Buffer. More... | |
float64 | getSum () const |
Returns the sum of all samples. More... | |
void | zNorm () |
Normalized the Buffer using Z score normalizing. More... | |
Buffer | getZNorm () const |
Returns a Z score normalized copy of the Buffer. More... | |
BufferSelection | operator() (const BooleanVector &bv) |
Returns a BufferSelection object used for manipulation of a selected region of samples. More... | |
Buffer & | operator= (const Buffer &rhs) |
The assignment operator. C++ only, for Python, use the copy constructor. More... | |
boolean | operator== (const Buffer &rhs) const |
Tests of equality. More... | |
boolean | operator!= (const Buffer &rhs) const |
Tests of inequality. More... | |
float64 & | operator[] (uint32 index) |
Retruns a reference into the Buffer. More... | |
const float64 & | operator[] (uint32 index) const |
Returns a const reference into the Buffer. More... | |
Buffer & | operator<< (const AudioStream &rhs) |
Concatenates Buffers and AudioStreams together. More... | |
Buffer & | operator<< (const Buffer &rhs) |
Concatenates Buffers together. More... | |
Buffer & | operator<< (float64 d) |
Concatenates samples to the Buffer. More... | |
Buffer & | operator+= (const Buffer &rhs) |
Adds each sample from the right hand side (rhs) Buffer with this Buffer. More... | |
Buffer & | operator-= (const Buffer &rhs) |
Subracts each sample from the right hand side (rhs) Buffer from this Buffer. More... | |
Buffer & | operator*= (const Buffer &rhs) |
Multiplies each sample from the right hand side (rhs) with this Buffer. More... | |
Buffer & | operator/= (const Buffer &rhs) |
Divides each sample in this Buffer with the right hand side (rhs) Buffer. More... | |
Buffer & | operator^= (const Buffer &powers) |
Each sample in the Buffer becomes the power x^n. More... | |
Buffer & | operator+= (float64 d) |
Adds the sample d to each sample in this Buffer. More... | |
Buffer & | operator-= (float64 d) |
Subtracts the sample d from each sample in this Buffer. More... | |
Buffer & | operator*= (float64 d) |
Multiplies the sample d with each sample in this Buffer. More... | |
Buffer & | operator/= (float64 d) |
Divides each sample in this Buffer by d. More... | |
Buffer & | operator^= (float64 power) |
Each sample in the Buffer becomes the power x^n. More... | |
BooleanVector | operator> (float64 rhs) |
Creates a BooleanVector where each value is true iff Buffer[n] > rhs. More... | |
BooleanVector | operator>= (float64 rhs) |
Creates a BooleanVector where each value is true iff Buffer[n] >= rhs. More... | |
BooleanVector | operator< (float64 rhs) |
Creates a BooleanVector where each value is true iff Buffer[n] < rhs. More... | |
BooleanVector | operator<= (float64 rhs) |
Creates a BooleanVector where each value is true iff Buffer[n] <= rhs. More... | |
BooleanVector | operator== (float64 rhs) |
Creates a BooleanVector where each value is true iff Buffer[n] == rhs. More... | |
BooleanVector | operator!= (float64 rhs) |
Creates a BooleanVector where each value is true iff Buffer[n] != rhs. More... | |
void | plot (const std::string &title="Buffer") const |
Requires matplotlib. Creates a plot of this Buffer. More... | |
const float64 * | getPointer () const |
Returns the raw point to the first sample in the Buffer. More... | |
float64 * | getPointer () |
Requires matplotlib. Creates a plot of this Buffer. More... | |
void | preallocate (uint32 n) |
Preallocates memory to hold an additional n samples. More... | |
void | readWavefile (const char *filename) |
Sets this Buffer to the contents of the wavefile on the disk. More... | |
void | resample (float64 factor) |
Resamples this Buffer using discrete-time resampling. More... | |
void | resample (const Buffer &factor) |
Resamples this Buffer using discrete-time resampling. More... | |
Buffer | getResample (float64 factor, const uint32 N=10, float64 beta=5.0) const |
Resamples a copy of this Buffer using discrete-time resampling. More... | |
Buffer | getResample (const Buffer &factor, const uint32 N=10, float64 beta=5.0) const |
Resamples a copy of this Buffer using discrete-time resampling. More... | |
Buffer | getResample (const uint32 L, const uint32 M, const uint32 N=10, float64 beta=5.0) const |
Resamples a copy of this Buffer using discrete-time resampling. More... | |
void | reverse () |
Reverses the samples in this Buffer. More... | |
Buffer | getReverse () const |
Reverses the samples in a copy of this Buffer. More... | |
void | round () |
Rounds the samples in this Buffer to the nearest integer value. More... | |
Buffer | getRound () const |
Rounds the samples in a copy of this Buffer to the nearest integer value. More... | |
BufferSelection | select (const uint32 start_index, const uint32 stop_index) |
Returns a BufferSelection for the range of indicies. More... | |
std::ostream & | write (std::ostream &out) const |
Serializes the Buffer to output stream, no endian checks. More... | |
std::string | write () const |
std::istream & | read (std::istream &stream_in) |
Constructs a Buffer from seralized data in the inputstream. More... | |
void | read (const std::string &string_in) |
void | smooth (uint32 n_passes, uint32 n_samples_per_average) |
Applies a moving average filter to smooth this Buffer. More... | |
Buffer | getSmooth (uint32 n_passes, uint32 n_samples_per_average) const |
Applies a moving average filter to smooth a copy of this Buffer. More... | |
void | speedUp (float64 step_size) |
Resamples this Buffer by the step_size, no interpolation. More... | |
Buffer | getSpeedUp (float64 step_size) const |
Resamples a copy of this Buffer by the step_size, no interpolation. More... | |
void | speedUp (const Buffer &step_size) |
Resamples this Buffer on a sample by sample basis, no interpolation. More... | |
Buffer | getSpeedUp (const Buffer &step_size) const |
Resamples a copy of this Buffer on a sample by sample basis, no interpolation. More... | |
void | sqrt () |
Takes the square root of each sample in this Buffer. More... | |
Buffer | getSqrt () const |
Taks the square root of each sample in a copy of this Buffer. More... | |
Buffer | subbuffer (uint32 start_index, uint32 n_samples=0) const |
Slice the Buffer. More... | |
void | upSample (uint32 n) |
Upsample this Buffer by a integral factor. N must be > 1. More... | |
Buffer | getUpSample (uint32 n) const |
Upsample a copy of this Buffer by a integral factor. N must be > 1. More... | |
void | writeWavefile (const char *filename) const |
Writes the Buffer to a Wavefile. More... | |
void | _set_at_index (int32 index, float64 x) |
SWIG helper function function to shadow. More... | |
void | _swig_shadow () |
SWIG helper function function to shadow. More... | |
Static Public Member Functions | |
static Buffer | ones (const uint32 n_samples) |
Returns a Buffer full of ones of length n_samples. More... | |
static Buffer | rand (const uint32 n_samples) |
Returns a Buffer full of random values of length n_samples. More... | |
static Buffer | zeros (const uint32 n_samples) |
Returns a Buffer full of zeros of length n_samples. More... | |
Protected Member Functions | |
Buffer | _get_resample (const uint32 L, const uint32 M, const uint32 N, float64 beta) const |
Protected Attributes | |
FloatVector | data_ |
Static Protected Attributes | |
static const uint32 | bytes_per_sample_ = sizeof(float64) |
Friends | |
std::ostream & | operator<< (std::ostream &out, const Buffer &rhs) |
Sends the contents of the Buffer to the output stream. More... | |
A Buffer for storing audio samples.
This is the workhourse of Nsound. This class dynamically allocates memory and frees the user of the class from worrying about buffer sizes. This class does not have a sample rate, samples are indexed by an integer index.
typedef FloatVector::iterator Nsound::Buffer::iterator |
typedef FloatVector::const_iterator Nsound::Buffer::const_iterator |
Nsound::Buffer::Buffer | ( | ) |
|
explicit |
|
explicit |
Creates a Buffer and fills it with the contents of list.
list | a FloatVector holding samples |
Definition at line 78 of file Buffer.cc.
Nsound::Buffer::Buffer | ( | const std::string & | filename, |
uint32 | chunk_size = 4096 |
||
) |
Nsound::Buffer::~Buffer | ( | ) |
Nsound::Buffer::Buffer | ( | const Buffer & | rhs | ) |
Nsound::Buffer::Buffer | ( | Buffer && | move | ) |
void Nsound::Buffer::abs | ( | ) |
Modifies the Buffer by making any negative value positive.
Definition at line 119 of file Buffer.cc.
References data_.
Referenced by Buffer_UnitTest(), DelayLine_UnitTest(), FFTransform_UnitTest(), FilterCombLowPassFeedback_UnitTest(), FilterLeastSquaresFIR_UnitTest(), FilterParametricEqualizer_UnitTest(), Generator_UnitTest(), getAbs(), main(), Sine_UnitTest(), and Triangle_UnitTest().
|
inline |
Modifies a copy of the Buffer by making any negative value positive.
Definition at line 174 of file Buffer.h.
References abs().
Referenced by Buffer_UnitTest(), BufferResample_UnitTest(), FFTransform_UnitTest(), FilterLeastSquaresFIR_UnitTest(), and main().
This method adds buffer to *this.
If the length of 'buffer' is longer than *this, *this will be extended. If n_samples is 0, the whole length of buffer will get added, otherwise, only n_samples will get added.
For example:
a = sample in *this b = sample in buffer c = a + b
this = [aaaaaaaaaaaaaaaaaaaaaaaaaaaa] + |--offset--|[bbbbbbbbb buffer bbbbbbbbbbbbbbbbbb]
= [aaaaaaaaaaacccccccccccccccccbbbbbbbbbbbbbbbbbbb]
Another exampple:
a = sample in *this b = sample in buffer c = a + b
this = [aaaaaaaaaaaaaaaaaaaaaaaaaaaa] + |--offset--|[bbbbbbbbb buffer bbbbbbbbbbbbbbbbbb] |--------n_samples------|
= [aaaaaaaaaaaccccccccccccccccccbbbbbbb]
offset | - The index into this Buffer to start adding |
buffer | - The Buffer to add data from |
n_samples | - The number of samples from buffer to add |
Definition at line 225 of file Buffer.cc.
References data_, and getLength().
Referenced by Nsound::Granulator::generate(), main(), Nsound::Stretcher::overlapAdd(), and testBufferAdd().
uint32 Nsound::Buffer::argmax | ( | ) | const |
Retruns the index of the maximum value in the Buffer.
Definition at line 460 of file Buffer.cc.
References begin(), and end().
Referenced by my_main().
uint32 Nsound::Buffer::argmin | ( | ) | const |
Retruns the index of the minimum value in the Buffer.
Definition at line 485 of file Buffer.cc.
References begin(), and end().
|
inline |
Retruns the itreator at the start of the Buffer.
Definition at line 285 of file Buffer.h.
References data_.
Referenced by _get_resample(), argmax(), argmin(), Nsound::FilterHighPassFIR::filter(), Nsound::FilterLowPassFIR::filter(), Nsound::Filter::filter(), Nsound::FilterStageIIR::filter(), Nsound::FilterBandRejectFIR::filter(), Nsound::FFTransform::ifft(), limit(), operator!=(), operator<(), operator<=(), operator==(), operator>(), operator>=(), round(), Nsound::EnvelopeAdsr::shape(), smooth(), and sqrt().
|
inline |
|
inline |
Retruns the itreator at the start of the Buffer.
Definition at line 318 of file Buffer.h.
References data_.
Referenced by Nsound::Stretcher::analyize(), Nsound::Generator::buzz(), Nsound::DelayLine::delay(), Nsound::Generator::drawSine(), Nsound::Generator::drawSine2(), Nsound::Vocoder::filter(), Nsound::Filter::filter(), Nsound::FilterBandPassVocoder::filter(), Nsound::FilterFlanger::filter(), Nsound::Generator::generate(), Nsound::Generator::generate2(), limit(), and Nsound::GuitarBass::play().
|
inline |
Retruns the itreator at the start of the Buffer.
Definition at line 333 of file Buffer.h.
References data_.
|
inline |
Retruns the itreator at the end of the Buffer.
Definition at line 348 of file Buffer.h.
References data_.
Referenced by _get_resample(), argmax(), argmin(), Nsound::FilterHighPassFIR::filter(), Nsound::FilterLowPassFIR::filter(), Nsound::Filter::filter(), Nsound::FilterStageIIR::filter(), Nsound::FilterBandRejectFIR::filter(), limit(), operator!=(), operator<(), operator<<(), operator<=(), operator==(), operator>(), operator>=(), round(), Nsound::EnvelopeAdsr::shape(), smooth(), and sqrt().
|
inline |
|
inline |
Retruns the number of bytes held in the Buffer array.
Definition at line 380 of file Buffer.h.
References bytes_per_sample_, and data_.
void Nsound::Buffer::exp | ( | ) |
Each sample in the Buffer becomes the power e^x.
Each sample in the Buffer becomes the power e^x, where x is the Buffer sample.
Definition at line 510 of file Buffer.cc.
References data_, and getLength().
Referenced by Nsound::Generator::drawDecay(), Nsound::Generator::drawGaussian(), and getExp().
|
inline |
Each sample in the Buffer becomes the power e^x.
Each sample in the Buffer becomes the power e^x, where x is the Buffer sample.
Definition at line 417 of file Buffer.h.
References exp().
void Nsound::Buffer::convolve | ( | const Buffer & | H | ) |
Convolves the Buffer with another Buffer.
H | another Buffer to convole with. |
Definition at line 520 of file Buffer.cc.
References getConvolve().
Convolves a copy of the Buffer with another Buffer.
H | another Buffer to convole with. |
Definition at line 527 of file Buffer.cc.
References getLength().
Referenced by convolve().
void Nsound::Buffer::dB | ( | ) |
Modifies the Buffer so each sample is converted to dB, 20 * log10(sample).
Definition at line 567 of file Buffer.cc.
References log10().
Referenced by getdB(), and Nsound::FFTChunk::plot().
|
inline |
Returns the Buffer in dB.
Definition at line 487 of file Buffer.h.
References dB().
Referenced by FilterLeastSquaresFIR_UnitTest(), and Nsound::Filter::plot().
void Nsound::Buffer::derivative | ( | uint32 | n | ) |
Calculates the nth derivative of the Buffer.
Definition at line 592 of file Buffer.cc.
References data_.
Referenced by getDerivative().
Returns the nth derivative of the Buffer.
Definition at line 518 of file Buffer.h.
References derivative().
Referenced by Nsound::FilterLeastSquaresFIR::makeKernel().
void Nsound::Buffer::downSample | ( | uint32 | n | ) |
Downsample this Buffer by a integral factor. N must be > 1.
Definition at line 605 of file Buffer.cc.
References getDownSample().
Returns a copy of this Buffer downsampled by a integral factor. N must be > 1.
Definition at line 615 of file Buffer.cc.
References getResample(), and M_ASSERT_VALUE.
Referenced by downSample().
Uint32Vector Nsound::Buffer::findPeaks | ( | uint32 | window_size = 0 , |
float64 | min_height = 0.0 |
||
) | const |
Find the peaks in the Buffer and return a vector of indicies.
Definition at line 623 of file Buffer.cc.
References data_, and getLength().
|
inline |
Returns the number of samples in the Buffer.
Definition at line 587 of file Buffer.h.
References data_.
Referenced by _get_resample(), _set_at_index(), add(), Nsound::Stretcher::analyize(), Buffer_UnitTest(), BufferResample_UnitTest(), Nsound::Spectrogram::computeMagnitude(), cosinewindow(), Nsound::Generator::ctor(), Nsound::FilterIIR::designKernel(), Nsound::Generator::drawWindowKaiser(), exp(), Nsound::FFTransform::fft(), FFTransform_UnitTest(), Nsound::FilterDC::filter(), Nsound::Vocoder::filter(), Nsound::FilterLowPassFIR::filter(), Nsound::Filter::filter(), Nsound::FilterSlinky::filter(), Nsound::ReverberationRoom::filter(), Nsound::FilterBandPassVocoder::filter(), Nsound::FilterFlanger::filter(), Nsound::FilterStageIIR::filter(), Nsound::FilterBandRejectFIR::filter(), Nsound::FilterBandRejectIIR::filter(), Nsound::FilterParametricEqualizer::filter(), findPeaks(), Nsound::Granulator::generate(), Nsound::Generator::Generator(), getConvolve(), Nsound::FFTChunk::getFrequencyAxis(), Nsound::FFTChunk::getImaginary(), Nsound::FFTChunk::getMagnitude(), getMean(), Nsound::BufferWindowSearch::getNextWindow(), Nsound::FFTChunk::getPhase(), Nsound::Filter::getPhaseResponse(), Nsound::FFTChunk::getReal(), getResample(), Nsound::FilterIIR::getRMS(), Nsound::BufferWindowSearch::getSamplesLeft(), getSignalEnergy(), getStd(), Nsound::Granulator::Granulator(), Nsound::FFTransform::ifft(), Nsound::Plotter::imagesc(), log(), log10(), main(), Nsound::FilterLeastSquaresFIR::makeKernel(), mul(), my_main(), operator*=(), operator+=(), operator-=(), Nsound::operator/(), operator/=(), operator<<(), Nsound::operator^(), operator^=(), Nsound::Stretcher::overlapAdd(), Nsound::AudioStream::pan(), Nsound::Clarinet::play(), Nsound::FluteSlide::play(), play_int(), Nsound::FFTChunk::plot(), Nsound::Plotter::plot(), Nsound::CircularBuffer::read(), reverse(), Nsound::FilterIIR::savePlot(), select(), Nsound::Kernel::setA(), Nsound::Kernel::setB(), Nsound::FilterLeastSquaresFIR::setKernel(), Nsound::EnvelopeAdsr::shape(), Nsound::Spectrogram::Spectrogram(), speedUp(), Nsound::Stretcher::Stretcher(), Nsound::Mesh2D::strike(), subbuffer(), testAutioStream(), testBufferAdd(), Nsound::FFTChunk::toCartesian(), Nsound::FFTChunk::toPolar(), Nsound::Triangle::Triangle(), Nsound::Vocoder::Vocoder(), Nsound::CircularBuffer::write(), Nsound::Wavefile::write(), write(), and zNorm().
Limits the Buffer to min and max.
Definition at line 876 of file Buffer.cc.
References begin(), and end().
Referenced by getLimit(), and Nsound::DrumBD01::play().
Limits the Buffer to min and max.
Definition at line 896 of file Buffer.cc.
References begin(), cbegin(), and end().
Returns a copy of the Buffer with min and max limits.
Definition at line 649 of file Buffer.h.
References limit().
Returns a copy of the Buffer with min and max limits.
Definition at line 670 of file Buffer.h.
References limit().
void Nsound::Buffer::log | ( | ) |
Sets each sample in the Buffer to the natural log.
Definition at line 923 of file Buffer.cc.
References data_, getLength(), and LM_MAX.
Referenced by getLog().
|
inline |
Returns the the Buffer where each sample is the natural log.
Definition at line 701 of file Buffer.h.
References log().
void Nsound::Buffer::log10 | ( | ) |
Sets each sample in the Buffer to log base 10.
Definition at line 936 of file Buffer.cc.
References data_, getLength(), and LM_MAX.
Referenced by dB(), and getLog10().
|
inline |
Returns the the Buffer where each sample is the natural log.
Definition at line 732 of file Buffer.h.
References log10().
float64 Nsound::Buffer::getMax | ( | ) | const |
Returns the maximum sample value in the Buffer.
Definition at line 951 of file Buffer.cc.
References data_, and M_ASSERT_VALUE.
Referenced by Buffer_UnitTest(), BufferResample_UnitTest(), Nsound::Generator::buzz(), DelayLine_UnitTest(), FFTransform_UnitTest(), Nsound::FilterBandPassIIR::FilterBandPassIIR(), FilterCombLowPassFeedback_UnitTest(), FilterLeastSquaresFIR_UnitTest(), FilterParametricEqualizer_UnitTest(), Generator_UnitTest(), main(), Nsound::Filter::plot(), Nsound::FilterIIR::savePlot(), Sine_UnitTest(), and Triangle_UnitTest().
float64 Nsound::Buffer::getMaxMagnitude | ( | ) | const |
Returns the maximum magnitude value in the Buffer, i.e. max(abs(samples)).
Definition at line 973 of file Buffer.cc.
References data_, and M_ASSERT_VALUE.
Referenced by normalize().
float64 Nsound::Buffer::getMean | ( | ) | const |
Returns the mean sample value in the Buffer.
Definition at line 995 of file Buffer.cc.
References getLength(), and getSum().
Referenced by getResample(), getStd(), and zNorm().
float64 Nsound::Buffer::getMin | ( | ) | const |
Returns the minimum sample value in the Buffer.
Definition at line 1004 of file Buffer.cc.
References data_, and M_ASSERT_VALUE.
Referenced by Buffer_UnitTest(), main(), and Nsound::FilterLeastSquaresFIR::makeKernel().
This method multiplies a Buffer to *this over a sub range.
If the length of 'buffer' is longer than *this, *this will be extended. If n_samples is 0, the whole length of buffer will get added, otherwise, only n_samples will get added.
Examples:
a = sample in *this b = sample in buffer c = a * b
this = [aaaaaaaaaaaaaaaaaaaaaaaaaaaa] * | offset |[bbbbbbbbb buffer bbbbbbbbbbbbbbbbbb]
= [aaaaaaaaaaaccccccccccccccccc]
a = sample in *this b = sample in buffer c = a * b
this = [aaaaaaaaaaaaaaaaaaaaaaaaaaaa] + | offset |[bbbbbbbbb buffer bbbbbbbbbbbbbbbbbb] |-n_samples---|
= [aaaaaaaaaaacccccccccccccccaa]
offset | - The index into this Buffer to start multiplying |
buffer | - The Buffer to multiply data from |
n_samples | - The number of samples from buffer to multiply |
Definition at line 1025 of file Buffer.cc.
References getLength(), and M_ASSERT_VALUE.
void Nsound::Buffer::normalize | ( | ) |
Multiplies the Buffer by a constant gain so the peak sample has magnitude 1.0.
Definition at line 1064 of file Buffer.cc.
References getMaxMagnitude().
Referenced by Nsound::Generator::drawGaussian(), FilterCombLowPassFeedback_UnitTest(), Nsound::Pluck::generate(), getNormalize(), main(), my_main(), and Nsound::DrumBD01::play().
|
inline |
Returns a copy of the Buffer normalized.
Definition at line 885 of file Buffer.h.
References normalize().
Returns the signal energy: E = 1 / N * sum(|x(i)|) over the window of N samples.
Definition at line 1077 of file Buffer.cc.
References data_, and getLength().
float64 Nsound::Buffer::getStd | ( | ) | const |
Returns the standard deviation of the Buffer.
Definition at line 1107 of file Buffer.cc.
References getLength(), getMean(), and getSum().
float64 Nsound::Buffer::getSum | ( | ) | const |
Returns the sum of all samples.
Definition at line 1118 of file Buffer.cc.
References data_.
Referenced by getMean(), Nsound::FilterIIR::getRMS(), getStd(), Nsound::Stretcher::searchForBestMatch(), and zNorm().
void Nsound::Buffer::zNorm | ( | ) |
Normalized the Buffer using Z score normalizing.
z = (x - mean(x)) / std(x)
Definition at line 1134 of file Buffer.cc.
References getLength(), getMean(), getSum(), and sqrt().
Referenced by getZNorm().
|
inline |
Returns a Z score normalized copy of the Buffer.
z = (x - mean(x)) / std(x)
Definition at line 965 of file Buffer.h.
References zNorm().
BufferSelection Nsound::Buffer::operator() | ( | const BooleanVector & | bv | ) |
Returns a BufferSelection object used for manipulation of a selected region of samples.
Buffer & Nsound::Buffer::operator<< | ( | const AudioStream & | rhs | ) |
Concatenates Buffers and AudioStreams together.
Definition at line 1219 of file Buffer.cc.
References Nsound::AudioStream::getMono().
Concatenates Buffers together.
Definition at line 1226 of file Buffer.cc.
References data_, end(), and getLength().
Adds each sample from the right hand side (rhs) Buffer with this Buffer.
All arithmatic operations only operate for N samples where N is min(b1.getLength(), b2.getLength()).
Definition at line 1254 of file Buffer.cc.
References data_, and getLength().
Subracts each sample from the right hand side (rhs) Buffer from this Buffer.
All arithmatic operations only operate for N samples where N is min(b1.getLength(), b2.getLength()).
Definition at line 1263 of file Buffer.cc.
References data_, and getLength().
Multiplies each sample from the right hand side (rhs) with this Buffer.
All arithmatic operations only operate for N samples where N is min(b1.getLength(), b2.getLength()).
Definition at line 1272 of file Buffer.cc.
References data_, and getLength().
Divides each sample in this Buffer with the right hand side (rhs) Buffer.
All arithmatic operations only operate for N samples where N is min(b1.getLength(), b2.getLength()).
Definition at line 1281 of file Buffer.cc.
References data_, and getLength().
Each sample in the Buffer becomes the power x^n.
Each sample in the Buffer becomes the power x^n, where x is the Buffer sample and N is the power.
Definition at line 1290 of file Buffer.cc.
References data_, and getLength().
Each sample in the Buffer becomes the power x^n.
Each sample in the Buffer becomes the power x^n, where x is the Buffer sample and N is the power.
Definition at line 1331 of file Buffer.cc.
References data_.
BooleanVector Nsound::Buffer::operator> | ( | float64 | rhs | ) |
Creates a BooleanVector where each value is true iff Buffer[n] > rhs.
Definition at line 2127 of file Buffer.cc.
References begin(), and end().
BooleanVector Nsound::Buffer::operator>= | ( | float64 | rhs | ) |
Creates a BooleanVector where each value is true iff Buffer[n] >= rhs.
Definition at line 2146 of file Buffer.cc.
References begin(), and end().
BooleanVector Nsound::Buffer::operator< | ( | float64 | rhs | ) |
Creates a BooleanVector where each value is true iff Buffer[n] < rhs.
Definition at line 2165 of file Buffer.cc.
References begin(), and end().
BooleanVector Nsound::Buffer::operator<= | ( | float64 | rhs | ) |
Creates a BooleanVector where each value is true iff Buffer[n] <= rhs.
Definition at line 2184 of file Buffer.cc.
References begin(), and end().
BooleanVector Nsound::Buffer::operator== | ( | float64 | rhs | ) |
Creates a BooleanVector where each value is true iff Buffer[n] == rhs.
Definition at line 2203 of file Buffer.cc.
References begin(), and end().
BooleanVector Nsound::Buffer::operator!= | ( | float64 | rhs | ) |
Creates a BooleanVector where each value is true iff Buffer[n] != rhs.
Definition at line 2221 of file Buffer.cc.
References begin(), and end().
void Nsound::Buffer::plot | ( | const std::string & | title = "Buffer" | ) | const |
Requires matplotlib. Creates a plot of this Buffer.
Definition at line 1551 of file Buffer.cc.
References Nsound::Plotter::figure(), Nsound::Plotter::plot(), and Nsound::Plotter::title().
Referenced by Buffer_UnitTest(), BufferResample_UnitTest(), DelayLine_UnitTest(), FFTransform_UnitTest(), FilterCombLowPassFeedback_UnitTest(), FilterLeastSquaresFIR_UnitTest(), FilterParametricEqualizer_UnitTest(), Generator_UnitTest(), main(), Sine_UnitTest(), testBufferAdd(), and Triangle_UnitTest().
|
inline |
Returns the raw point to the first sample in the Buffer.
Definition at line 1382 of file Buffer.h.
References data_.
Referenced by Nsound::FilterLeastSquaresFIR::FilterLeastSquaresFIR(), Nsound::FilterLeastSquaresFIR::makeKernel(), Nsound::FilterLeastSquaresFIR::setKernel(), and Nsound::FilterLeastSquaresFIR::setWindow().
|
inline |
void Nsound::Buffer::preallocate | ( | uint32 | n | ) |
Preallocates memory to hold an additional n samples.
This makes a call to std::vector::reserve( this->getLength() + n).
Definition at line 1544 of file Buffer.cc.
References data_.
void Nsound::Buffer::readWavefile | ( | const char * | filename | ) |
Sets this Buffer to the contents of the wavefile on the disk.
If the wavefile is stereo, it only reads the first channel.
Definition at line 1562 of file Buffer.cc.
References M_CHECK_PTR.
|
inline |
Resamples this Buffer using discrete-time resampling.
Definition at line 1446 of file Buffer.h.
References getResample().
Referenced by main().
|
inline |
Resamples this Buffer using discrete-time resampling.
Definition at line 1467 of file Buffer.h.
References getResample().
Buffer Nsound::Buffer::getResample | ( | float64 | factor, |
const uint32 | N = 10 , |
||
float64 | beta = 5.0 |
||
) | const |
Resamples a copy of this Buffer using discrete-time resampling.
Definition at line 1607 of file Buffer.cc.
References Nsound::find_fraction().
Referenced by BufferResample_UnitTest(), getDownSample(), getResample(), getUpSample(), Nsound::Stretcher::pitchShift(), and resample().
Buffer Nsound::Buffer::getResample | ( | const Buffer & | factor, |
const uint32 | N = 10 , |
||
float64 | beta = 5.0 |
||
) | const |
Resamples a copy of this Buffer using discrete-time resampling.
Definition at line 1622 of file Buffer.cc.
References getLength(), getMean(), Nsound::BufferWindowSearch::getNextWindow(), getResample(), Nsound::BufferWindowSearch::getSamplesLeft(), and subbuffer().
Buffer Nsound::Buffer::getResample | ( | const uint32 | L, |
const uint32 | M, | ||
const uint32 | N = 10 , |
||
float64 | beta = 5.0 |
||
) | const |
Resamples a copy of this Buffer using discrete-time resampling.
Definition at line 1653 of file Buffer.cc.
References _get_resample(), getLength(), Nsound::BufferWindowSearch::getNextWindow(), and Nsound::BufferWindowSearch::getSamplesLeft().
void Nsound::Buffer::reverse | ( | ) |
Reverses the samples in this Buffer.
Definition at line 1850 of file Buffer.cc.
References data_, and getLength().
Referenced by Buffer_UnitTest(), and getReverse().
|
inline |
Reverses the samples in a copy of this Buffer.
Definition at line 1558 of file Buffer.h.
References reverse().
Referenced by _get_resample(), Nsound::Granulator::Granulator(), Nsound::FFTransform::ifft(), Nsound::FilterLeastSquaresFIR::makeKernel(), and Nsound::Stretcher::overlapAdd().
void Nsound::Buffer::round | ( | ) |
Rounds the samples in this Buffer to the nearest integer value.
Values with remainders 0.5 or greater are rounded up, otherwise truncated.
Definition at line 1864 of file Buffer.cc.
References begin(), and end().
Referenced by getRound().
|
inline |
Rounds the samples in a copy of this Buffer to the nearest integer value.
Values with remainders 0.5 or greater are rounded up, otherwise truncated.
Definition at line 1593 of file Buffer.h.
References round().
BufferSelection Nsound::Buffer::select | ( | const uint32 | start_index, |
const uint32 | stop_index | ||
) |
Returns a BufferSelection for the range of indicies.
start_index | the start of the selection |
stop_index | the stop of the selection |
Definition at line 1897 of file Buffer.cc.
References getLength().
std::ostream & Nsound::Buffer::write | ( | std::ostream & | out | ) | const |
Serializes the Buffer to output stream, no endian checks.
out | the std::ostream to write bytes to |
Definition at line 1922 of file Buffer.cc.
References data_, and getLength().
std::istream & Nsound::Buffer::read | ( | std::istream & | stream_in | ) |
void Nsound::Buffer::read | ( | const std::string & | string_in | ) |
Definition at line 1972 of file Buffer.cc.
References read().
Applies a moving average filter to smooth this Buffer.
n_passes | the number of times to repeat the moving average |
n_samples_per_average | the number of samples to average |
Definition at line 1981 of file Buffer.cc.
References begin(), end(), Nsound::FilterMovingAverage::filter(), and Nsound::FilterMovingAverage::reset().
Referenced by Buffer_UnitTest(), Nsound::Pluck::generate(), and getSmooth().
Applies a moving average filter to smooth a copy of this Buffer.
n_passes | the number of times to repeat the moving average |
n_samples_per_average | the number of samples to average |
Definition at line 1672 of file Buffer.h.
References smooth().
void Nsound::Buffer::speedUp | ( | float64 | step_size | ) |
Resamples this Buffer by the step_size, no interpolation.
Definition at line 2008 of file Buffer.cc.
References data_.
Referenced by getSpeedUp().
Resamples a copy of this Buffer by the step_size, no interpolation.
Definition at line 1707 of file Buffer.h.
References speedUp().
Referenced by Nsound::FFTransform::fft(), and Nsound::Stretcher::pitchShift().
void Nsound::Buffer::speedUp | ( | const Buffer & | step_size | ) |
Resamples this Buffer on a sample by sample basis, no interpolation.
Definition at line 2024 of file Buffer.cc.
References getLength().
Resamples a copy of this Buffer on a sample by sample basis, no interpolation.
Definition at line 1748 of file Buffer.h.
References speedUp().
void Nsound::Buffer::sqrt | ( | ) |
Takes the square root of each sample in this Buffer.
Definition at line 2051 of file Buffer.cc.
References begin(), and end().
Referenced by getSqrt(), and zNorm().
|
inline |
Taks the square root of each sample in a copy of this Buffer.
Definition at line 1779 of file Buffer.h.
References sqrt().
Referenced by Nsound::DrumBD01::play().
Slice the Buffer.
Definition at line 2073 of file Buffer.cc.
References data_, and getLength().
Referenced by _get_resample(), Buffer_UnitTest(), Nsound::Spectrogram::computeMagnitude(), Nsound::FFTransform::fft(), Nsound::FFTChunk::getImaginary(), Nsound::FFTChunk::getMagnitude(), Nsound::BufferWindowSearch::getNextWindow(), Nsound::FFTChunk::getPhase(), Nsound::Filter::getPhaseResponse(), Nsound::FFTChunk::getReal(), getResample(), Nsound::FFTransform::ifft(), Nsound::FilterLeastSquaresFIR::makeKernel(), my_main(), Nsound::Stretcher::overlapAdd(), Nsound::FFTChunk::plot(), Nsound::Stretcher::searchForBestMatch(), Nsound::Spectrogram::Spectrogram(), and Nsound::Triangle::Triangle().
void Nsound::Buffer::upSample | ( | uint32 | n | ) |
Upsample this Buffer by a integral factor. N must be > 1.
Definition at line 2101 of file Buffer.cc.
References getUpSample().
Upsample a copy of this Buffer by a integral factor. N must be > 1.
Definition at line 2111 of file Buffer.cc.
References getResample().
Referenced by upSample().
void Nsound::Buffer::writeWavefile | ( | const char * | filename | ) | const |
Writes the Buffer to a Wavefile.
Definition at line 2118 of file Buffer.cc.
References M_CHECK_PTR, and Nsound::operator>>().
SWIG helper function function to shadow.
Definition at line 1876 of file Buffer.cc.
References data_, getLength(), and M_THROW.
|
inline |
Returns a Buffer full of ones of length n_samples.
Definition at line 2239 of file Buffer.cc.
References Nsound::Generator::drawLine().
Referenced by Buffer_UnitTest(), and Nsound::AudioStream::pad().
Returns a Buffer full of random values of length n_samples.
Definition at line 2252 of file Buffer.cc.
References Nsound::Generator::whiteNoise().
Returns a Buffer full of zeros of length n_samples.
Definition at line 2265 of file Buffer.cc.
References Nsound::Generator::drawLine().
Referenced by Nsound::Spectrogram::computeMagnitude(), Nsound::Sawtooth::Sawtooth(), and Nsound::Square::Square().
|
protected |
Definition at line 1684 of file Buffer.cc.
References begin(), data_, end(), Nsound::FilterLeastSquaresFIR::filter(), Nsound::FilterLeastSquaresFIR::getKernel(), getLength(), getReverse(), M_ASSERT_VALUE, Nsound::FilterLeastSquaresFIR::setKernel(), sr, and subbuffer().
Referenced by getResample().
|
friend |
Sends the contents of the Buffer to the output stream.
Definition at line 1338 of file Buffer.cc.
|
protected |
Definition at line 1874 of file Buffer.h.
Referenced by _get_resample(), _set_at_index(), abs(), add(), begin(), Buffer(), cbegin(), derivative(), end(), exp(), findPeaks(), getLength(), getMax(), getMaxMagnitude(), getMin(), getNBytes(), getPointer(), getSignalEnergy(), getSum(), log(), log10(), operator!=(), operator*=(), operator+=(), operator-=(), operator/=(), operator<<(), Nsound::operator<<(), operator=(), operator==(), operator[](), operator^=(), preallocate(), read(), reverse(), speedUp(), subbuffer(), and write().
Definition at line 1876 of file Buffer.h.
Referenced by getNBytes().