33 #ifndef _NSOUND_BUFFER_H_
34 #define _NSOUND_BUFFER_H_
122 Buffer(
const std::string & filename,
uint32 chunk_size = 4096);
175 {
Buffer temp(*
this); temp.
abs();
return temp; }
286 {
return data_.begin(); }
304 {
return data_.begin(); }
349 {
return data_.end(); }
364 {
return data_.end(); }
418 {
Buffer temp(*
this); temp.
exp();
return temp; }
488 {
Buffer temp(*
this); temp.
dB();
return temp; }
566 float64 min_height = 0.0)
const;
650 {
Buffer temp(*
this); temp.
limit(min, max);
return temp; }
671 {
Buffer temp(*
this); temp.
limit(min, max);
return temp; }
702 {
Buffer temp(*
this); temp.
log();
return temp; }
999 {
return data_[index]; }
1005 {
return data_[index]; }
1045 {
data_.push_back(d);
return *
this; }
1368 plot(
const std::string & title =
"Buffer")
const;
1383 {
return data_.data(); }
1398 {
return data_.data(); }
1594 {
Buffer temp(*
this); temp.
round();
return temp; }
1620 write(std::ostream & out)
const;
1632 read(std::istream & stream_in);
1636 read(
const std::string & string_in);
1673 {
Buffer temp(*
this); temp.
smooth(n_passes, n_samples_per_average);
return temp; }
1708 {
Buffer temp(*
this); temp.
speedUp(step_size);
return temp; }
1749 {
Buffer temp(*
this); temp.
speedUp(step_size);
return temp; }
1780 {
Buffer temp(*
this); temp.
sqrt();
return temp; }
1999 return (rhs * -1.0) + d;
2015 for(
uint32 i = 0; i < size; ++i)
2017 temp[i] = d / rhs[i];
2030 for(
uint32 i = 0; i < size; ++i)
2032 temp[i] = ::pow(d ,rhs[i]);
Buffer subbuffer(uint32 start_index, uint32 n_samples=0) const
Slice the Buffer.
const_iterator begin() const
Retruns the itreator at the start of the Buffer.
void resample(const Buffer &factor)
Resamples this Buffer using discrete-time resampling.
Buffer getSmooth(uint32 n_passes, uint32 n_samples_per_average) const
Applies a moving average filter to smooth a copy of this Buffer.
Buffer getSpeedUp(float64 step_size) const
Resamples a copy of this Buffer by the step_size, no interpolation.
Buffer getSpeedUp(const Buffer &step_size) const
Resamples a copy of this Buffer on a sample by sample basis, no interpolation.
std::ostream & operator<<(std::ostream &out, const Buffer &rhs_buffer)
AudioStream operator-(const AudioStream &lhs, const AudioStream &rhs)
float64 getStd() const
Returns the standard deviation of the Buffer.
boolean operator!=(const Buffer &rhs) const
Tests of inequality.
void readWavefile(const char *filename)
Sets this Buffer to the contents of the wavefile on the disk.
boolean operator==(const Buffer &rhs) const
Tests of equality.
void dB()
Modifies the Buffer so each sample is converted to dB, 20 * log10(sample).
Buffer getConvolve(const Buffer &H) const
Convolves a copy of the Buffer with another Buffer.
Buffer()
Creates an empty Buffer that also calss std::vector::reserve() to preallocate memory for samples...
AudioStream operator+(const AudioStream &lhs, const AudioStream &rhs)
AudioStream operator/(const AudioStream &lhs, const AudioStream &rhs)
float64 * getPointer()
Requires matplotlib. Creates a plot of this Buffer.
Buffer getLimit(float64 min, float64 max) const
Returns a copy of the Buffer with min and max limits.
AudioStream operator^(const AudioStream &lhs, const AudioStream &rhs)
Buffer getDownSample(uint32 n) const
Returns a copy of this Buffer downsampled by a integral factor. N must be > 1.
Buffer getZNorm() const
Returns a Z score normalized copy of the Buffer.
std::vector< float64 > FloatVector
Buffer getSignalEnergy(uint32 window_size) const
Returns the signal energy: E = 1 / N * sum(|x(i)|) over the window of N samples.
void log10()
Sets each sample in the Buffer to log base 10.
void preallocate(uint32 n)
Preallocates memory to hold an additional n samples.
void downSample(uint32 n)
Downsample this Buffer by a integral factor. N must be > 1.
static Buffer zeros(const uint32 n_samples)
Returns a Buffer full of zeros of length n_samples.
Buffer & operator/=(const Buffer &rhs)
Divides each sample in this Buffer with the right hand side (rhs) Buffer.
BufferSelection operator()(const BooleanVector &bv)
Returns a BufferSelection object used for manipulation of a selected region of samples.
const_circular_iterator cbegin() const
Retruns the itreator at the start of the Buffer.
Buffer & operator=(const Buffer &rhs)
The assignment operator. C++ only, for Python, use the copy constructor.
void plot(const std::string &title="Buffer") const
Requires matplotlib. Creates a plot of this Buffer.
static const uint32 bytes_per_sample_
A circulator iterator for class Buffer.
float64 getMean() const
Returns the mean sample value in the Buffer.
std::istream & read(std::istream &stream_in)
Constructs a Buffer from seralized data in the inputstream.
void limit(float64 min, float64 max)
Limits the Buffer to min and max.
void _swig_shadow()
SWIG helper function function to shadow.
void resample(float64 factor)
Resamples this Buffer using discrete-time resampling.
Buffer getLog10() const
Returns the the Buffer where each sample is the natural log.
std::vector< Buffer * > BufferPointerVector
AudioStream operator*(const AudioStream &lhs, const AudioStream &rhs)
const float64 & operator[](uint32 index) const
Returns a const reference into the Buffer.
Buffer getAbs() const
Modifies a copy of the Buffer by making any negative value positive.
Buffer getDerivative(uint32 n) const
Returns the nth derivative of the Buffer.
void writeWavefile(const char *filename) const
Writes the Buffer to a Wavefile.
float64 & operator[](uint32 index)
Retruns a reference into the Buffer.
circular_iterator cbegin()
Retruns the itreator at the start of the Buffer.
float64 getMaxMagnitude() const
Returns the maximum magnitude value in the Buffer, i.e. max(abs(samples)).
void _set_at_index(int32 index, float64 x)
SWIG helper function function to shadow.
uint32 getLength() const
Returns the number of samples in the Buffer.
Buffer getExp() const
Each sample in the Buffer becomes the power e^x.
void convolve(const Buffer &H)
Convolves the Buffer with another Buffer.
iterator end()
Retruns the itreator at the end of the Buffer.
Buffer getRound() const
Rounds the samples in a copy of this Buffer to the nearest integer value.
Nsound::const_circular_iterator const_circular_iterator
FloatVector::const_iterator const_iterator
void zNorm()
Normalized the Buffer using Z score normalizing.
std::vector< Buffer > BufferVector
std::string write() const
void smooth(uint32 n_passes, uint32 n_samples_per_average)
Applies a moving average filter to smooth this Buffer.
iterator begin()
Retruns the itreator at the start of the Buffer.
BooleanVector operator<(float64 rhs)
Creates a BooleanVector where each value is true iff Buffer[n] < rhs.
static Buffer ones(const uint32 n_samples)
Returns a Buffer full of ones of length n_samples.
void speedUp(float64 step_size)
Resamples this Buffer by the step_size, no interpolation.
void reverse()
Reverses the samples in this Buffer.
void normalize()
Multiplies the Buffer by a constant gain so the peak sample has magnitude 1.0.
Buffer getLimit(const Buffer &min, const Buffer &max) const
Returns a copy of the Buffer with min and max limits.
std::vector< uint32 > Uint32Vector
static Buffer rand(const uint32 n_samples)
Returns a Buffer full of random values of length n_samples.
void exp()
Each sample in the Buffer becomes the power e^x.
Buffer & operator^=(const Buffer &powers)
Each sample in the Buffer becomes the power x^n.
const float64 * getPointer() const
Returns the raw point to the first sample in the Buffer.
uint32 argmin() const
Retruns the index of the minimum value in the Buffer.
Buffer & operator*=(const Buffer &rhs)
Multiplies each sample from the right hand side (rhs) with this Buffer.
void abs()
Modifies the Buffer by making any negative value positive.
Nsound::circular_iterator circular_iterator
Buffer getLog() const
Returns the the Buffer where each sample is the natural log.
BufferSelection select(const uint32 start_index, const uint32 stop_index)
Returns a BufferSelection for the range of indicies.
float64 getSum() const
Returns the sum of all samples.
void sqrt()
Takes the square root of each sample in this Buffer.
A Buffer for storing audio samples.
Buffer getUpSample(uint32 n) const
Upsample a copy of this Buffer by a integral factor. N must be > 1.
BooleanVector operator<=(float64 rhs)
Creates a BooleanVector where each value is true iff Buffer[n] <= rhs.
std::vector< boolean > BooleanVector
float64 getMin() const
Returns the minimum sample value in the Buffer.
void round()
Rounds the samples in this Buffer to the nearest integer value.
Buffer _get_resample(const uint32 L, const uint32 M, const uint32 N, float64 beta) const
Buffer getNormalize() const
Returns a copy of the Buffer normalized.
Buffer getResample(float64 factor, const uint32 N=10, float64 beta=5.0) const
Resamples a copy of this Buffer using discrete-time resampling.
Buffer getSqrt() const
Taks the square root of each sample in a copy of this Buffer.
uint32 getNBytes() const
Retruns the number of bytes held in the Buffer array.
Buffer & operator-=(const Buffer &rhs)
Subracts each sample from the right hand side (rhs) Buffer from this Buffer.
void upSample(uint32 n)
Upsample this Buffer by a integral factor. N must be > 1.
FloatVector::iterator iterator
const_iterator end() const
Retruns the itreator at the end of the Buffer.
float64 getMax() const
Returns the maximum sample value in the Buffer.
Buffer & operator+=(const Buffer &rhs)
Adds each sample from the right hand side (rhs) Buffer with this Buffer.
void add(const Buffer &buffer, uint32 offset=0, uint32 n_samples=0)
This method adds buffer to *this.
Buffer getReverse() const
Reverses the samples in a copy of this Buffer.
BooleanVector operator>=(float64 rhs)
Creates a BooleanVector where each value is true iff Buffer[n] >= rhs.
~Buffer()
Destroys the Buffer.
Uint32Vector findPeaks(uint32 window_size=0, float64 min_height=0.0) const
Find the peaks in the Buffer and return a vector of indicies.
BooleanVector operator>(float64 rhs)
Creates a BooleanVector where each value is true iff Buffer[n] > rhs.
A helper class for advance operators.
Buffer & operator<<(const AudioStream &rhs)
Concatenates Buffers and AudioStreams together.
Buffer getdB() const
Returns the Buffer in dB.
void derivative(uint32 n)
Calculates the nth derivative of the Buffer.
uint32 argmax() const
Retruns the index of the maximum value in the Buffer.
void mul(const Buffer &buffer, uint32 offset=0, uint32 n_samples=0)
This method multiplies a Buffer to *this over a sub range.
void log()
Sets each sample in the Buffer to the natural log.