2013-12-12 21:02:10 +01:00
|
|
|
/*
|
|
|
|
* Author: Harry van Haaren 2013
|
|
|
|
* harryhaaren@gmail.com
|
2016-12-27 13:47:19 +01:00
|
|
|
*
|
2013-12-12 21:02:10 +01:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2016-12-27 13:47:19 +01:00
|
|
|
*
|
2013-12-12 21:02:10 +01:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2016-12-27 13:47:19 +01:00
|
|
|
*
|
2013-12-12 21:02:10 +01:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "audiobuffer.hxx"
|
2017-03-19 12:45:04 +01:00
|
|
|
#include "config.hxx"
|
2013-12-12 21:02:10 +01:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
AudioBuffer::AudioBuffer()
|
|
|
|
{
|
2016-12-27 13:47:19 +01:00
|
|
|
ID = privateID++;
|
|
|
|
init();
|
2013-12-12 21:02:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
AudioBuffer::AudioBuffer(unsigned long size)
|
|
|
|
{
|
2016-12-27 13:47:19 +01:00
|
|
|
// FIXME recorded buffers don't get an ID, using garbage IDs
|
|
|
|
/// no ID assigned: it *takes* the one from the previous buffer!
|
|
|
|
init();
|
2017-03-19 12:45:04 +01:00
|
|
|
bufferL.resize(size);
|
|
|
|
bufferR.resize(size);
|
2013-12-12 21:02:10 +01:00
|
|
|
}
|
2016-12-27 13:47:19 +01:00
|
|
|
|
2013-12-12 21:02:10 +01:00
|
|
|
void AudioBuffer::init()
|
|
|
|
{
|
2016-12-27 13:47:19 +01:00
|
|
|
numBeats = 0;
|
|
|
|
audioFrames = 0;
|
|
|
|
memset( name, 0, sizeof(char)*20 );
|
|
|
|
//sprintf( name, "%i", ID );
|
2013-12-12 21:02:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// this function is used for "resizing" an exisiting buffer, and should
|
|
|
|
/// not be called for any other reason.
|
|
|
|
void AudioBuffer::setID(int id)
|
|
|
|
{
|
2016-12-27 13:47:19 +01:00
|
|
|
ID = id;
|
2013-12-12 21:02:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int AudioBuffer::getID()
|
|
|
|
{
|
2016-12-27 13:47:19 +01:00
|
|
|
return ID;
|
2013-12-12 21:02:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioBuffer::setName(const char* n)
|
|
|
|
{
|
2016-12-27 13:47:19 +01:00
|
|
|
memcpy( name, n, sizeof(char)* 19 );
|
|
|
|
|
|
|
|
if ( strlen(n) > 19 ) {
|
2013-12-12 21:02:10 +01:00
|
|
|
#ifdef DEBUG_BUFFER
|
2016-12-27 13:47:19 +01:00
|
|
|
cout << "AudioBuffer setName too long, truncating." << endl;
|
2013-12-12 21:02:10 +01:00
|
|
|
#endif
|
2016-12-27 13:47:19 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-12-12 21:02:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
char* AudioBuffer::getName()
|
|
|
|
{
|
2016-12-27 13:47:19 +01:00
|
|
|
return name;
|
2013-12-12 21:02:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int AudioBuffer::getBeats()
|
|
|
|
{
|
2016-12-27 13:47:19 +01:00
|
|
|
return numBeats;
|
2013-12-12 21:02:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioBuffer::setBeats(int b)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_BUFFER
|
2016-12-27 13:47:19 +01:00
|
|
|
cout << "AudioBuffer now has " << b << " beats\n" << endl;
|
2013-12-12 21:02:10 +01:00
|
|
|
#endif
|
2016-12-27 13:47:19 +01:00
|
|
|
numBeats = b;
|
2013-12-12 21:02:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioBuffer::setAudioFrames(long af)
|
|
|
|
{
|
2016-12-27 13:47:19 +01:00
|
|
|
audioFrames = af;
|
2013-12-12 21:02:10 +01:00
|
|
|
#ifdef DEBUG_BUFFER
|
2016-12-27 13:47:19 +01:00
|
|
|
cout << "AudioBuffer " << ID << " has " << audioFrames << " audioFrames\n" << endl;
|
2013-12-12 21:02:10 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
long AudioBuffer::getAudioFrames()
|
|
|
|
{
|
2016-12-27 13:47:19 +01:00
|
|
|
return audioFrames;
|
2013-12-12 21:02:10 +01:00
|
|
|
}
|
|
|
|
|
2017-03-19 12:45:04 +01:00
|
|
|
long AudioBuffer::getSize()
|
2013-12-12 21:02:10 +01:00
|
|
|
{
|
2017-03-19 12:45:04 +01:00
|
|
|
if(bufferL.size() != bufferR.size()) {
|
|
|
|
LUPPP_WARN("left and right channels of audio buffer have different size: %i vs %i", bufferL.size(), bufferR.size() );
|
|
|
|
}
|
|
|
|
return std::min(bufferL.size(), bufferR.size());
|
2013-12-12 21:02:10 +01:00
|
|
|
}
|
|
|
|
|
2017-03-19 12:45:04 +01:00
|
|
|
std::vector<float>& AudioBuffer::getDataL()
|
2013-12-12 21:02:10 +01:00
|
|
|
{
|
2017-03-19 12:45:04 +01:00
|
|
|
return bufferL;
|
|
|
|
}
|
|
|
|
std::vector<float>& AudioBuffer::getDataR()
|
|
|
|
{
|
|
|
|
return bufferR;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioBuffer::nonRtSetSample(std::vector<float>& sampleL, std::vector<float>& sampleR)
|
|
|
|
{
|
|
|
|
bufferL.swap(sampleL);
|
|
|
|
bufferR.swap(sampleR);
|
2013-12-12 21:02:10 +01:00
|
|
|
}
|
|
|
|
void AudioBuffer::nonRtResize(unsigned long size)
|
|
|
|
{
|
2017-03-19 12:45:04 +01:00
|
|
|
bufferL.resize(size);
|
|
|
|
bufferR.resize(size);
|
2013-12-12 21:02:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
ostream& AudioBuffer::operator<<(ostream& o, const AudioBuffer& a)
|
|
|
|
{
|
|
|
|
o << "AudioBuffer " << a.name <<
|
|
|
|
" beats: " << a.numBeats <<
|
|
|
|
" audioFrames: " << a.audioFrames << endl;
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
*/
|