#include <Nsound/Buffer.h>
Classes | |
| class | circular_iterator |
Public Types | |
| typedef FloatVector::iterator | iterator |
| typedef FloatVector::const_iterator | const_iterator |
Public Member Functions | |
| Buffer () | |
| Buffer (uint32 chunk_size) | |
| Buffer (const FloatVector &list) | |
| Buffer (const std::string &filename, uint32 chunk_size=4096) | |
| ~Buffer () | |
| Buffer (const Buffer &rhs) | |
| void | abs () |
| Buffer | getAbs () const |
| void | add (const Buffer &buffer, uint32 offset=0, uint32 n_samples=0) |
| This method adds buffer to *this. | |
| uint32 | argmax () const |
| uint32 | argmin () const |
| iterator | begin () |
| const_iterator | begin () const |
| circular_iterator | cbegin () |
| circular_iterator | cbegin () const |
| iterator | end () |
| const_iterator | end () const |
| uint32 | getNBytes () const |
| void | exp () |
| Buffer | getExp () const |
| void | convolve (const Buffer &H) |
| Buffer | getConvolve (const Buffer &H) const |
| void | dB () |
| Buffer | getdB () const |
| void | derivative (uint32 n) |
| Buffer | getDerivative (uint32 n) const |
| void | downSample (uint32 n) |
| Buffer | getDownSample (uint32 n) const |
| Uint32Vector | findPeaks (uint32 window_size=0, const float64 &min_height=0.0) const |
| uint32 | getLength () const |
| void | limit (const float64 &min, const float64 &max) |
| void | limit (const Buffer &min, const Buffer &max) |
| Buffer | getLimit (const float64 &min, const float64 &max) const |
| Buffer | getLimit (const Buffer &min, const Buffer &max) const |
| void | log () |
| Buffer | getLog () const |
| void | log10 () |
| Buffer | getLog10 () const |
| float64 | getMax () const |
| float64 | getMaxMagnitude () const |
| float64 | getMean () const |
| float64 | getMin () const |
| void | normalize () |
| Buffer | getNormalize () const |
| Buffer | getSignalEnergy (uint32 window_size) const |
| float64 | getStd () const |
| float64 | getSum () const |
| void | zNorm () |
| Buffer | getZNorm () const |
| BufferSelection | operator() (const BooleanVector &bv) |
| Buffer & | operator= (const Buffer &rhs) |
| boolean | operator== (const Buffer &rhs) const |
| boolean | operator!= (const Buffer &rhs) const |
| const float64 | operator[] (uint32 index) const |
| float64 & | operator[] (uint32 index) |
| Buffer & | operator<< (const AudioStream &rhs) |
| Buffer & | operator<< (const Buffer &rhs) |
| Buffer & | operator<<= (const Buffer &rhs) |
| Buffer & | operator<< (const float64 &d) |
| Buffer & | operator<<= (const float64 &d) |
| Buffer & | operator+= (const Buffer &rhs) |
| Buffer & | operator-= (const Buffer &rhs) |
| Buffer & | operator*= (const Buffer &rhs) |
| Buffer & | operator/= (const Buffer &rhs) |
| Buffer & | operator^= (const Buffer &powers) |
| Buffer & | operator+= (const float64 &d) |
| Buffer & | operator-= (const float64 &d) |
| Buffer & | operator*= (const float64 &d) |
| Buffer & | operator/= (const float64 &d) |
| Buffer & | operator^= (const float64 &power) |
| BooleanVector | operator> (const float64 &rhs) |
| BooleanVector | operator>= (const float64 &rhs) |
| BooleanVector | operator< (const float64 &rhs) |
| BooleanVector | operator<= (const float64 &rhs) |
| BooleanVector | operator== (const float64 &rhs) |
| BooleanVector | operator!= (const float64 &rhs) |
| void | plot (const std::string &title="Buffer") const |
| const float64 * | getPointer () const |
| float64 * | getPointer () |
| void | preallocate (uint32 n) |
| void | readWavefile (const char *filename) |
| void | resample (const float64 &factor) |
| void | resample (const Buffer &factor) |
| Buffer | getResample (const float64 &factor, const uint32 N=10, const float64 &beta=5.0) const |
| Buffer | getResample (const Buffer &factor, const uint32 N=10, const float64 &beta=5.0) const |
| Buffer | getResample (const uint32 L, const uint32 M, const uint32 N=10, const float64 &beta=5.0) const |
| void | reverse () |
| Buffer | getReverse () const |
| void | round () |
| Buffer | getRound () const |
| BufferSelection | select (const uint32 start_index, const uint32 stop_index) |
| void | smooth (uint32 n_passes, uint32 n_samples_per_average) |
| Buffer | getSmooth (uint32 n_passes, uint32 n_samples_per_average) const |
| void | speedUp (const float64 &step_size) |
| Buffer | getSpeedUp (const float64 &step_size) const |
| void | speedUp (const Buffer &step_size) |
| Buffer | getSpeedUp (const Buffer &step_size) const |
| void | sqrt () |
| Buffer | getSqrt () const |
| Buffer | subbuffer (uint32 start_index, uint32 n_samples=0) const |
| void | upSample (uint32 n) |
| Buffer | getUpSample (uint32 n) const |
| void | writeWavefile (const char *filename) const |
| float64 | get_at_index (int32 index) const |
| SWIG helper function for operator[]. | |
| void | set_at_index (int32 index, const float64 &d) |
| SWIG helper function for operator[]. | |
| void | swig_hook () |
| SWIG helper function function to shadow. | |
Static Public Member Functions | |
| static Buffer | ones (const uint32 n_samples) |
| Returns a Buffer full of ones of length n_samples. | |
| static Buffer | rand (const uint32 n_samples) |
| Returns a Buffer full of random values of length n_samples. | |
| static Buffer | zeros (const uint32 n_samples) |
| Returns a Buffer full of zeros of length n_samples. | |
Protected Types | |
| enum | MathOperator { ADD, SUBTRACT, MULTIPLY, DIVIDE, POW } |
Protected Member Functions | |
| Buffer | getResample_ (const uint32 L, const uint32 M, const uint32 N, const float64 &beta) const |
| Buffer & | vectorOperator (const Buffer &rhs, MathOperator op) |
| Buffer & | scalarOperator (const float64 &d, MathOperator op) |
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) |
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.
Definition at line 61 of file Buffer.h.
| typedef FloatVector::iterator Nsound::Buffer::iterator |
| typedef FloatVector::const_iterator Nsound::Buffer::const_iterator |
enum Nsound::Buffer::MathOperator [protected] |
| Buffer::Buffer | ( | ) |
Creates an empty Buffer that also calss std::vector::reserve() to preallocate memory for samples.
| chunk_size | the number of samples to preallocate. |
Definition at line 59 of file Buffer.cc.
References data_.
Referenced by operator<<().
| Buffer::Buffer | ( | uint32 | chunk_size | ) | [explicit] |
| Buffer::Buffer | ( | const FloatVector & | list | ) | [explicit] |
Creates a Buffer and fills it with the contents of list.
| list | a FloatVector holding samples |
// C++ FloatVector fv; fv.push_back(1.0); fv.push_back(2.0); fv.push_back(3.0); fv.push_back(4.0); fv.push_back(5.0); Buffer b(fv); // Python b = Buffer([1,2,3,4,5])
Definition at line 77 of file Buffer.cc.
00079 : 00080 data_(list) // Copies contents 00081 { }
| Buffer::Buffer | ( | const std::string & | filename, | |
| uint32 | chunk_size = 4096 | |||
| ) |
| Buffer::Buffer | ( | const Buffer & | rhs | ) |
Copy constructor, must be used in Python to copy Buffers.
| void Buffer::abs | ( | ) |
Modifies the Buffer by making any negative value positive.
Definition at line 112 of file Buffer.cc.
References data_.
Referenced by Nsound::AudioStream::abs(), Buffer_UnitTest(), DelayLine_UnitTest(), FFTransform_UnitTest(), FilterCombLowPassFeedback_UnitTest(), FilterLeastSquaresFIR_UnitTest(), FilterParametricEqualizer_UnitTest(), Generator_UnitTest(), getAbs(), main(), Sine_UnitTest(), and Triangle_UnitTest().
| Buffer Nsound::Buffer::getAbs | ( | ) | const [inline] |
Modifies a copy of the Buffer by making any negative value positive.
Definition at line 176 of file Buffer.h.
References abs().
Referenced by Buffer_UnitTest(), BufferResample_UnitTest(), FFTransform_UnitTest(), FilterBandPassFIR_UnitTest(), FilterBandPassIIR_UnitTest(), FilterBandRejectFIR_UnitTest(), FilterBandRejectIIR_UnitTest(), FilterHighPassFIR_UnitTest(), FilterHighPassIIR_UnitTest(), FilterLeastSquaresFIR_UnitTest(), FilterLowPassFIR_UnitTest(), FilterLowPassIIR_UnitTest(), and main().
00177 { Buffer temp(*this); temp.abs(); return temp; };
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 220 of file Buffer.cc.
References data_, and getLength().
Referenced by Nsound::AudioStream::add(), Nsound::Granulator::generate(), main(), Nsound::Stretcher::overlapAdd(), and testBufferAdd().
00223 { 00224 uint32 a_length = getLength(); 00225 uint32 b_length = b.getLength(); 00226 00228 // Case 1: n_samples == 0 00229 // && a_length < offset 00230 // 00231 // [aaaaaaa] 00232 // + |--offset--|[bbbbbbbbbbbbbbbbbbbbbb] 00233 // result = |aaaaaaaa---bbbbbbbbbbbbbbbbbbbbbbb| 00235 if(n_samples == 0 && a_length < offset) 00236 { 00237 // Append zeros 00238 for(uint32 i = a_length; i < offset; ++i) 00239 { 00240 *this << 0.0; 00241 } 00242 00243 // Append b 00244 *this << b; 00245 } 00246 00248 // Case 2: n_samples != 0 00249 // && a_length < offset 00250 // && n_samples <= b_length 00251 // 00252 // [aaaaaaa] 00253 // + |--offset--|[bbbbbbbbbbbbbbbbbbbbbb] 00254 // |---n_samples---| 00255 // result = |aaaaaaaa---bbbbbbbbbbbbbbbb| 00257 else if(n_samples != 0 00258 && a_length < offset 00259 && n_samples <= b_length) 00260 { 00261 // Append zeros 00262 for(uint32 i = a_length; i < offset; ++i) 00263 { 00264 *this << 0.0; 00265 } 00266 00267 for(uint32 i = 0; i < n_samples; ++i) 00268 { 00269 *this << b[i]; 00270 } 00271 } 00272 00274 // Case 3: n_samples != 0 00275 // && a_length < offset 00276 // && n_samples > b_length 00277 // 00278 // [aaaaaaa] 00279 // + |--offset--|[bbbbbbbbbbbbbbbbbbbbbb] 00280 // |---n_samples----------------| 00281 // result = |aaaaaaaa---bbbbbbbbbbbbbbbbbbbbbbbb-----| 00283 else if(n_samples != 0 00284 && a_length < offset 00285 && n_samples > b_length) 00286 { 00287 // Append zeros 00288 for(uint32 i = a_length; i < offset; ++i) 00289 { 00290 *this << 0.0; 00291 } 00292 00293 // Append b samples 00294 00295 *this << b; 00296 00297 // Append zeros 00298 00299 for(uint32 i = b_length; i < n_samples; ++i) 00300 { 00301 *this << 0.0; 00302 } 00303 } 00304 00306 // Case 4: n_samples == 0 00307 // && a_length >= offset 00308 // && a_length < offset + b_length 00309 // 00310 // [aaaaaaaaaaaaaaaaaaaaaaaaaaaa] 00311 // + |--offset--|[bbbbbbbbbbbbbbbbbbbbbb] 00312 // result = |aaaaaaaaaaaccccccccccccccccccbbbbb| 00314 else if(n_samples == 0 00315 && a_length >= offset 00316 && a_length < offset + b_length) 00317 { 00318 uint32 b_index = 0; 00319 for(uint32 i = offset; i < a_length; ++i) 00320 { 00321 data_[i] += b[b_index++]; 00322 } 00323 00324 for(uint32 i = b_index; i < b_length; ++i) 00325 { 00326 *this << b[i]; 00327 } 00328 } 00329 00331 // Case 5: n_samples != 0 00332 // && a_length >= offset 00333 // && n_samples <= b_length 00334 // && a_length <= offset + n_samples 00335 // 00336 // [aaaaaaaaaaaaaaaaaaaa] 00337 // + |--offset--|[bbbbbbbbbbbbbbbbbbbbbb] 00338 // |----n_samples----| 00339 // result = |aaaaaaaaaacccccccccccbbbbbbb| 00341 else if(n_samples != 0 00342 && a_length >= offset 00343 && a_length <= offset + n_samples 00344 && n_samples <= b_length) 00345 { 00346 uint32 b_index = 0; 00347 for(uint32 i = offset; i < a_length; ++i) 00348 { 00349 data_[i] += b[b_index++]; 00350 } 00351 00352 for(uint32 i = b_index; i < n_samples; ++i) 00353 { 00354 *this << b[i]; 00355 } 00356 } 00358 // Case 6: n_samples != 0 00359 // && a_length >= offset 00360 // && n_samples < b_length 00361 // && a_length > offset + n_samples 00362 // 00363 // [aaaaaaaaaaaaaaaaaaaaaaaaaaaa] 00364 // + |--offset--|[bbbbbbbbbbbbbbbbbbbbbb] 00365 // |--n_samples--| 00366 // result = |aaaaaaaaaacccccccccccccccaaa| 00368 else if(n_samples != 0 00369 && a_length >= offset 00370 && a_length > offset + n_samples 00371 && n_samples < b_length) 00372 { 00373 uint32 b_index = 0; 00374 for(uint32 i = offset; i < offset + n_samples; ++i) 00375 { 00376 data_[i] += b[b_index++]; 00377 } 00378 } 00379 00381 // Case 7: a_length >= offset 00382 // && n_samples > b_length 00383 // && a_length <= offset + b_length 00384 // 00385 // [aaaaaaaaaaaaaaaaaaaa] 00386 // + |--offset--|[bbbbbbbbbbbbbbbbbbbbbb] 00387 // |----n_samples---------------| 00388 // result = |aaaaaaaaaaaccccccccccbbbbbbbbbbbbbb----| 00390 else if(a_length >= offset 00391 && a_length <= offset + b_length 00392 && n_samples > b_length) 00393 { 00394 uint32 b_index = 0; 00395 for(uint32 i = offset; i < a_length; ++i) 00396 { 00397 data_[i] += b[b_index++]; 00398 } 00399 00400 for(uint32 i = b_index; i < b_length; ++i) 00401 { 00402 *this << b[i]; 00403 } 00404 00405 for(uint32 i = b_length; i < n_samples; ++i) 00406 { 00407 *this << 0.0; 00408 } 00409 } 00411 // Case 8: n_samples == 0 00412 // && a_length >= offset + b_length 00413 // 00414 // [aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa] 00415 // + |--offset--|[bbbbbbbbbbbbbbbbbbbbbb] 00416 // result = |aaaaaaaaaaaccccccccccccccccccccccccaaaaaa| 00418 else if(n_samples == 0 00419 && a_length >= offset + b_length) 00420 { 00421 uint32 b_index = 0; 00422 for(uint32 i = offset; i < offset + b_length; ++i) 00423 { 00424 data_[i] += b[b_index++]; 00425 } 00426 } 00427 00429 // Case 9: a_length >= offset + n_samples 00430 // && n_samples >= b_length 00431 // 00432 // result = [aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa] 00433 // + |--offset--|[bbbbbbbbbbbbbbbbbbbbb] 00434 // |----n_samples------------| 00435 // = |aaaaaaaaaaaacccccccccccccccccccccaaaaaaaa| 00437 else if( a_length >= offset + n_samples 00438 && n_samples >= b_length) 00439 { 00440 uint32 b_index = 0; 00441 for(uint32 i = offset; i < offset + b_length; ++i) 00442 { 00443 data_[i] += b[b_index++]; 00444 } 00445 } 00447 // Case 10: n_samples != 0 00448 // && a_length > offset + b_length 00449 // && a_length < offset + n_samples 00450 // 00451 // result = [aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa] 00452 // + |--offset--|[bbbbbbbbbbbbbbbbbbbbb] 00453 // |----n_samples----------------------| 00454 // = |aaaaaaaaaaaccccccccccccccccccccccaaaaaaa------| 00456 else if(n_samples != 0 00457 && a_length > offset + b_length 00458 && a_length < offset + n_samples) 00459 { 00460 uint32 b_index = 0; 00461 for(uint32 i = offset; i < offset + b_length; ++i) 00462 { 00463 data_[i] += b[b_index++]; 00464 } 00465 00466 for(uint32 i = a_length; i < offset + n_samples; ++i) 00467 { 00468 *this << 0.0; 00469 } 00470 } 00471 }
| uint32 Buffer::argmax | ( | ) | const |
Retruns the index of the maximum value in the Buffer.
Definition at line 476 of file Buffer.cc.
References begin(), and end().
Referenced by main().
00477 { 00478 uint32 index = 0; 00479 00480 Buffer::const_iterator itor = begin(); 00481 Buffer::const_iterator tend = end(); 00482 00483 float64 max = *itor; 00484 00485 uint32 i = 0; 00486 while(itor != tend) 00487 { 00488 if(*itor > max) 00489 { 00490 max = *itor; 00491 index = i; 00492 } 00493 ++i; 00494 ++itor; 00495 } 00496 return index; 00497 }
| uint32 Buffer::argmin | ( | ) | const |
Retruns the index of the minimum value in the Buffer.
Definition at line 502 of file Buffer.cc.
References begin(), and end().
00503 { 00504 uint32 index = 0; 00505 00506 Buffer::const_iterator itor = begin(); 00507 Buffer::const_iterator tend = end(); 00508 00509 float64 min = *itor; 00510 00511 uint32 i = 0; 00512 while(itor != tend) 00513 { 00514 if(*itor < min) 00515 { 00516 min = *itor; 00517 index = i; 00518 } 00519 ++i; 00520 ++itor; 00521 } 00522 return index; 00523 }
| iterator Nsound::Buffer::begin | ( | ) | [inline] |
Retruns the itreator at the start of the Buffer.
// C++ Buffer b1("california.wav"); Buffer::iterator itor = b1.begin(); // Python, you can already iterate over the samples b1 = Buffer("california.wav"); for sample in b1: // do something
Definition at line 291 of file Buffer.h.
References data_.
Referenced by argmax(), argmin(), Nsound::FilterStageIIR::filter(), Nsound::FilterLowPassFIR::filter(), Nsound::FilterHighPassFIR::filter(), Nsound::FilterBandRejectFIR::filter(), Nsound::Filter::filter(), getResample_(), Nsound::FFTransform::ifft(), limit(), operator!=(), Nsound::BufferSelection::operator*=(), Nsound::BufferSelection::operator+=(), Nsound::BufferSelection::operator-=(), Nsound::BufferSelection::operator/=(), operator<(), operator<=(), Nsound::BufferSelection::operator=(), operator==(), operator>(), operator>=(), round(), smooth(), sqrt(), and vectorOperator().
00292 { return data_.begin(); };
| const_iterator Nsound::Buffer::begin | ( | ) | const [inline] |
| circular_iterator Nsound::Buffer::cbegin | ( | ) | [inline] |
Retruns the itreator at the start of the Buffer.
// C++ Buffer b1("california.wav"); Buffer::circular_iterator ctor = b1.begin(); // Python, currently not supported
Definition at line 326 of file Buffer.h.
References data_.
Referenced by Nsound::Stretcher::analyize(), Buffer_UnitTest(), Nsound::Generator::buzz(), Nsound::Generator::drawSine(), Nsound::Generator::drawSine2(), Nsound::Vocoder::filter(), Nsound::FilterFlanger::filter(), Nsound::FilterBandPassVocoder::filter(), Nsound::Filter::filter(), Nsound::Generator::generate(), Nsound::Generator::generate2(), limit(), and Nsound::GuitarBass::play().
| circular_iterator Nsound::Buffer::cbegin | ( | ) | const [inline] |
| iterator Nsound::Buffer::end | ( | ) | [inline] |
Retruns the itreator at the end of the Buffer.
// C++ Buffer b1("california.wav"); Buffer::iterator end = b1.end(); // Python, currently not supported
Definition at line 358 of file Buffer.h.
References data_.
Referenced by argmax(), argmin(), Nsound::FilterStageIIR::filter(), Nsound::FilterLowPassFIR::filter(), Nsound::FilterHighPassFIR::filter(), Nsound::FilterBandRejectFIR::filter(), Nsound::Filter::filter(), getResample_(), limit(), operator!=(), Nsound::BufferSelection::operator*=(), Nsound::BufferSelection::operator+=(), Nsound::BufferSelection::operator-=(), Nsound::BufferSelection::operator/=(), operator<(), operator<<(), operator<=(), Nsound::BufferSelection::operator=(), operator==(), operator>(), operator>=(), round(), scalarOperator(), smooth(), sqrt(), and vectorOperator().
00359 { return data_.end(); };
| const_iterator Nsound::Buffer::end | ( | ) | const [inline] |
| uint32 Nsound::Buffer::getNBytes | ( | ) | const [inline] |
Retruns the number of bytes held in the Buffer array.
Definition at line 392 of file Buffer.h.
References bytes_per_sample_, and data_.
00393 { return bytes_per_sample_ * data_.size(); };
| void 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 528 of file Buffer.cc.
References data_, and getLength().
Referenced by Nsound::Generator::drawDecay(), Nsound::Generator::drawGaussian(), and getExp().
| Buffer Nsound::Buffer::getExp | ( | ) | const [inline] |
| void Buffer::convolve | ( | const Buffer & | H | ) |
Convolves the Buffer with another Buffer.
| H | another Buffer to convole with. |
Definition at line 539 of file Buffer.cc.
References getConvolve().
Referenced by Nsound::AudioStream::convolve().
00540 { 00541 *this = getConvolve(H); 00542 }
Convolves a copy of the Buffer with another Buffer.
| H | another Buffer to convole with. |
Definition at line 547 of file Buffer.cc.
References getLength().
Referenced by convolve(), and main().
00548 { 00549 // Alocate the output Buffer will all zeros. 00550 Buffer y = *this * 0.0; 00551 00552 // Pad y with H.getLength() samples. 00553 for(uint32 i = 0; i < H.getLength(); ++i) 00554 { 00555 y << 0.0; 00556 } 00557 00558 // For each sample in this Buffer. 00559 for(uint32 i = 0; i < getLength(); ++i) 00560 { 00561 // For each sample in H. 00562 for(uint32 j = 0; j < H.getLength(); ++j) 00563 { 00564 y[i + j] += (*this)[i] * H[j]; 00565 } 00566 } 00567 00568 return y; 00569 }
| void Buffer::dB | ( | ) |
Modifies the Buffer so each sample is converted to dB, 20 * log10(sample).
Definition at line 574 of file Buffer.cc.
References log10().
Referenced by Nsound::AudioStream::dB(), getdB(), and Nsound::FFTChunk::plot().
00575 { 00576 //~ FloatVector::iterator itor = data_.begin(); 00577 //~ FloatVector::iterator end = data_.end(); 00578 00579 //~ while(itor != end) 00580 //~ { 00581 //~ if(*itor == 0.0) 00582 //~ { 00583 //~ *itor = -150.0; 00584 //~ } 00585 //~ else 00586 //~ { 00587 //~ *itor = 20.0 * ::log10(*itor); 00588 //~ } 00589 00590 //~ ++itor; 00591 //~ } 00592 00593 log10(); 00594 *this *= 20.0; 00595 }
| Buffer Nsound::Buffer::getdB | ( | ) | const [inline] |
Returns the Buffer in dB.
Definition at line 505 of file Buffer.h.
References dB().
Referenced by FilterLeastSquaresFIR_UnitTest(), main(), and Nsound::Filter::plot().
00506 { Buffer temp(*this); temp.dB(); return temp; };
| void Buffer::derivative | ( | uint32 | n | ) |
Calculates the nth derivative of the Buffer.
// C++ Buffer b1("california.wav"); b1.derivative(1); // Python b1 = Buffer("california.wav") b1.derivative(1)
Definition at line 600 of file Buffer.cc.
References data_.
Referenced by Nsound::AudioStream::derivative(), and getDerivative().
Returns the nth derivative of the Buffer.
// C++ Buffer b1("california.wav"); Buffer b2 = b1.getDerivative(1); // Python b1 = Buffer("california.wav") b2 = b1.getDerivative(1)
Definition at line 538 of file Buffer.h.
References derivative().
Referenced by Nsound::FilterLeastSquaresFIR::makeKernel().
00539 { Buffer temp(*this); temp.derivative(n); return temp; };
| void Buffer::downSample | ( | uint32 | n | ) |
Downsample this Buffer by a integral factor. N must be > 1.
// C++ Buffer b1("california.wav"); b1.downSample(2); // Python b1 = Buffer("california.wav") b1.downSample(2)
Definition at line 614 of file Buffer.cc.
References getDownSample().
Referenced by Nsound::AudioStream::downSample().
00615 { 00616 *this = getDownSample(n); 00617 }
Returns a copy of this Buffer downsampled by a integral factor. N must be > 1.
// C++ Buffer b1("california.wav"); Buffer b2 = b1.getDownSample(2); // Python b1 = Buffer("california.wav") b2 = b1.getDownSample(2)
Definition at line 625 of file Buffer.cc.
References getResample().
Referenced by downSample().
00626 { 00627 return getResample(static_cast<uint32>(1),M); 00628 }
| Uint32Vector Buffer::findPeaks | ( | uint32 | window_size = 0, |
|
| const float64 & | min_height = 0.0 | |||
| ) | const |
Find the peaks in the Buffer and return a vector of indicies.
// C++ Buffer b1("california.wav"); Uint32Vector v = b1.findPeaks(1000, 0.0); // Python b1 = Buffer("california.wav") peaks = b1.findPeaks(1000, 0.0)
Definition at line 633 of file Buffer.cc.
References data_, and getLength().
Referenced by main().
00636 { 00637 Uint32Vector peaks; 00638 peaks.reserve(128); 00639 00640 uint32 h_window_size = window_size / 2 + 1; // half window size 00641 00642 uint32 n_samples = getLength(); 00643 00644 for(uint32 i = 1; i < n_samples - 1; ++i) 00645 { 00646 boolean is_peak = false; 00647 00648 float64 sample = data_[i]; 00649 00650 if(window_size <= 2) 00651 { 00652 if( sample > data_[i - 1] && 00653 sample > data_[i + 1]) 00654 { 00655 is_peak = true; 00656 } 00657 } 00658 else 00659 { 00660 // Assume it's a peak. 00661 00662 is_peak = true; 00663 00664 for(uint32 j = 1; j < h_window_size; ++j) 00665 { 00666 if(j < i) 00667 { 00668 if(data_[i - j] > sample) 00669 { 00670 is_peak = false; 00671 break; 00672 } 00673 } 00674 00675 if(i + j < n_samples) 00676 { 00677 if(data_[i + j] > sample) 00678 { 00679 is_peak = false; 00680 break; 00681 } 00682 } 00683 } 00684 } 00685 00686 if(is_peak && sample > min_height) 00687 { 00688 peaks.push_back(i); 00689 } 00690 } 00691 00692 return peaks; 00693 }
| uint32 Nsound::Buffer::getLength | ( | ) | const [inline] |
Returns the number of samples in the Buffer.
Definition at line 612 of file Buffer.h.
References data_.
Referenced by add(), Nsound::AdsrEnvelope::AdsrEnvelope(), Nsound::Stretcher::analyize(), Buffer_UnitTest(), BufferResample_UnitTest(), cosinewindow(), Nsound::Generator::ctor(), Nsound::Envelope::ctor(), Nsound::FilterIIR::designKernel(), Nsound::Generator::drawWindowKaiser(), exp(), Nsound::FFTransform::fft(), FFTransform_UnitTest(), Nsound::Vocoder::filter(), Nsound::ReverberationRoom::filter(), Nsound::FilterStageIIR::filter(), Nsound::FilterSlinky::filter(), Nsound::FilterParametricEqualizer::filter(), Nsound::FilterLowPassFIR::filter(), Nsound::FilterFlanger::filter(), Nsound::FilterDC::filter(), Nsound::FilterBandRejectIIR::filter(), Nsound::FilterBandRejectFIR::filter(), Nsound::FilterBandPassVocoder::filter(), Nsound::Filter::filter(), findPeaks(), Nsound::Granulator::generate(), Nsound::Generator::Generator(), get_at_index(), getConvolve(), Nsound::AudioStream::getDuration(), Nsound::FFTChunk::getFrequencyAxis(), Nsound::FFTChunk::getImaginary(), Nsound::AudioStream::getLength(), Nsound::FFTChunk::getMagnitude(), getMean(), Nsound::BufferWindowSearch::getNextWindow(), Nsound::FFTChunk::getPhase(), Nsound::Filter::getPhaseResponse(), Nsound::FFTChunk::getReal(), getResample(), getResample_(), Nsound::FilterIIR::getRMS(), Nsound::BufferWindowSearch::getSamplesLeft(), getSignalEnergy(), getStd(), Nsound::Granulator::Granulator(), Nsound::FFTransform::ifft(), Nsound::Plotter::imagesc(), log(), log10(), main(), Nsound::FilterLeastSquaresFIR::makeKernel(), Nsound::Plotter::makePyListFromBuffer(), Nsound::operator/(), Nsound::operator^(), Nsound::Stretcher::overlapAdd(), Nsound::AudioStream::pad(), Nsound::AudioStream::pan(), Nsound::FluteSlide::play(), Nsound::Clarinet::play(), play_int(), Nsound::Plotter::plot(), Nsound::FFTChunk::plot(), reverse(), Nsound::FilterIIR::savePlot(), select(), set_at_index(), Nsound::Kernel::setA(), Nsound::Kernel::setB(), Nsound::FilterLeastSquaresFIR::setKernel(), Nsound::Envelope::shape(), Nsound::Spectrogram::Spectrogram(), speedUp(), Nsound::Square::Square(), Nsound::Stretcher::Stretcher(), Nsound::Mesh2D::strike(), subbuffer(), testAutioStream(), testBufferAdd(), Nsound::FFTChunk::toCartesian(), Nsound::FFTChunk::toPolar(), Nsound::Triangle::Triangle(), Nsound::Wavefile::write(), and zNorm().
00613 { return data_.size(); };
Limits the Buffer to min and max.
Definition at line 886 of file Buffer.cc.
References begin(), and end().
Referenced by getLimit(), Nsound::AudioStream::limit(), and Nsound::DrumBD01::play().
00887 { 00888 Buffer::iterator itor = this->begin(); 00889 Buffer::iterator end = this->end(); 00890 00891 while(itor != end) 00892 { 00893 float64 s = *itor; 00894 00895 if(s > max) s = max; 00896 if(s < min) s = min; 00897 00898 *itor = s; 00899 00900 ++itor; 00901 } 00902 }
Limits the Buffer to min and max.
// C++ Sine gen(100.0); Buffer b1("california.wav"); Buffer b2 = gen.generate(5.0, 2.0); // 5 seconds at 2 Hz b1.limit(b2, b2 + 1.0); // Python gen = Sine(100.0) b1 = Buffer("california.wav") b2 = Buffer(100) // sets chunk size to 100 b2 << gen.generate(5.0, 2.0) // 5 seconds at 2 Hz b1.limit(b2, b2 + 1.0)
Definition at line 907 of file Buffer.cc.
References begin(), cbegin(), and end().
00908 { 00909 Buffer::circular_iterator imin = min.cbegin(); 00910 Buffer::circular_iterator imax = max.cbegin(); 00911 00912 Buffer::iterator itor = this->begin(); 00913 Buffer::iterator end = this->end(); 00914 00915 while(itor != end) 00916 { 00917 float64 s = *itor; 00918 00919 if(s > *imax) s = *imax; 00920 if(s < *imin) s = *imin; 00921 00922 *itor = s; 00923 00924 ++itor; 00925 ++imax; 00926 ++imin; 00927 } 00928 }
Returns a copy of the Buffer with min and max limits.
// C++ Sine gen(100.0); Buffer b1("california.wav"); Buffer b2 = gen.generate(5.0, 2.0); // 5 seconds at 2 Hz Buffer b3 = b1.getLimit(b2, b2 + 1.0); // Python gen = Sine(100.0) b1 = Buffer("california.wav") b2 = Buffer(100) // sets chunk size to 100 b2 << gen.generate(5.0, 2.0) // 5 seconds at 2 Hz b3 = b1.getLimit(b2, b2 + 1.0)
Definition at line 688 of file Buffer.h.
References limit().
00689 { Buffer temp(*this); temp.limit(min, max); return temp; };
| void Buffer::log | ( | ) |
Sets each sample in the Buffer to the natural log.
Definition at line 935 of file Buffer.cc.
References data_, getLength(), and LM_MAX.
Referenced by getLog(), and Nsound::Vocoder::Vocoder().
| Buffer Nsound::Buffer::getLog | ( | ) | const [inline] |
| void Buffer::log10 | ( | ) |
Sets each sample in the Buffer to log base 10.
Definition at line 949 of file Buffer.cc.
References data_, getLength(), and LM_MAX.
Referenced by dB(), and getLog10().
| Buffer Nsound::Buffer::getLog10 | ( | ) | const [inline] |
| float64 Buffer::getMax | ( | ) | const |
Returns the maximum sample value in the Buffer.
Definition at line 965 of file Buffer.cc.
References data_.
Referenced by Buffer_UnitTest(), BufferResample_UnitTest(), Nsound::Generator::buzz(), DelayLine_UnitTest(), FFTransform_UnitTest(), FilterBandPassFIR_UnitTest(), Nsound::FilterBandPassIIR::FilterBandPassIIR(), FilterBandPassIIR_UnitTest(), FilterBandRejectFIR_UnitTest(), FilterBandRejectIIR_UnitTest(), FilterCombLowPassFeedback_UnitTest(), FilterHighPassFIR_UnitTest(), FilterHighPassIIR_UnitTest(), FilterLeastSquaresFIR_UnitTest(), FilterLowPassFIR_UnitTest(), FilterLowPassIIR_UnitTest(), FilterParametricEqualizer_UnitTest(), Generator_UnitTest(), Nsound::AudioStream::getMax(), main(), Nsound::Plotter::plot(), Nsound::Filter::plot(), Nsound::FilterIIR::savePlot(), Sine_UnitTest(), and Triangle_UnitTest().
| float64 Buffer::getMaxMagnitude | ( | ) | const |
Returns the maximum magnitude value in the Buffer, i.e. max(abs(samples)).
// C++ Buffer b1("california.wav"); float64 max = b1.getMaxMagnitude(); // Python b1 = Buffer("california.wav") m = b1.getMaxMagnitude()
Definition at line 986 of file Buffer.cc.
References data_.
Referenced by Nsound::AudioStream::getMaxMagnitude(), and normalize().
| float64 Buffer::getMean | ( | ) | const |
Returns the mean sample value in the Buffer.
Definition at line 1007 of file Buffer.cc.
References getLength(), and getSum().
Referenced by getResample(), getStd(), main(), and zNorm().
| float64 Buffer::getMin | ( | ) | const |
Returns the minimum sample value in the Buffer.
Definition at line 1017 of file Buffer.cc.
References data_.
Referenced by Buffer_UnitTest(), Nsound::AudioStream::getMin(), Nsound::FilterLeastSquaresFIR::makeKernel(), and Nsound::Plotter::plot().
01018 { 01019 float64 min = data_[0]; 01020 01021 for(const_iterator itor = data_.begin(); 01022 itor != data_.end(); 01023 ++itor) 01024 { 01025 if(*itor < min) 01026 { 01027 min = *itor; 01028 } 01029 } 01030 01031 return min; 01032 }
| void Buffer::normalize | ( | ) |
Multiplies the Buffer by a constant gain so the peak sample has magnitude 1.0.
Definition at line 1037 of file Buffer.cc.
References getMaxMagnitude().
Referenced by Nsound::Generator::drawGaussian(), FilterBandPassFIR_UnitTest(), FilterBandPassIIR_UnitTest(), FilterBandRejectFIR_UnitTest(), FilterBandRejectIIR_UnitTest(), FilterCombLowPassFeedback_UnitTest(), FilterHighPassFIR_UnitTest(), FilterHighPassIIR_UnitTest(), FilterLowPassIIR_UnitTest(), Nsound::Pluck::generate(), getNormalize(), main(), and Nsound::DrumBD01::play().
01038 { 01039 float64 peak = getMaxMagnitude(); 01040 01041 float64 normal_factor = 1.0 / peak; 01042 01043 *this *= normal_factor; 01044 }
| Buffer Nsound::Buffer::getNormalize | ( | ) | const [inline] |
Returns a copy of the Buffer normalized.
// C++ Buffer b1("california.wav"); Buffer b2 = b1.getNormalize(); // Python b1 = Buffer("california.wav") b2 = b1.getNormalize()
Definition at line 851 of file Buffer.h.
References normalize().
00852 { Buffer temp(*this); temp.normalize(); return temp; };
Returns the signal energy: E = 1 / N * sum(|x(i)|) over the window of N samples
// C++ Buffer b1("california.wav"); float64 energy = b1.getSignalEnergy(); // Python b1 = Buffer("california.wav") energy = b1.getSignalEnergy()
Definition at line 1049 of file Buffer.cc.
References data_, and getLength().
01050 { 01051 float64 n = static_cast<float64>(N); 01052 01053 Buffer y; 01054 01055 uint32 length = getLength(); 01056 01057 for(uint32 i = 0; i < length; ++i) 01058 { 01059 float64 sum = 0.0; 01060 01061 for(uint32 j = 0; j < N; ++j) 01062 { 01063 if(i + j < length - 1) 01064 { 01065 sum += ::fabs(data_[i + j]); 01066 } 01067 } 01068 sum /= n; 01069 01070 y << sum; 01071 01072 } 01073 01074 return y; 01075 }
| float64 Buffer::getStd | ( | ) | const |
| float64 Buffer::getSum | ( | ) | const |
Returns the sum of all samples.
Definition at line 1092 of file Buffer.cc.
References data_.
Referenced by getMean(), Nsound::FilterIIR::getRMS(), getStd(), Nsound::Stretcher::searchForBestMatch(), and zNorm().
01093 { 01094 float64 sum = 0.0; 01095 01096 for(const_iterator itor = data_.begin(); 01097 itor != data_.end(); 01098 ++itor) 01099 { 01100 sum += *itor; 01101 } 01102 01103 return sum; 01104 }
| void Buffer::zNorm | ( | ) |
Normalized the Buffer using Z score normalizing. z = (x - mean(x)) / std(x)
Definition at line 1109 of file Buffer.cc.
References getLength(), getMean(), getSum(), and sqrt().
Referenced by getZNorm().
01110 { 01111 // z = (x - mean(x)) / std(x) 01112 01113 // We won't call getStd() to avoid calculatig the diff and mean twice. 01114 01115 // z = (x - mean(x)) / sqrt( sum((x - mean(x))^2) / N) 01116 01117 float64 mean = getMean(); 01118 01119 Buffer diff = *this - mean; 01120 01121 float64 std = (diff*diff).getSum() / static_cast<float64>(getLength()); 01122 01123 std = ::sqrt(std); 01124 01125 *this = diff / (std + 1e-20); 01126 }
| Buffer Nsound::Buffer::getZNorm | ( | ) | const [inline] |
| BufferSelection Buffer::operator() | ( | const BooleanVector & | bv | ) |
Returns a BufferSelection object used for manipulation of a selected region of samples.
Definition at line 1151 of file Buffer.cc.
01152 { 01153 BufferSelection bs(*this, bv); 01154 01155 return bs; 01156 }
The assignment operator. C++ only, for Python, use the copy constructor.
Definition at line 1132 of file Buffer.cc.
References data_.
01133 { 01134 if(this == &rhs_buffer) // If it is the same object, return it. 01135 { 01136 return *this; 01137 } 01138 01139 // Allocate or deallocate BufferChunks as necessary. 01140 01141 data_.clear(); 01142 01143 *this << rhs_buffer; 01144 01145 return *this; 01146 }
| Buffer & Buffer::operator<< | ( | const AudioStream & | rhs | ) |
Concatenates Buffers and AudioStreams together.
Definition at line 1203 of file Buffer.cc.
References Nsound::AudioStream::getMono().
01204 { 01205 (*this) << rhs.getMono()[0]; 01206 01207 return *this; 01208 }
Concatenates Buffers together.
Definition at line 1213 of file Buffer.cc.
References Buffer(), data_, and end().
01214 { 01215 if(this == & rhs_buffer) 01216 { 01217 Buffer * rhs = new Buffer(rhs_buffer); 01218 *this << *rhs; 01219 delete rhs; 01220 01221 return *this; 01222 } 01223 01224 std::vector<float64>::const_iterator itor = rhs_buffer.data_.begin(); 01225 std::vector<float64>::const_iterator end = rhs_buffer.data_.end(); 01226 01227 while(itor != end) 01228 { 01229 data_.push_back(*itor); 01230 ++itor; 01231 } 01232 01233 return *this; 01234 }
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 1251 of file Buffer.cc.
References ADD, and vectorOperator().
01252 { 01253 return vectorOperator(rhs,ADD); 01254 }
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 1257 of file Buffer.cc.
References SUBTRACT, and vectorOperator().
01258 { 01259 return vectorOperator(rhs,SUBTRACT); 01260 }
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 1263 of file Buffer.cc.
References MULTIPLY, and vectorOperator().
01264 { 01265 return vectorOperator(rhs,MULTIPLY); 01266 }
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 1270 of file Buffer.cc.
References DIVIDE, and vectorOperator().
01271 { 01272 return vectorOperator(rhs,DIVIDE); 01273 }
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 1277 of file Buffer.cc.
References POW, and vectorOperator().
01278 { 01279 return vectorOperator(rhs,POW); 01280 }
Adds the sample d to each sample in this Buffer.
Definition at line 1373 of file Buffer.cc.
References ADD, and scalarOperator().
01374 { 01375 return scalarOperator(d,ADD); 01376 }
Subtracts the sample d from each sample in this Buffer.
Definition at line 1380 of file Buffer.cc.
References scalarOperator(), and SUBTRACT.
01381 { 01382 return scalarOperator(d,SUBTRACT); 01383 }
Multiplies the sample d with each sample in this Buffer.
Definition at line 1387 of file Buffer.cc.
References MULTIPLY, and scalarOperator().
01388 { 01389 return scalarOperator(d,MULTIPLY); 01390 }
Divides each sample in this Buffer by d.
Definition at line 1394 of file Buffer.cc.
References DIVIDE, and scalarOperator().
01395 { 01396 return scalarOperator(d,DIVIDE); 01397 }
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.
// C++
mag = real ^ 2 + imag ^ 2;
mag = (real ^ (2 + imag)) ^ 2;
mag = (real ^ 2) + (imag ^ 2);
Definition at line 1401 of file Buffer.cc.
References POW, and scalarOperator().
01402 { 01403 return scalarOperator(d,POW); 01404 }
| BooleanVector Buffer::operator> | ( | const float64 & | rhs | ) |
Creates a BooleanVector where each value is true iff Buffer[n] > rhs.
Definition at line 2408 of file Buffer.cc.
References begin(), and end().
02409 { 02410 BooleanVector bv; 02411 02412 Buffer::const_iterator itor = this->begin(); 02413 Buffer::const_iterator end = this->end(); 02414 02415 while(itor != end) 02416 { 02417 if(*itor > rhs) bv.push_back(true); 02418 else bv.push_back(false); 02419 ++itor; 02420 } 02421 02422 return bv; 02423 }
| BooleanVector Buffer::operator>= | ( | const float64 & | rhs | ) |
Creates a BooleanVector where each value is true iff Buffer[n] >= rhs.
Definition at line 2428 of file Buffer.cc.
References begin(), and end().
02429 { 02430 BooleanVector bv; 02431 02432 Buffer::const_iterator itor = this->begin(); 02433 Buffer::const_iterator end = this->end(); 02434 02435 while(itor != end) 02436 { 02437 if(*itor >= rhs) bv.push_back(true); 02438 else bv.push_back(false); 02439 ++itor; 02440 } 02441 02442 return bv; 02443 }
| BooleanVector Buffer::operator< | ( | const float64 & | rhs | ) |
Creates a BooleanVector where each value is true iff Buffer[n] < rhs.
Definition at line 2448 of file Buffer.cc.
References begin(), and end().
02449 { 02450 BooleanVector bv; 02451 02452 Buffer::const_iterator itor = this->begin(); 02453 Buffer::const_iterator end = this->end(); 02454 02455 while(itor != end) 02456 { 02457 if(*itor < rhs) bv.push_back(true); 02458 else bv.push_back(false); 02459 ++itor; 02460 } 02461 02462 return bv; 02463 }
| BooleanVector Buffer::operator<= | ( | const float64 & | rhs | ) |
Creates a BooleanVector where each value is true iff Buffer[n] <= rhs.
Definition at line 2468 of file Buffer.cc.
References begin(), and end().
02469 { 02470 BooleanVector bv; 02471 02472 Buffer::const_iterator itor = this->begin(); 02473 Buffer::const_iterator end = this->end(); 02474 02475 while(itor != end) 02476 { 02477 if(*itor <= rhs) bv.push_back(true); 02478 else bv.push_back(false); 02479 ++itor; 02480 } 02481 02482 return bv; 02483 }
| BooleanVector Buffer::operator== | ( | const float64 & | rhs | ) |
Creates a BooleanVector where each value is true iff Buffer[n] == rhs.
Definition at line 2488 of file Buffer.cc.
References begin(), and end().
02489 { 02490 BooleanVector bv; 02491 02492 Buffer::const_iterator itor = this->begin(); 02493 Buffer::const_iterator end = this->end(); 02494 02495 while(itor != end) 02496 { 02497 bv.push_back(*itor == rhs); 02498 ++itor; 02499 } 02500 02501 return bv; 02502 }
| BooleanVector Buffer::operator!= | ( | const float64 & | rhs | ) |
Creates a BooleanVector where each value is true iff Buffer[n] != rhs.
Definition at line 2507 of file Buffer.cc.
References begin(), and end().
02508 { 02509 BooleanVector bv; 02510 02511 Buffer::const_iterator itor = this->begin(); 02512 Buffer::const_iterator end = this->end(); 02513 02514 while(itor != end) 02515 { 02516 bv.push_back(*itor != rhs); 02517 ++itor; 02518 } 02519 02520 return bv; 02521 }
| void Buffer::plot | ( | const std::string & | title = "Buffer" |
) | const |
Requires matplotlib. Creates a plot of this Buffer.
// C++ Buffer b1("california.wav"); b1.plot("This is california.wav"); Plotter::show(); // This will render any plots created. // Python b1 = Buffer("california.wav") b1.plot("This is california.wav") Plotter.show()
Definition at line 1683 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(), FilterBandPassFIR_UnitTest(), FilterBandPassIIR_UnitTest(), FilterBandRejectFIR_UnitTest(), FilterBandRejectIIR_UnitTest(), FilterCombLowPassFeedback_UnitTest(), FilterHighPassFIR_UnitTest(), FilterHighPassIIR_UnitTest(), FilterLeastSquaresFIR_UnitTest(), FilterLowPassFIR_UnitTest(), FilterLowPassIIR_UnitTest(), FilterParametricEqualizer_UnitTest(), Generator_UnitTest(), main(), Sine_UnitTest(), testBufferAdd(), and Triangle_UnitTest().
| const float64* Nsound::Buffer::getPointer | ( | ) | const [inline] |
Returns the raw point to the first sample in the Buffer.
// C++ Buffer b1("california.wav"); const flaot64 * ptr = b1.getPointer(); // Python, not supported or needed.
Definition at line 1393 of file Buffer.h.
References data_.
Referenced by Nsound::FilterLeastSquaresFIR::FilterLeastSquaresFIR(), Nsound::FilterLeastSquaresFIR::makeKernel(), Nsound::FilterLeastSquaresFIR::setKernel(), and Nsound::FilterLeastSquaresFIR::setWindow().
01394 { return &(data_[0]); }
| float64* Nsound::Buffer::getPointer | ( | ) | [inline] |
Requires matplotlib. Creates a plot of this Buffer.
// C++ Buffer b1("california.wav"); b1.plot("This is california.wav"); Plotter::show(); // This will render any plots created. // Python, not supported or needed.
Definition at line 1409 of file Buffer.h.
References data_.
01410 { return &(data_[0]); }
| void Buffer::preallocate | ( | uint32 | n | ) |
Preallocates memory to hold an additional n samples. This makes a call to std::vector::reserve( this->getLength() + n).
// C++ Buffer b1("california.wav"); b1.preallocate(100); // Python b1 = Buffer("california.wav") b1.preallocate(100);
Definition at line 1675 of file Buffer.cc.
References data_.
Referenced by Nsound::AudioStream::AudioStream().
| void 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.
// C++ Buffer b1; b1.readWavefile("california.wav"); // Python b1 = Buffer() b1.readWavefile("california.wav")
| void Nsound::Buffer::resample | ( | const float64 & | factor | ) | [inline] |
Resamples this Buffer using discrete-time resampling.
Definition at line 1461 of file Buffer.h.
References getResample().
Referenced by main(), and Nsound::AudioStream::resample().
01462 { *this = getResample(factor, 10, 5.0); };
| void Nsound::Buffer::resample | ( | const Buffer & | factor | ) | [inline] |
Resamples this Buffer using discrete-time resampling.
Definition at line 1483 of file Buffer.h.
References getResample().
01484 { *this = getResample(factor, 10, 5.0); };
| Buffer Buffer::getResample | ( | const float64 & | factor, | |
| const uint32 | N = 10, |
|||
| const float64 & | beta = 5.0 | |||
| ) | const |
Resamples a copy of this Buffer using discrete-time resampling.
// C++ Buffer b1("california.wav"); Buffer b2 = b1.getResample(0.666); // Python b1 = Buffer("california.wav") b2 = b1.getResample(0.666)
Definition at line 1742 of file Buffer.cc.
References find_fraction().
Referenced by BufferResample_UnitTest(), getDownSample(), getResample(), getUpSample(), Nsound::Stretcher::pitchShift(), and resample().
01746 { 01747 uint32 L = 0; 01748 uint32 M = 0; 01749 01750 find_fraction(factor, 0.0001, L, M); 01751 01752 return getResample(L,M,N,beta); 01753 }
| Buffer Buffer::getResample | ( | const Buffer & | factor, | |
| const uint32 | N = 10, |
|||
| const float64 & | beta = 5.0 | |||
| ) | const |
Resamples a copy of this Buffer using discrete-time resampling.
Definition at line 1758 of file Buffer.cc.
References getLength(), getMean(), Nsound::BufferWindowSearch::getNextWindow(), getResample(), Nsound::BufferWindowSearch::getSamplesLeft(), and subbuffer().
01762 { 01763 BufferWindowSearch search(*this, 1024); 01764 01765 uint32 pos = 0; 01766 01767 Buffer y; 01768 01769 while(search.getSamplesLeft() > 0) 01770 { 01771 Buffer window = search.getNextWindow(); 01772 01773 uint32 Lw = window.getLength(); 01774 01775 Buffer ratio = factor.subbuffer(pos, Lw); 01776 01777 float64 r = ratio.getMean(); 01778 01779 y << window.getResample(r,N,beta); 01780 01781 pos += Lw; 01782 } 01783 01784 return y; 01785 }
| Buffer Buffer::getResample | ( | const uint32 | L, | |
| const uint32 | M, | |||
| const uint32 | N = 10, |
|||
| const float64 & | beta = 5.0 | |||
| ) | const |
Resamples a copy of this Buffer using discrete-time resampling.
// C++ Buffer b1("california.wav"); Buffer b2 = b1.getResample(1, 3); // Python b1 = Buffer("california.wav") b2 = b1.getResample(1, 3)
Definition at line 1790 of file Buffer.cc.
References getLength(), Nsound::BufferWindowSearch::getNextWindow(), getResample_(), and Nsound::BufferWindowSearch::getSamplesLeft().
01795 { 01796 Buffer y; 01797 01798 // If the Buffer is really long, break it up into window to reduce memory 01799 // usage. 01800 if(getLength() > 40000) 01801 { 01802 BufferWindowSearch search(*this, 2048); 01803 01804 while(search.getSamplesLeft() > 0) 01805 { 01806 Buffer window = search.getNextWindow(); 01807 01808 y << window.getResample_(L,M,N,beta); 01809 } 01810 } 01811 else 01812 { 01813 y << getResample_(L,M,N,beta); 01814 } 01815 01816 return y; 01817 }
| void Buffer::reverse | ( | ) |
Reverses the samples in this Buffer.
Definition at line 2001 of file Buffer.cc.
References data_, and getLength().
Referenced by Buffer_UnitTest(), getReverse(), and Nsound::AudioStream::reverse().
| Buffer Nsound::Buffer::getReverse | ( | ) | const [inline] |
Reverses the samples in a copy of this Buffer.
// C++ Buffer b1("california.wav"); Buffer b2 = b1.getReverse(); // Python b1 = Buffer("california.wav") b2 = b1.getReverse()
Definition at line 1579 of file Buffer.h.
References reverse().
Referenced by getResample_(), Nsound::Granulator::Granulator(), Nsound::FFTransform::ifft(), Nsound::FilterLeastSquaresFIR::makeKernel(), and Nsound::Stretcher::overlapAdd().
01580 { Buffer temp(*this); temp.reverse(); return temp; };
| void 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 2016 of file Buffer.cc.
References begin(), and end().
Referenced by getRound().
02017 { 02018 for(Buffer::iterator i = this->begin(); 02019 i != this->end(); 02020 ++i) 02021 { 02022 *i = std::floor(*i + 0.5); 02023 } 02024 }
| Buffer Nsound::Buffer::getRound | ( | ) | const [inline] |
| BufferSelection 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 2046 of file Buffer.cc.
References getLength().
02047 { 02048 uint32 n_samples = getLength(); 02049 02050 BooleanVector bv; 02051 02052 bv.reserve(n_samples); 02053 02054 for(uint32 i = 0; i < n_samples; ++i) 02055 { 02056 if( i >= start_index && i <= stop_index) 02057 { 02058 bv.push_back(true); 02059 } 02060 else 02061 { 02062 bv.push_back(false); 02063 } 02064 } 02065 02066 return BufferSelection(*this, bv); 02067 }
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 2072 of file Buffer.cc.
References begin(), end(), and Nsound::FilterMovingAverage::filter().
Referenced by Buffer_UnitTest(), Nsound::Pluck::generate(), getSmooth(), main(), and Nsound::AudioStream::smooth().
02073 { 02074 if(n_samples_to_average < 2) 02075 { 02076 return; 02077 } 02078 02079 FilterMovingAverage maf(n_samples_to_average); 02080 02081 Buffer::iterator end = this->end(); 02082 02083 for(uint32 i = 0; i < n_passes; ++i) 02084 { 02085 Buffer::iterator itor = this->begin(); 02086 02087 while(itor != end) 02088 { 02089 *itor = maf.filter(*itor); 02090 ++itor; 02091 } 02092 } 02093 }
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 1674 of file Buffer.h.
References smooth().
01675 { Buffer temp(*this); temp.smooth(n_passes, n_samples_per_average); return temp; };
| void Buffer::speedUp | ( | const float64 & | step_size | ) |
Resamples this Buffer by the step_size, no interpolation.
Definition at line 2098 of file Buffer.cc.
References data_.
Referenced by getSpeedUp(), and Nsound::AudioStream::speedUp().
Resamples a copy of this Buffer by the step_size, no interpolation.
Definition at line 1711 of file Buffer.h.
References speedUp().
Referenced by Nsound::FFTransform::fft(), and Nsound::Stretcher::pitchShift().
01712 { Buffer temp(*this); temp.speedUp(step_size); return temp; };
| void Buffer::speedUp | ( | const Buffer & | step_size | ) |
Resamples this Buffer on a sample by sample basis, no interpolation.
Definition at line 2115 of file Buffer.cc.
References getLength().
02116 { 02117 Buffer new_buffer; 02118 02119 float32 n_samples = static_cast<float32>(getLength()); 02120 uint32 step_buffer_size = step_buffer.getLength(); 02121 02122 uint32 step_buffer_index = 0; 02123 float32 step_size = 0.0; 02124 02125 for(float32 i = 0.0; i < n_samples; i += step_size) 02126 { 02127 new_buffer << data_[static_cast<uint32>(i)]; 02128 02129 step_size = step_buffer[step_buffer_index++]; 02130 02131 if(step_buffer_index >= step_buffer_size) 02132 { 02133 step_buffer_index -= step_buffer_size; 02134 } 02135 } 02136 02137 *this = new_buffer; 02138 }
| void Buffer::sqrt | ( | ) |
Takes the square root of each sample in this Buffer.
Definition at line 2143 of file Buffer.cc.
References begin(), and end().
Referenced by getSqrt(), getStd(), main(), Nsound::AudioStream::sqrt(), and zNorm().
02144 { 02145 Buffer::iterator itor = this->begin(); 02146 Buffer::iterator end = this->end(); 02147 02148 while(itor != end) 02149 { 02150 float64 v = *itor; 02151 if(v > 0.0) 02152 { 02153 *itor = std::sqrt(v); 02154 } 02155 else if(v < 0.0) 02156 { 02157 *itor = -std::sqrt(-v); 02158 } 02159 ++itor; 02160 } 02161 }
| Buffer Nsound::Buffer::getSqrt | ( | ) | const [inline] |
Slice the Buffer.
Definition at line 2166 of file Buffer.cc.
References data_, and getLength().
Referenced by Buffer_UnitTest(), Nsound::FFTransform::fft(), Nsound::FFTChunk::getImaginary(), Nsound::FFTChunk::getMagnitude(), Nsound::BufferWindowSearch::getNextWindow(), Nsound::FFTChunk::getPhase(), Nsound::Filter::getPhaseResponse(), Nsound::FFTChunk::getReal(), getResample(), getResample_(), Nsound::FFTransform::ifft(), main(), Nsound::FilterLeastSquaresFIR::makeKernel(), Nsound::Stretcher::overlapAdd(), Nsound::FFTChunk::plot(), Nsound::Stretcher::searchForBestMatch(), Nsound::Spectrogram::Spectrogram(), and Nsound::AudioStream::substream().
02167 { 02168 uint32 n = n_samples; 02169 02170 if(n > getLength()) n = getLength(); 02171 02172 Buffer new_buffer(n); 02173 02174 if(start_index >= data_.size()) 02175 return new_buffer; 02176 02177 uint32 stop_index = start_index + n; 02178 02179 if(n == 0 || stop_index >= data_.size()) 02180 { 02181 stop_index = data_.size(); 02182 } 02183 02184 for(uint32 i = start_index; i < stop_index; ++i) 02185 { 02186 new_buffer << data_[i]; 02187 } 02188 02189 return new_buffer; 02190 }
| void Buffer::upSample | ( | uint32 | n | ) |
Upsample this Buffer by a integral factor. N must be > 1.
Definition at line 2195 of file Buffer.cc.
References getUpSample().
Referenced by Nsound::AudioStream::upSample().
02196 { 02197 *this = getUpSample(n); 02198 }
Upsample a copy of this Buffer by a integral factor. N must be > 1.
// C++ Buffer b1("california.wav"); Buffer b2 = b1.getUpSample(2); // Python b1 = Buffer("california.wav") b2 = b1.getUpSample(2)
Definition at line 2206 of file Buffer.cc.
References getResample().
Referenced by upSample().
02207 { 02208 return getResample(L,static_cast<uint32>(1)); 02209 }
| void Buffer::writeWavefile | ( | const char * | filename | ) | const |
Writes the Buffer to a Wavefile.
// C++ Buffer b1("california.wav"); b1.writeWavefile("california_copy.wav"); // Python b1 = Buffer("california.wav") b1.writeWavefile("california_copy.wav")
Definition at line 2214 of file Buffer.cc.
References Nsound::operator>>().
02215 { 02216 02217 if(filename == NULL) return; 02218 02219 Nsound::operator>>(*this, filename); 02220 }
SWIG helper function for operator[].
Definition at line 867 of file Buffer.cc.
References data_, and getLength().
SWIG helper function for operator[].
Definition at line 2029 of file Buffer.cc.
References data_, and getLength().
| void Nsound::Buffer::swig_hook | ( | ) | [inline] |
Returns a Buffer full of zeros of length n_samples.
Definition at line 2554 of file Buffer.cc.
References Nsound::Generator::drawLine().
Referenced by Nsound::Sawtooth::Sawtooth(), and Nsound::Square::Square().
| Buffer Buffer::getResample_ | ( | const uint32 | L, | |
| const uint32 | M, | |||
| const uint32 | N, | |||
| const float64 & | beta | |||
| ) | const [protected] |
Definition at line 1822 of file Buffer.cc.
References begin(), data_, end(), Nsound::FilterLeastSquaresFIR::filter(), Nsound::FilterLeastSquaresFIR::getKernel(), getLength(), getReverse(), Nsound::FilterLeastSquaresFIR::setKernel(), sr, and subbuffer().
Referenced by getResample().
01827 { 01828 //~ cout << "\tL=" << L << "\tM=" << M << endl; 01829 01830 if(L == 1 && M == 1) 01831 { 01832 return *this; 01833 } 01834 01835 if( (L == 0) || 01836 (M == 0) || 01837 (N == 0) || 01838 (beta < 0.0)) 01839 { 01840 cerr << __FILE__ << ":" << __LINE__ 01841 << "::getResample(): bad parameters" 01842 << endl; 01843 01844 return *this; 01845 } 01846 01847 uint32 LMmax = (L > M) ? L : M; 01848 01849 float64 fc = 1.0 / 2.0 / static_cast<float64>(LMmax); 01850 01851 // ensure kernel length is a multiple of L 01852 uint32 Lh = 2 * N * LMmax; 01853 01854 float64 sr = 1000.0; // arbitrary, but usefull if the filter is plotted. 01855 01856 Buffer f(4); 01857 Buffer a(4); 01858 01859 f << 0.0 << sr*fc << sr*fc << sr*0.5; 01860 a << 1.0 << 1.0 << 0.0 << 0.0; 01861 01862 FilterLeastSquaresFIR lpf(sr, Lh, f, a, beta); 01863 01864 uint32 delay = (Lh-1)/2; 01865 01867 // Create Polyphase filter bank if interpolating 01868 std::vector<FilterLeastSquaresFIR> bank; 01869 if(L > 1) 01870 { 01871 // Get the kernel. 01872 Buffer h = lpf.getKernel(); 01873 01874 Buffer pseudo_f(2); 01875 Buffer pseudo_a(2); 01876 01877 pseudo_f << 0.0 << 0.5; 01878 pseudo_a << 0.0 << 0.0; 01879 01880 for(uint32 i = 0; i < L; ++i) 01881 { 01882 FilterLeastSquaresFIR poly_f(1.0, L, pseudo_f, pseudo_a, beta); 01883 01884 Buffer poly_h(Lh/L); 01885 01886 // Pull out cooefficents for the polyphase filter 01887 for(uint32 j = Lh-L; j >= 0 && j < Lh; j -= L) 01888 { 01889 poly_h << h[j+i]; 01890 } 01891 01892 poly_f.setKernel(poly_h.getReverse()); 01893 01894 bank.push_back(poly_f); 01895 } 01896 } 01897 01898 uint32 n_filters = bank.size(); 01899 01901 // Interpolation 01902 01903 Buffer::const_iterator x = data_.begin(); 01904 Buffer::const_iterator x_end = data_.end(); 01905 01906 uint32 Lx = getLength(); 01907 uint32 Ly = getLength() * L / M; 01908 01909 Buffer y(Ly); 01910 01911 if(L > 1) 01912 { 01913 //~ cerr << "Interpolation by " << L << endl << flush; 01914 01915 float64 scale = static_cast<float64>(L); 01916 01917 // Loop over all the samples 01918 while(x != x_end) 01919 { 01920 // Polyphase filter the input, for all L-1 samples 01921 for(uint32 j = 0; j < L; ++j) 01922 { 01923 float64 sample = *x * scale; 01924 01925 for(uint32 k = 0; k < n_filters; ++k) 01926 { 01927 y << bank[k].filter(sample); 01928 } 01929 ++x; 01930 if(x == x_end) break; 01931 } 01932 01933 // Add some samples to the end for filter delay compansation. 01934 if(x == x_end) 01935 { 01936 float64 x_n = data_[Lx - 1] * scale; 01937 01938 for(uint32 j = 0; j < Lh/L; ++j) 01939 { 01940 for(uint32 k = 0; k < n_filters; ++k) 01941 { 01942 y << bank[k].filter(x_n); 01943 } 01944 } 01945 break; 01946 } 01947 } 01948 } 01949 01950 // Only down sampling, still need to filter. 01951 else 01952 { 01953 for(uint32 i = 0; i < Lx; ++i) 01954 { 01955 y << lpf.filter(data_[i]); 01956 } 01957 01958 // Add some samples to the end for filter delay compansation. 01959 float64 x_n = data_[Lx - 1]; 01960 for(uint32 i = 0; i < Lh; ++i) 01961 { 01962 y << lpf.filter(x_n); 01963 } 01964 } 01965 01966 // Compensate for filter delay. 01967 y = y.subbuffer(delay, Lx*L); 01968 01970 // Decimation 01971 if(M > 1) 01972 { 01973 //~ cerr << "Decimation by " << M << endl << flush; 01974 01975 x = y.begin(); 01976 x_end = y.end(); 01977 01978 Buffer y2(Ly / M); 01979 01980 uint32 i = 0; 01981 while(x != x_end) 01982 { 01983 if(i % M == 0) 01984 { 01985 y2 << *x; 01986 } 01987 01988 ++x; 01989 ++i; 01990 } 01991 01992 y = y2; 01993 } 01994 01995 return y; 01996 }
| Buffer & Buffer::vectorOperator | ( | const Buffer & | rhs, | |
| MathOperator | op | |||
| ) | [protected] |
Definition at line 1284 of file Buffer.cc.
References ADD, begin(), DIVIDE, end(), MULTIPLY, POW, and SUBTRACT.
Referenced by operator*=(), operator+=(), operator-=(), operator/=(), and operator^=().
01285 { 01286 Buffer::iterator lhs = this->begin(); 01287 Buffer::iterator lhs_end = this->end(); 01288 01289 Buffer::const_iterator rhs = rhs_buffer.begin(); 01290 Buffer::const_iterator rhs_end = rhs_buffer.end(); 01291 01292 switch(op) 01293 { 01294 case ADD: 01295 { 01296 while(lhs != lhs_end && rhs != rhs_end) 01297 { 01298 *lhs += *rhs; 01299 01300 ++lhs; 01301 ++rhs; 01302 } 01303 break; 01304 } 01305 case SUBTRACT: 01306 { 01307 while(lhs != lhs_end && rhs != rhs_end) 01308 { 01309 *lhs -= *rhs; 01310 01311 ++lhs; 01312 ++rhs; 01313 } 01314 break; 01315 } 01316 case MULTIPLY: 01317 { 01318 while(lhs != lhs_end && rhs != rhs_end) 01319 { 01320 *lhs *= *rhs; 01321 01322 ++lhs; 01323 ++rhs; 01324 } 01325 break; 01326 } 01327 case DIVIDE: 01328 { 01329 while(lhs != lhs_end && rhs != rhs_end) 01330 { 01331 *lhs /= (*rhs +1e-20) ; // avoid dividing by zero. 01332 01333 ++lhs; 01334 ++rhs; 01335 } 01336 break; 01337 } 01338 case POW: 01339 { 01340 while(lhs != lhs_end && rhs != rhs_end) 01341 { 01342 *lhs = ::pow(*lhs, *rhs); 01343 01344 ++lhs; 01345 ++rhs; 01346 } 01347 break; 01348 } 01349 } 01350 01351 return *this; 01352 }
| Buffer & Buffer::scalarOperator | ( | const float64 & | d, | |
| MathOperator | op | |||
| ) | [protected] |
Definition at line 1408 of file Buffer.cc.
References ADD, data_, DIVIDE, end(), MULTIPLY, POW, and SUBTRACT.
Referenced by operator*=(), operator+=(), operator-=(), operator/=(), and operator^=().
01409 { 01410 std::vector<float64>::iterator lhs = data_.begin(); 01411 std::vector<float64>::iterator end = data_.end(); 01412 01413 switch(op) 01414 { 01415 case ADD: 01416 { 01417 while(lhs != end) 01418 { 01419 *lhs += d; 01420 ++lhs; 01421 } 01422 break; 01423 } 01424 case SUBTRACT: 01425 { 01426 while(lhs != end) 01427 { 01428 *lhs -= d; 01429 ++lhs; 01430 } 01431 break; 01432 } 01433 case MULTIPLY: 01434 { 01435 while(lhs != end) 01436 { 01437 *lhs *= d; 01438 ++lhs; 01439 } 01440 break; 01441 } 01442 case DIVIDE: 01443 { 01444 while(lhs != end) 01445 { 01446 *lhs /= (d + 1e-16); // avoid dividing by zero. 01447 ++lhs; 01448 } 01449 break; 01450 } 01451 case POW: 01452 { 01453 while(lhs != end) 01454 { 01455 *lhs = ::pow(*lhs, d); 01456 ++lhs; 01457 } 01458 break; 01459 } 01460 } 01461 01462 return *this; 01463 }
| std::ostream& operator<< | ( | std::ostream & | out, | |
| const Buffer & | rhs | |||
| ) | [friend] |
Sends the contents of the Buffer to the output stream.
FloatVector Nsound::Buffer::data_ [protected] |
Definition at line 2016 of file Buffer.h.
Referenced by abs(), add(), begin(), Buffer(), cbegin(), derivative(), end(), exp(), findPeaks(), get_at_index(), getLength(), getMax(), getMaxMagnitude(), getMin(), getNBytes(), getPointer(), getResample_(), getSignalEnergy(), getSum(), log(), log10(), operator!=(), Nsound::operator<<(), operator<<(), operator<<=(), operator=(), operator==(), operator[](), preallocate(), reverse(), scalarOperator(), set_at_index(), speedUp(), and subbuffer().
const uint32 Nsound::Buffer::bytes_per_sample_ = sizeof(float64) [static, protected] |
Definition at line 2018 of file Buffer.h.
Referenced by getNBytes().
1.6.3