ofxPDSP
SampleBuffer.h
1 
2 // SampleBuffer.h
3 // ofxPDSP
4 // Nicola Pisanti, MIT License, 2016
5 
6 
7 #ifndef PDSP_SAMPLERS_SAMPLEBUFFER_H_INCLUDED
8 #define PDSP_SAMPLERS_SAMPLEBUFFER_H_INCLUDED
9 
10 #include "../pdspCore.h"
11 #include <assert.h>
12 #include "../../flags.h"
13 
14 #include "ofxAudioFile.h"
15 
16 #include <cstring>
17 #include <string>
18 
19 namespace pdsp {
20 
28 class SampleBuffer {
29 
30 public:
31  SampleBuffer();
32  SampleBuffer(const SampleBuffer& other);
33  SampleBuffer& operator= (const SampleBuffer& other);
34  ~SampleBuffer();
35 
40  void load( std::string filePath );
41 
49  void load( float* interleavedBuffer, double sampleRate, int length, int channels=1 );
50 
54  void unLoad();
55 
59  bool loaded();
60 
66  void init( int tableLen, int numTables=1 );
67 
72  void normalize( );
73 
78  void setMonoChannel(int monoChannelIndex);
79 
84  void setVerbose(bool verbose);
85 
89  std::string filePath;
90 
94  float** buffer;
95 
99  int channels;
100 
104  int mono;
105 
109  int length;
110 
115 
116 private:
117  bool verbose;
118 
119 };
120 
121 } // end pdsp namespace
122 
123 
124 
125 #endif // PDSP_SAMPLERS_SAMPLEBUFFER_H_INCLUDED
void setMonoChannel(int monoChannelIndex)
some Units automatically select one channel if more than one are loaded. This set this default channe...
Definition: SampleBuffer.cpp:67
void init(int tableLen, int numTables=1)
inits the SampleBuffer with an empty table (all the values set to 0.0f)
Definition: SampleBuffer.cpp:174
float ** buffer
multidimensional buffer, use it like this: buffer[channel][sample]
Definition: SampleBuffer.h:94
double fileSampleRate
sample rate of the loaded channels
Definition: SampleBuffer.h:114
void normalize()
scales all the sample values of all the channels so that the absolute maximum value is 1...
Definition: SampleBuffer.cpp:215
void setVerbose(bool verbose)
activate logging of file loading operations for this SampleBuffer
Definition: SampleBuffer.cpp:63
int length
length of each buffer
Definition: SampleBuffer.h:109
Contains the data loaded from an audio file.
Definition: SampleBuffer.h:28
std::string filePath
path of loaded file, or contains diagnostic strings if a file is not loaded
Definition: SampleBuffer.h:89
bool loaded()
returns true if data has been loaded into the SampleBuffer
Definition: SampleBuffer.cpp:91
Thread-safe value control with smoothing.
Definition: SequencerBridge.h:11
int mono
index of channel to select for mono operation
Definition: SampleBuffer.h:104
void load(std::string filePath)
loads the audio data from a file using libsndfile
Definition: SampleBuffer.cpp:149
int channels
number of channels
Definition: SampleBuffer.h:99
void unLoad()
unload the data from the buffer and free the allocated memory
Definition: SampleBuffer.cpp:76