2013-05-20 00:57:12 +02:00
|
|
|
|
|
|
|
#ifndef LUPPP_AUDIOBUFFER_H
|
|
|
|
#define LUPPP_AUDIOBUFFER_H
|
|
|
|
|
|
|
|
#include <vector>
|
2013-09-05 19:33:16 +02:00
|
|
|
#include <string>
|
|
|
|
#include <cstring>
|
2013-08-13 18:03:33 +02:00
|
|
|
#include <iostream>
|
2013-09-11 17:39:00 +02:00
|
|
|
#include <sstream>
|
|
|
|
#include <stdlib.h>
|
2013-05-20 00:57:12 +02:00
|
|
|
|
2013-09-05 19:33:16 +02:00
|
|
|
using namespace std;
|
|
|
|
|
2013-08-06 23:20:37 +02:00
|
|
|
/// AudioBuffer stores float samples in a big vector.
|
2013-05-20 00:57:12 +02:00
|
|
|
class AudioBuffer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AudioBuffer()
|
|
|
|
{
|
2013-08-22 02:29:55 +02:00
|
|
|
ID = privateID++;
|
2013-09-06 02:28:14 +02:00
|
|
|
init();
|
2013-08-06 23:10:27 +02:00
|
|
|
}
|
|
|
|
AudioBuffer(unsigned long size)
|
|
|
|
{
|
2013-09-06 00:54:58 +02:00
|
|
|
// FIXME recorded buffers don't get an ID, using garbage IDs
|
2013-08-22 02:35:43 +02:00
|
|
|
/// no ID assigned: it *takes* the one from the previous buffer!
|
2013-09-06 02:28:14 +02:00
|
|
|
init();
|
|
|
|
buffer.resize(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void init()
|
|
|
|
{
|
2013-08-22 02:29:55 +02:00
|
|
|
numBeats = 0;
|
2013-09-06 00:07:19 +02:00
|
|
|
audioFrames = 0;
|
2013-09-11 17:39:00 +02:00
|
|
|
memset( name, 0, sizeof(char)*20 );
|
|
|
|
stringstream s;
|
|
|
|
s << ID;
|
|
|
|
sprintf ( name, "%s\n", s.str().c_str() );
|
|
|
|
}
|
2013-08-07 01:16:27 +02:00
|
|
|
|
2013-08-22 02:35:43 +02:00
|
|
|
/// this function is used for "resizing" an exisiting buffer, and should
|
|
|
|
/// not be called for any other reason.
|
|
|
|
void setID(int id)
|
|
|
|
{
|
|
|
|
ID = id;
|
|
|
|
}
|
2013-08-22 02:29:55 +02:00
|
|
|
|
2013-05-20 00:57:12 +02:00
|
|
|
int getID()
|
|
|
|
{
|
|
|
|
return ID;
|
|
|
|
}
|
2013-08-22 02:29:55 +02:00
|
|
|
|
2013-09-05 16:06:23 +02:00
|
|
|
void setName(const char* n)
|
|
|
|
{
|
|
|
|
if ( strlen(n) > 19 )
|
2013-09-05 19:33:16 +02:00
|
|
|
{
|
2013-09-05 16:06:23 +02:00
|
|
|
#ifdef DEBUG_BUFFER
|
2013-09-05 19:33:16 +02:00
|
|
|
cout << "AudioBuffer setName too long!" << endl;
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
2013-09-05 16:06:23 +02:00
|
|
|
|
|
|
|
memcpy( name, n, sizeof(char)* 20 );
|
|
|
|
}
|
|
|
|
|
2013-05-20 00:57:12 +02:00
|
|
|
int getBeats()
|
|
|
|
{
|
|
|
|
return numBeats;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setBeats(int b)
|
|
|
|
{
|
2013-08-22 15:36:56 +02:00
|
|
|
#ifdef DEBUG_BUFFER
|
2013-09-05 19:33:16 +02:00
|
|
|
cout << "AudioBuffer now has " << b << " beats\n" << endl;
|
2013-08-22 15:36:56 +02:00
|
|
|
#endif
|
2013-05-20 00:57:12 +02:00
|
|
|
numBeats = b;
|
|
|
|
}
|
|
|
|
|
2013-09-06 00:07:19 +02:00
|
|
|
void setAudioFrames(long af)
|
|
|
|
{
|
|
|
|
audioFrames = af;
|
|
|
|
#ifdef DEBUG_BUFFER
|
|
|
|
cout << "AudioBuffer " << ID << " has " << audioFrames << " audioFrames\n" << endl;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
long getAudioFrames()
|
|
|
|
{
|
|
|
|
return audioFrames;
|
|
|
|
}
|
|
|
|
|
2013-07-27 18:50:10 +02:00
|
|
|
std::vector<float>& getData()
|
2013-05-20 00:57:12 +02:00
|
|
|
{
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nonRtSetSample(std::vector<float>& sample)
|
|
|
|
{
|
|
|
|
buffer.swap(sample);
|
|
|
|
}
|
2013-09-11 14:07:21 +02:00
|
|
|
void nonRtResize(unsigned long size)
|
|
|
|
{
|
|
|
|
buffer.resize(size);
|
|
|
|
}
|
2013-09-11 17:39:00 +02:00
|
|
|
|
|
|
|
friend ostream& operator<<(ostream& o, const AudioBuffer& a)
|
|
|
|
{
|
|
|
|
o << "AudioBuffer " << a.name <<
|
|
|
|
" beats: " << a.numBeats <<
|
|
|
|
" audioFrames: " << a.audioFrames << endl;
|
|
|
|
return o;
|
|
|
|
}
|
2013-05-20 00:57:12 +02:00
|
|
|
|
|
|
|
protected:
|
2013-08-22 02:29:55 +02:00
|
|
|
static int privateID;
|
|
|
|
int ID;
|
2013-05-20 00:57:12 +02:00
|
|
|
|
|
|
|
int numBeats;
|
|
|
|
|
2013-09-06 00:07:19 +02:00
|
|
|
/// holds the number of samples that are usable audio, as opposed to
|
|
|
|
/// buffer.size(), which also has non-used space at the end.
|
|
|
|
long audioFrames;
|
|
|
|
|
2013-09-05 16:06:23 +02:00
|
|
|
char name[20];
|
|
|
|
|
2013-05-20 00:57:12 +02:00
|
|
|
std::vector<float> buffer;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|