Nsound  0.9.4
Buffer.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // $Id: Buffer.h 912 2015-07-26 00:50:29Z weegreenblobbie $
4 //
5 // Nsound is a C++ library and Python module for audio synthesis featuring
6 // dynamic digital filters. Nsound lets you easily shape waveforms and write
7 // to disk or plot them. Nsound aims to be as powerful as Csound but easy to
8 // use.
9 //
10 // Copyright (c) 2004-Present Nick Hilton
11 //
12 // weegreenblobbie_yahoo_com (replace '_' with '@' and '.')
13 //
14 //-----------------------------------------------------------------------------
15 
16 //-----------------------------------------------------------------------------
17 //
18 // This program is free software; you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation; either version 2 of the License, or
21 // (at your option) any later version.
22 //
23 // This program is distributed in the hope that it will be useful,
24 // but WITHOUT ANY WARRANTY; without even the implied warranty of
25 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 // GNU Library General Public License for more details.
27 //
28 // You should have received a copy of the GNU General Public License
29 // along with this program; if not, write to the Free Software
30 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 //
32 //-----------------------------------------------------------------------------
33 #ifndef _NSOUND_BUFFER_H_
34 #define _NSOUND_BUFFER_H_
35 
36 #include <Nsound/Nsound.h>
37 #include <Nsound/BufferSelection.h>
39 
40 #include <cmath>
41 #include <iostream>
42 #include <iterator>
43 #include <string>
44 #include <vector>
45 
46 namespace Nsound
47 {
48 
49 // Forward declaration
50 class AudioStream;
51 
52 //-----------------------------------------------------------------------------
54 //
60 class Buffer
61 {
62  public:
63 
64  // Forward declaration
65 
68 
69  typedef FloatVector::iterator iterator;
70  typedef FloatVector::const_iterator const_iterator;
71 
73  //
85  Buffer();
86  explicit Buffer(uint32 chunk_size);
87 
89  //
107  explicit Buffer(const FloatVector & list);
108 
110  //
122  Buffer(const std::string & filename, uint32 chunk_size = 4096);
123 
125  ~Buffer();
126 
128  //
140  Buffer(const Buffer & rhs);
141 
142  #ifndef SWIG
143  Buffer(Buffer && move);
144  #endif
145 
147  //
158  void
159  abs();
160 
162  //
173  Buffer
174  getAbs() const
175  { Buffer temp(*this); temp.abs(); return temp; }
176 
177  // add()
178  //
180  //
234  //
235  void
236  add(const Buffer & buffer,
237  uint32 offset = 0,
238  uint32 n_samples = 0);
239 
241  //
252  uint32
253  argmax() const;
254 
256  //
267  uint32
268  argmin() const;
269 
271  //
283  inline
284  iterator
286  { return data_.begin(); }
287 
289  //
301  inline
303  begin() const
304  { return data_.begin(); }
305 
307  //
316  inline
319  { return circular_iterator(data_); }
320 
322  //
331  inline
333  cbegin() const
334  { return const_circular_iterator(data_); }
335 
337  //
346  inline
347  iterator
348  end()
349  { return data_.end(); }
350 
352  //
361  inline
363  end() const
364  { return data_.end(); }
365 
367  //
378  inline
379  uint32
380  getNBytes() const
381  { return static_cast<uint32>(bytes_per_sample_ * data_.size()); }
382 
384  //
398  void
399  exp();
400 
402  //
416  Buffer
417  getExp() const
418  { Buffer temp(*this); temp.exp(); return temp; }
419 
421  //
436  void
437  convolve(const Buffer & H);
438 
440  //
455  Buffer
456  getConvolve(const Buffer & H) const;
457 
459  //
471  void
472  dB();
473 
475  //
486  Buffer
487  getdB() const
488  { Buffer temp(*this); temp.dB(); return temp; }
489 
491  //
502  void
503  derivative(uint32 n);
504 
506  //
517  Buffer
519  { Buffer temp(*this); temp.derivative(n); return temp; }
520 
522  //
533  void
534  downSample(uint32 n);
535 
537  //
548  Buffer
549  getDownSample(uint32 n) const;
550 
552  //
564  findPeaks(
565  uint32 window_size = 0,
566  float64 min_height = 0.0) const;
567 
568 //~ Experimental, doesn't work yet
569 //~//~ //! Returns the estimated fundamental frequency of the Buffer.
570 //~ Buffer
571 //~ findPitch(float64 sample_rate);
572 
574  //
585  inline
586  uint32
587  getLength() const
588  { return static_cast<uint32>(data_.size()); }
589 
591  //
613  void
614  limit(float64 min, float64 max);
615 
617  //
633  void
634  limit(const Buffer & min, const Buffer & max);
635 
637  //
648  Buffer
649  getLimit(float64 min, float64 max) const
650  { Buffer temp(*this); temp.limit(min, max); return temp; }
651 
653  //
669  Buffer
670  getLimit(const Buffer & min, const Buffer & max) const
671  { Buffer temp(*this); temp.limit(min, max); return temp; }
672 
674  //
685  void
686  log();
687 
689  //
700  Buffer
701  getLog() const
702  { Buffer temp(*this); temp.log(); return temp; }
703 
705  //
716  void
717  log10();
718 
720  //
731  Buffer
732  getLog10() const
733  { Buffer temp(*this); temp.log10(); return temp; }
734 
736  //
747  float64
748  getMax() const;
749 
751  //
762  float64
763  getMaxMagnitude() const;
764 
766  //
777  float64
778  getMean() const;
779 
781  //
792  float64
793  getMin() const;
794 
795 
796  // mul()
797  //
799  //
851  //
852  void
853  mul(const Buffer & buffer,
854  uint32 offset = 0,
855  uint32 n_samples = 0);
856 
858  //
869  void
870  normalize();
871 
873  //
884  Buffer
885  getNormalize() const
886  { Buffer temp(*this); temp.normalize(); return temp; }
887 
889  //
900  Buffer
901  getSignalEnergy(uint32 window_size) const;
902 
904  //
915  float64
916  getStd() const;
917 
919  //
930  float64
931  getSum() const;
932 
934  //
947  void
948  zNorm();
949 
951  //
964  Buffer
965  getZNorm() const
966  { Buffer temp(*this); temp.zNorm(); return temp; }
967 
969  //
981  operator()(const BooleanVector & bv);
982 
984  Buffer &
985  operator=(const Buffer & rhs);
986 
988  boolean
989  operator==(const Buffer & rhs) const;
990 
992  boolean
993  operator!=(const Buffer & rhs) const;
994 
996  inline
997  float64 &
999  { return data_[index]; }
1000 
1002  inline
1003  const float64 &
1004  operator[](uint32 index) const
1005  { return data_[index]; }
1006 
1008  //
1021  Buffer &
1022  operator<<(const AudioStream & rhs);
1023 
1025  //
1038  Buffer &
1039  operator<<(const Buffer & rhs);
1040 
1042  inline
1043  Buffer &
1045  { data_.push_back(d); return *this; }
1046 
1048  //
1064  Buffer & operator+=(const Buffer & rhs);
1065 
1067  //
1083  Buffer & operator-=(const Buffer & rhs);
1084 
1086  //
1102  Buffer & operator*=(const Buffer & rhs);
1103 
1105  //
1121  Buffer & operator/=(const Buffer & rhs);
1122 
1124  //
1140  Buffer & operator^=(const Buffer & powers);
1141 
1143  //
1154  Buffer & operator+=(float64 d);
1155 
1157  //
1168  Buffer & operator-=(float64 d);
1169 
1171  //
1182  Buffer & operator*=(float64 d);
1183 
1185  //
1196  Buffer & operator/=(float64 d);
1197 
1199  //
1228  Buffer & operator^=(float64 power);
1229 
1230  #ifndef SWIG
1231  friend
1233  std::ostream &
1234  operator<<(std::ostream & out, const Buffer & rhs);
1235  #endif
1236 
1238  //
1250 
1252  //
1264 
1266  //
1278 
1280  //
1292 
1294  //
1306 
1308  //
1320 
1321  //~ //~ //! EXPERIMENTAL! Transforms the Buffer to the frequency domain and shifts it by n_bins_to_shift and then transforms it back to the time domain.
1322  //~ //
1323  //~ //! \par Example:
1324  //~ //! \code
1325  //~ //! // C++
1326  //~ //! Buffer b1("california.wav");
1327  //~ //! b1.pitchShift(2048, 2048, 2);
1328  //~ //!
1329  //~ //! // Python
1330  //~ //! b1 = Buffer("california.wav")
1331  //~ //! b1.pitchShift(2048, 2048, 2)
1332  //~ //! \endcode
1333  //~ void
1334  //~ pitchShift(uint32 window_size, uint32 fft_size, int32 n_bins_to_shift );
1335  //~
1336  //~ //~ //! EXPERIMENTAL! Transforms a copy of the Buffer to the frequency domain and shifts it by n_bins_to_shift and then transforms it back to the time domain.
1337  //~ //
1338  //~ //! \par Example:
1339  //~ //! \code
1340  //~ //! // C++
1341  //~ //! Buffer b1("california.wav");
1342  //~ //! Buffer b2 = b1.getPitchShift(2048, 2048, 2);
1343  //~ //!
1344  //~ //! // Python
1345  //~ //! b1 = Buffer("california.wav")
1346  //~ //! b2 = b1.getPitchShift(2048, 2048, 2)
1347  //~ //! \endcode
1348  //~ Buffer
1349  //~ getPitchShift(uint32 window_size, uint32 fft_size, int32 n_bins_to_shift) const
1350  //~ { Buffer temp(*this);
1351  //~ temp.pitchShift(window_size, fft_size, n_bins_to_shift); return temp;}
1352 
1354  //
1367  void
1368  plot(const std::string & title = "Buffer") const;
1369 
1371  //
1380  const
1381  float64 *
1382  getPointer() const
1383  { return data_.data(); }
1384 
1386  //
1396  float64 *
1398  { return data_.data(); }
1399 
1401  //
1414  void
1415  preallocate(uint32 n);
1416 
1418  //
1430  void
1431  readWavefile(const char * filename);
1432 
1434  //
1445  void
1447  { *this = getResample(factor, 10, 5.0); }
1448 
1450  //
1466  void
1467  resample(const Buffer & factor)
1468  { *this = getResample(factor, 10, 5.0); }
1469 
1471  //
1482  Buffer
1483  getResample(
1484  float64 factor,
1485  const uint32 N = 10,
1486  float64 beta = 5.0) const;
1487 
1489  //
1505  Buffer
1506  getResample(
1507  const Buffer & factor,
1508  const uint32 N = 10,
1509  float64 beta = 5.0) const;
1510 
1512  //
1523  Buffer
1524  getResample(
1525  const uint32 L,
1526  const uint32 M,
1527  const uint32 N = 10,
1528  float64 beta = 5.0) const;
1529 
1531  //
1542  void
1543  reverse();
1544 
1546  //
1557  Buffer
1558  getReverse() const
1559  { Buffer temp(*this); temp.reverse(); return temp; }
1560 
1562  //
1575  void
1576  round();
1577 
1579  //
1592  Buffer
1593  getRound() const
1594  { Buffer temp(*this); temp.round(); return temp; }
1595 
1597  //
1612  select(const uint32 start_index, const uint32 stop_index);
1613 
1614  #ifndef SWIG
1615  //
1618  //
1619  std::ostream &
1620  write(std::ostream & out) const;
1621  #endif
1622 
1623  std::string
1624  write() const;
1625 
1626  #ifndef SWIG
1627  //
1630  //
1631  std::istream &
1632  read(std::istream & stream_in);
1633  #endif
1634 
1635  void
1636  read(const std::string & string_in);
1637 
1639  //
1653  void
1654  smooth(uint32 n_passes, uint32 n_samples_per_average);
1655 
1657  //
1671  Buffer
1672  getSmooth(uint32 n_passes, uint32 n_samples_per_average) const
1673  { Buffer temp(*this); temp.smooth(n_passes, n_samples_per_average); return temp; }
1674 
1676  //
1689  void
1690  speedUp(float64 step_size);
1691 
1693  //
1706  Buffer
1707  getSpeedUp(float64 step_size) const
1708  { Buffer temp(*this); temp.speedUp(step_size); return temp; }
1709 
1711  //
1727  void
1728  speedUp(const Buffer & step_size);
1729 
1731  //
1747  Buffer
1748  getSpeedUp(const Buffer & step_size) const
1749  { Buffer temp(*this); temp.speedUp(step_size); return temp; }
1750 
1752  //
1763  void
1764  sqrt();
1765 
1767  //
1778  Buffer
1779  getSqrt() const
1780  { Buffer temp(*this); temp.sqrt(); return temp; }
1781 
1783  //
1796  Buffer
1797  subbuffer(uint32 start_index, uint32 n_samples = 0) const;
1798 
1800  //
1811  void
1812  upSample(uint32 n);
1813 
1815  //
1826  Buffer
1827  getUpSample(uint32 n) const;
1828 
1830  //
1841  void
1842  writeWavefile(const char * filename) const;
1843 
1845  void _set_at_index(int32 index, float64 x);
1846 
1848  void _swig_shadow(){}
1849 
1851  static
1852  Buffer
1853  ones(const uint32 n_samples);
1854 
1856  static
1857  Buffer
1858  rand(const uint32 n_samples);
1859 
1861  static
1862  Buffer
1863  zeros(const uint32 n_samples);
1864 
1865 protected:
1866 
1867  Buffer
1868  _get_resample(
1869  const uint32 L,
1870  const uint32 M,
1871  const uint32 N,
1872  float64 beta) const;
1873 
1875 
1876  static const uint32 bytes_per_sample_ = sizeof(float64);
1877 
1878 }; // class Buffer
1879 
1880 
1881 
1882 //-----------------------------------------------------------------------------
1883 // Non class methods
1884 //-----------------------------------------------------------------------------
1885 
1887 inline Buffer operator+(const Buffer & lhs, const Buffer & rhs)
1888 {
1889  Buffer temp(lhs);
1890  return temp += rhs;
1891 }
1892 
1894 inline Buffer operator-(const Buffer & lhs, const Buffer & rhs)
1895 {
1896  Buffer temp(lhs);
1897  return temp -= rhs;
1898 }
1899 
1901 inline Buffer operator*(const Buffer & lhs, const Buffer & rhs)
1902 {
1903  Buffer temp(lhs);
1904  return temp *= rhs;
1905 }
1906 
1908 inline Buffer operator/(const Buffer & lhs, const Buffer & rhs)
1909 {
1910  Buffer temp(lhs);
1911  return temp /= rhs;
1912 }
1913 
1915 inline Buffer operator^(const Buffer & lhs, const Buffer & rhs)
1916 {
1917  Buffer temp(lhs);
1918  return temp ^= rhs;
1919 }
1920 
1921 // Scalar operators
1922 
1924 inline Buffer operator+(const Buffer & lhs, float64 d)
1925 {
1926  Buffer temp(lhs);
1927  return temp += d;
1928 }
1929 
1931 inline Buffer operator-(const Buffer & lhs, float64 d)
1932 {
1933  Buffer temp(lhs);
1934  return temp -= d;
1935 }
1936 
1938 inline Buffer operator*(const Buffer & lhs, float64 d)
1939 {
1940  Buffer temp(lhs);
1941  return temp *= d;
1942 }
1943 
1945 inline Buffer operator/(const Buffer & lhs, float64 d)
1946 {
1947  Buffer temp(lhs);
1948  return temp /= d;
1949 }
1950 
1953 //
1982 inline Buffer operator^(const Buffer & lhs, float64 d)
1983 {
1984  Buffer temp(lhs);
1985  return temp ^= d;
1986 }
1987 
1988 // Reverse scalar operators
1989 
1991 inline Buffer operator+(float64 d, const Buffer & rhs)
1992 {
1993  return rhs + d;
1994 }
1995 
1997 inline Buffer operator-(float64 d, const Buffer & rhs)
1998 {
1999  return (rhs * -1.0) + d;
2000 }
2001 
2003 inline Buffer operator*(float64 d, const Buffer & rhs)
2004 {
2005  return rhs * d;
2006 }
2007 
2009 inline Buffer operator/(float64 d, const Buffer & rhs)
2010 {
2011  Buffer temp(rhs);
2012 
2013  uint32 size = rhs.getLength();
2014 
2015  for(uint32 i = 0; i < size; ++i)
2016  {
2017  temp[i] = d / rhs[i];
2018  }
2019 
2020  return temp;
2021 }
2022 
2024 inline Buffer operator^(float64 d, const Buffer & rhs)
2025 {
2026  Buffer temp(rhs);
2027 
2028  uint32 size = rhs.getLength();
2029 
2030  for(uint32 i = 0; i < size; ++i)
2031  {
2032  temp[i] = ::pow(d ,rhs[i]);
2033  }
2034 
2035  return temp;
2036 }
2037 
2038 // DOXME
2039 typedef std::vector<Buffer> BufferVector;
2040 typedef std::vector<Buffer *> BufferPointerVector;
2041 
2042 // Friends
2043 std::ostream &
2044 operator<<(std::ostream & out, const Buffer & rhs);
2045 
2046 } // namespace
2047 
2048 // :mode=c++: jEdit modeline
2049 #endif
Buffer subbuffer(uint32 start_index, uint32 n_samples=0) const
Slice the Buffer.
Definition: Buffer.cc:2073
const_iterator begin() const
Retruns the itreator at the start of the Buffer.
Definition: Buffer.h:303
unsigned int uint32
Definition: Nsound.h:153
void resample(const Buffer &factor)
Resamples this Buffer using discrete-time resampling.
Definition: Buffer.h:1467
Buffer getSmooth(uint32 n_passes, uint32 n_samples_per_average) const
Applies a moving average filter to smooth a copy of this Buffer.
Definition: Buffer.h:1672
Buffer getSpeedUp(float64 step_size) const
Resamples a copy of this Buffer by the step_size, no interpolation.
Definition: Buffer.h:1707
Buffer getSpeedUp(const Buffer &step_size) const
Resamples a copy of this Buffer on a sample by sample basis, no interpolation.
Definition: Buffer.h:1748
std::ostream & operator<<(std::ostream &out, const Buffer &rhs_buffer)
Definition: Buffer.cc:1338
AudioStream operator-(const AudioStream &lhs, const AudioStream &rhs)
Definition: AudioStream.h:635
float64 getStd() const
Returns the standard deviation of the Buffer.
Definition: Buffer.cc:1107
boolean operator!=(const Buffer &rhs) const
Tests of inequality.
Definition: Buffer.cc:1199
void readWavefile(const char *filename)
Sets this Buffer to the contents of the wavefile on the disk.
Definition: Buffer.cc:1562
boolean operator==(const Buffer &rhs) const
Tests of equality.
Definition: Buffer.cc:1179
void dB()
Modifies the Buffer so each sample is converted to dB, 20 * log10(sample).
Definition: Buffer.cc:567
Buffer getConvolve(const Buffer &H) const
Convolves a copy of the Buffer with another Buffer.
Definition: Buffer.cc:527
Buffer()
Creates an empty Buffer that also calss std::vector::reserve() to preallocate memory for samples...
Definition: Buffer.cc:62
AudioStream operator+(const AudioStream &lhs, const AudioStream &rhs)
Definition: AudioStream.h:629
AudioStream operator/(const AudioStream &lhs, const AudioStream &rhs)
Definition: AudioStream.h:647
float64 * getPointer()
Requires matplotlib. Creates a plot of this Buffer.
Definition: Buffer.h:1397
Buffer getLimit(float64 min, float64 max) const
Returns a copy of the Buffer with min and max limits.
Definition: Buffer.h:649
AudioStream operator^(const AudioStream &lhs, const AudioStream &rhs)
Definition: AudioStream.h:653
Buffer getDownSample(uint32 n) const
Returns a copy of this Buffer downsampled by a integral factor. N must be > 1.
Definition: Buffer.cc:615
Buffer getZNorm() const
Returns a Z score normalized copy of the Buffer.
Definition: Buffer.h:965
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.
Definition: Buffer.cc:1077
void log10()
Sets each sample in the Buffer to log base 10.
Definition: Buffer.cc:936
void preallocate(uint32 n)
Preallocates memory to hold an additional n samples.
Definition: Buffer.cc:1544
void downSample(uint32 n)
Downsample this Buffer by a integral factor. N must be > 1.
Definition: Buffer.cc:605
static Buffer zeros(const uint32 n_samples)
Returns a Buffer full of zeros of length n_samples.
Definition: Buffer.cc:2265
Buffer & operator/=(const Buffer &rhs)
Divides each sample in this Buffer with the right hand side (rhs) Buffer.
Definition: Buffer.cc:1281
BufferSelection operator()(const BooleanVector &bv)
Returns a BufferSelection object used for manipulation of a selected region of samples.
Definition: Buffer.cc:1170
const_circular_iterator cbegin() const
Retruns the itreator at the start of the Buffer.
Definition: Buffer.h:333
Buffer & operator=(const Buffer &rhs)
The assignment operator. C++ only, for Python, use the copy constructor.
Definition: Buffer.cc:1156
void plot(const std::string &title="Buffer") const
Requires matplotlib. Creates a plot of this Buffer.
Definition: Buffer.cc:1551
static const uint32 bytes_per_sample_
Definition: Buffer.h:1876
A circulator iterator for class Buffer.
float64 getMean() const
Returns the mean sample value in the Buffer.
Definition: Buffer.cc:995
std::istream & read(std::istream &stream_in)
Constructs a Buffer from seralized data in the inputstream.
Definition: Buffer.cc:1945
void limit(float64 min, float64 max)
Limits the Buffer to min and max.
Definition: Buffer.cc:876
void _swig_shadow()
SWIG helper function function to shadow.
Definition: Buffer.h:1848
void resample(float64 factor)
Resamples this Buffer using discrete-time resampling.
Definition: Buffer.h:1446
Buffer getLog10() const
Returns the the Buffer where each sample is the natural log.
Definition: Buffer.h:732
std::vector< Buffer * > BufferPointerVector
Definition: Buffer.h:2040
AudioStream operator*(const AudioStream &lhs, const AudioStream &rhs)
Definition: AudioStream.h:641
const float64 & operator[](uint32 index) const
Returns a const reference into the Buffer.
Definition: Buffer.h:1004
Buffer getAbs() const
Modifies a copy of the Buffer by making any negative value positive.
Definition: Buffer.h:174
double float64
Definition: Nsound.h:146
Buffer getDerivative(uint32 n) const
Returns the nth derivative of the Buffer.
Definition: Buffer.h:518
void writeWavefile(const char *filename) const
Writes the Buffer to a Wavefile.
Definition: Buffer.cc:2118
float64 & operator[](uint32 index)
Retruns a reference into the Buffer.
Definition: Buffer.h:998
circular_iterator cbegin()
Retruns the itreator at the start of the Buffer.
Definition: Buffer.h:318
float64 getMaxMagnitude() const
Returns the maximum magnitude value in the Buffer, i.e. max(abs(samples)).
Definition: Buffer.cc:973
void _set_at_index(int32 index, float64 x)
SWIG helper function function to shadow.
Definition: Buffer.cc:1876
uint32 getLength() const
Returns the number of samples in the Buffer.
Definition: Buffer.h:587
Buffer getExp() const
Each sample in the Buffer becomes the power e^x.
Definition: Buffer.h:417
void convolve(const Buffer &H)
Convolves the Buffer with another Buffer.
Definition: Buffer.cc:520
iterator end()
Retruns the itreator at the end of the Buffer.
Definition: Buffer.h:348
Buffer getRound() const
Rounds the samples in a copy of this Buffer to the nearest integer value.
Definition: Buffer.h:1593
Nsound::const_circular_iterator const_circular_iterator
Definition: Buffer.h:67
FloatVector::const_iterator const_iterator
Definition: Buffer.h:70
void zNorm()
Normalized the Buffer using Z score normalizing.
Definition: Buffer.cc:1134
std::vector< Buffer > BufferVector
Definition: Buffer.h:2039
std::string write() const
Definition: Buffer.cc:1936
void smooth(uint32 n_passes, uint32 n_samples_per_average)
Applies a moving average filter to smooth this Buffer.
Definition: Buffer.cc:1981
iterator begin()
Retruns the itreator at the start of the Buffer.
Definition: Buffer.h:285
BooleanVector operator<(float64 rhs)
Creates a BooleanVector where each value is true iff Buffer[n] < rhs.
Definition: Buffer.cc:2165
static Buffer ones(const uint32 n_samples)
Returns a Buffer full of ones of length n_samples.
Definition: Buffer.cc:2239
void speedUp(float64 step_size)
Resamples this Buffer by the step_size, no interpolation.
Definition: Buffer.cc:2008
void reverse()
Reverses the samples in this Buffer.
Definition: Buffer.cc:1850
void normalize()
Multiplies the Buffer by a constant gain so the peak sample has magnitude 1.0.
Definition: Buffer.cc:1064
Buffer getLimit(const Buffer &min, const Buffer &max) const
Returns a copy of the Buffer with min and max limits.
Definition: Buffer.h:670
std::vector< uint32 > Uint32Vector
static Buffer rand(const uint32 n_samples)
Returns a Buffer full of random values of length n_samples.
Definition: Buffer.cc:2252
void exp()
Each sample in the Buffer becomes the power e^x.
Definition: Buffer.cc:510
Buffer & operator^=(const Buffer &powers)
Each sample in the Buffer becomes the power x^n.
Definition: Buffer.cc:1290
const float64 * getPointer() const
Returns the raw point to the first sample in the Buffer.
Definition: Buffer.h:1382
uint32 argmin() const
Retruns the index of the minimum value in the Buffer.
Definition: Buffer.cc:485
Buffer & operator*=(const Buffer &rhs)
Multiplies each sample from the right hand side (rhs) with this Buffer.
Definition: Buffer.cc:1272
void abs()
Modifies the Buffer by making any negative value positive.
Definition: Buffer.cc:119
Nsound::circular_iterator circular_iterator
Definition: Buffer.h:66
Buffer getLog() const
Returns the the Buffer where each sample is the natural log.
Definition: Buffer.h:701
BufferSelection select(const uint32 start_index, const uint32 stop_index)
Returns a BufferSelection for the range of indicies.
Definition: Buffer.cc:1897
float64 getSum() const
Returns the sum of all samples.
Definition: Buffer.cc:1118
void sqrt()
Takes the square root of each sample in this Buffer.
Definition: Buffer.cc:2051
A Buffer for storing audio samples.
Definition: Buffer.h:60
Buffer getUpSample(uint32 n) const
Upsample a copy of this Buffer by a integral factor. N must be > 1.
Definition: Buffer.cc:2111
BooleanVector operator<=(float64 rhs)
Creates a BooleanVector where each value is true iff Buffer[n] <= rhs.
Definition: Buffer.cc:2184
std::vector< boolean > BooleanVector
signed int int32
Definition: Nsound.h:142
float64 getMin() const
Returns the minimum sample value in the Buffer.
Definition: Buffer.cc:1004
void round()
Rounds the samples in this Buffer to the nearest integer value.
Definition: Buffer.cc:1864
Buffer _get_resample(const uint32 L, const uint32 M, const uint32 N, float64 beta) const
Definition: Buffer.cc:1684
Buffer getNormalize() const
Returns a copy of the Buffer normalized.
Definition: Buffer.h:885
Buffer getResample(float64 factor, const uint32 N=10, float64 beta=5.0) const
Resamples a copy of this Buffer using discrete-time resampling.
Definition: Buffer.cc:1607
Buffer getSqrt() const
Taks the square root of each sample in a copy of this Buffer.
Definition: Buffer.h:1779
uint32 getNBytes() const
Retruns the number of bytes held in the Buffer array.
Definition: Buffer.h:380
Buffer & operator-=(const Buffer &rhs)
Subracts each sample from the right hand side (rhs) Buffer from this Buffer.
Definition: Buffer.cc:1263
void upSample(uint32 n)
Upsample this Buffer by a integral factor. N must be > 1.
Definition: Buffer.cc:2101
FloatVector::iterator iterator
Definition: Buffer.h:69
const_iterator end() const
Retruns the itreator at the end of the Buffer.
Definition: Buffer.h:363
float64 getMax() const
Returns the maximum sample value in the Buffer.
Definition: Buffer.cc:951
Buffer & operator+=(const Buffer &rhs)
Adds each sample from the right hand side (rhs) Buffer with this Buffer.
Definition: Buffer.cc:1254
void add(const Buffer &buffer, uint32 offset=0, uint32 n_samples=0)
This method adds buffer to *this.
Definition: Buffer.cc:225
Buffer getReverse() const
Reverses the samples in a copy of this Buffer.
Definition: Buffer.h:1558
BooleanVector operator>=(float64 rhs)
Creates a BooleanVector where each value is true iff Buffer[n] >= rhs.
Definition: Buffer.cc:2146
~Buffer()
Destroys the Buffer.
Definition: Buffer.cc:112
Uint32Vector findPeaks(uint32 window_size=0, float64 min_height=0.0) const
Find the peaks in the Buffer and return a vector of indicies.
Definition: Buffer.cc:623
BooleanVector operator>(float64 rhs)
Creates a BooleanVector where each value is true iff Buffer[n] > rhs.
Definition: Buffer.cc:2127
A helper class for advance operators.
Buffer & operator<<(const AudioStream &rhs)
Concatenates Buffers and AudioStreams together.
Definition: Buffer.cc:1219
FloatVector data_
Definition: Buffer.h:1874
Buffer getdB() const
Returns the Buffer in dB.
Definition: Buffer.h:487
void derivative(uint32 n)
Calculates the nth derivative of the Buffer.
Definition: Buffer.cc:592
uint32 argmax() const
Retruns the index of the maximum value in the Buffer.
Definition: Buffer.cc:460
void mul(const Buffer &buffer, uint32 offset=0, uint32 n_samples=0)
This method multiplies a Buffer to *this over a sub range.
Definition: Buffer.cc:1025
void log()
Sets each sample in the Buffer to the natural log.
Definition: Buffer.cc:923