33 #ifndef _NSOUND_AUDIO_STREAM_H_
34 #define _NSOUND_AUDIO_STREAM_H_
62 uint32 n_samples_pre_allocate = 4096);
125 float64 duration_seconds = 0.0);
389 plot(
const std::string & title =
"AudioStream")
const;
459 write(std::ostream & out)
const;
469 read(std::istream & stream_in);
472 read(
const std::string & string_in);
496 {
AudioStream temp(*
this); temp.
smooth(n_passes, n_samples_per_average);
return temp;};
743 temp[i] = d / rhs[i];
AudioStream getPan(const Buffer &pan) const
Sets the amplitude level left vs right.
AudioStream getPad(float64 fill=0.0) const
void speedUp(float32 step_size)
Resamples the AudioStream by the step_size, no interpolation.
BooleanVectorVector operator>(float64 rhs)
AudioStream operator-(const AudioStream &lhs, const AudioStream &rhs)
AudioStream getdB() const
Returns the AudioStream in dB.
float64 getDuration() const
Returns the number of seconds of audio data in the stream.
void downSample(uint32 n)
Downsample by a integral factor. N must be > 1.
AudioStream getSqrt() const
Returns an AudioStream after taking the square root of each sample.
AudioStream getNormalize() const
Returns the normalized AudioStream.
boolean operator!=(const AudioStream &rhs) const
Boolean != operator.
float64 getMin() const
Returns the minimum sample value in the AudioStream.
AudioStream operator+(const AudioStream &lhs, const AudioStream &rhs)
AudioStream & operator*=(const AudioStream &rhs)
float64 getSampleRate() const
Returns the sample rate of the stream.
void readWavefile(const char *filename)
Read a Wavefile.
AudioStream operator/(const AudioStream &lhs, const AudioStream &rhs)
AudioStream getTranspose() const
Retuns a copy of the AudioStream transposed.
AudioStream operator^(const AudioStream &lhs, const AudioStream &rhs)
AudioStream getLimit(const Buffer &min, const Buffer &max) const
Limits the AudioStream the min and max values.
AudioStreamSelection operator()(const BooleanVectorVector &bv)
Returns an AudioStreamSelection object used for manipulation of a selected region of samples...
std::istream & read(std::istream &stream_in)
Constructs an AudioStream from seralized data in the inputstream.
AudioStream getDownSample(uint32 n) const
Downsample by a integral factor. N must be > 1.
uint32 getLength() const
Returns the number of samples of audio data in the stream.
std::string write() const
AudioStreamSelection select(const uint32 start_index, const uint32 stop_index)
Returns an AudioStreamSelection for the range of indicies.
AudioStream & operator+=(const AudioStream &rhs)
void reverse()
Reverses the AudioStream.
std::vector< Buffer * > buffers_
AudioStream & operator^=(const AudioStream &rhs)
BooleanVectorVector operator<(float64 rhs)
void _swig_shadow()
SWIG helper function function to shadow.
AudioStream operator*(const AudioStream &lhs, const AudioStream &rhs)
AudioStream substream(uint32 start_index, uint32 n_samples=0) const
float64 getMax() const
Returns the maximum sample value in the Audiostream.
void upSample(uint32 n)
Upsample by a integral factor. N must be > 1.
void convolve(const Buffer &b)
Convolves every channel in the AudioStream with the Buffer.
void setNChannels(uint32 channels)
void normalize()
Multiplies the AudioStream by a constant gain so the peak sample has magnitude 1.0.
BooleanVectorVector operator<=(float64 rhs)
~AudioStream()
Destructor.
AudioStream & operator-=(const AudioStream &rhs)
uint32 getNChannels(void) const
Returns the number of audio channels in the stream.
AudioStream getConvolve(const Buffer &b) const
Convolves every channel in the AudioStream with the Buffer.
void plot(const std::string &title="AudioStream") const
void mono()
Collapses all channels into one Buffer making it mono.
const Buffer & operator[](uint32 index) const
These methods provide a reference to the Buffer object held in the channel.
void writeWavefile(const char *filename) const
Write the AudioStream to a Wavefile.
AudioStream getResample2(float64 new_sample_rate) const
Resample to the specified sample rate.
AudioStream getPan(float64 pan) const
Sets the amplitude level left vs right.
std::vector< std::vector< boolean > > BooleanVectorVector
AudioStream getLimit(float64 min, float64 max) const
Limits the AudioStream the min and max values.
void derivative(uint32 n)
Calculates the nth derivative of the AudioStream.
void _set_at_index(int32 i, const Buffer &)
SWIG helper function.
void resample2(float64 new_sample_rate)
Resample to the specified sample rate.
AudioStream & operator/=(const AudioStream &rhs)
AudioStream & operator<<(const AudioStream &rhs)
Concatenates or appends rhs to the AudioStream.
AudioStream getSpeedUp(float32 step_size) const
Resamples the AudioStream by the step_size, no interpolation.
void transpose()
Treating the AudioStream as a matrix, this peforms a matrix transpose.
void dB()
Modifies the AudioStream so each sample is converted to dB, 20 * log10(sample).
A Buffer for storing audio samples.
static AudioStream rand(float64 sample_rate, const uint32 n_channels, float64 duration)
Returns a Buffer full of random values of length n_samples.
boolean operator==(const AudioStream &rhs) const
Boolean == operator.
static AudioStream ones(float64 sample_rate, const uint32 n_channels, float64 duration)
Returns an AudioStream full of ones of duration seconds.
void limit(float64 min, float64 max)
Limits the AudioStream the min and max values.
void add(const AudioStream &as, uint32 offset, uint32 n_samples=0)
This method adds the passed AudioStream to this AudioStream.
AudioStream getMono() const
Collapses all channels into one Buffer making it mono.
void pan(float64 pan)
Sets the amplitude level left vs right.
static AudioStream zeros(float64 sample_rate, const uint32 n_channels, float64 duration)
Returns a Buffer full of zeros of length n_samples.
AudioStream getUpSample(uint32 n) const
Upsample by a integral factor. N must be > 1.
void abs()
This method calls abs on all buffers held in the stream.
AudioStream getResample(const Buffer &factor) const
Resample by a dynamic non-integer factor.
AudioStream getAbs() const
Modifies the AudioStream by making any negative value positive.
AudioStream getReverse() const
Reverses the samples in the AudioStream.
A helper class for advance operators.
BooleanVectorVector operator>=(float64 rhs)
void setSampleRate(uint32 sample_rate)
AudioStream getResample(float64 factor) const
Resample by a non-integer factor.
void smooth(uint32 n_passes, uint32 n_samples_per_average)
Implements a standard moving average filter to smooth the waveform.
AudioStream getSpeedUp(const Buffer &step_size) const
Resamples the AudioStream by a variable step_size, no interpolation.
void sqrt()
Takes the square root of each sample in the AudioStream.
AudioStream getSmooth(uint32 n_passes, uint32 n_samples_per_average) const
Implements a standard moving average filter to smooth the waveform.
AudioStream()
Create an AudioStream.
void resample(float64 factor)
Resample by a non-integer factor.
float64 getMaxMagnitude() const
Returns the maximum sample magnitude value in the AudioStream, i.e. max(abs(samples))..
AudioStream getDerivative(uint32 n) const
Returns the nth derivative of the Buffer.
void pad(float64 fill=0.0)
Pads the AudioStream so that each channel has exactly the same number of samples. ...
AudioStream & operator=(const AudioStream &rhs)
Assignment operator.