Commit 0057f105 authored by jhammen's avatar jhammen
Browse files

compute overlap between sample and current period

parent 68199a50
......@@ -15,6 +15,7 @@
* along with handrumr.lv2. If not, see <http://www.gnu.org/licenses/>.
*/
#include <jsoncpp/json/json.h>
#include <algorithm>
#include "plugin.h"
......@@ -33,7 +34,7 @@ SamplePlay *Plugin::nextSlot()
}
Plugin::Plugin(const LV2_Feature* const* features, uint16_t channelCount)
: maxActive(0), channelCount(channelCount), instruments(0)
: channelCount(channelCount), maxActive(0), instruments(0)
{
outputPort = new float*[channelCount];
const char* missing = lv2_features_query(features,
......@@ -271,17 +272,25 @@ void Plugin::run(uint32_t sampleCount)
SamplePlay &play = active[counter];
if(play.active()) {
uint16_t channel = play.channel();
uint32_t i = play.start();
while(play.hasNext() && i < sampleCount) {
outputPort[channel][i++] += play.next();
// compute overlap
uint32_t start = play.offset();
uint64_t end = std::min(play.remaining() + start, (uint64_t)sampleCount);
// add overlap
for(uint64_t i = start; i < end; i++) {
outputPort[channel][i] += play.next();
}
if(play.finished()) {
// shrink maxActive if possible
while(maxActive > 0 && !active[maxActive - 1].active()) {
maxActive--;
}
} else {
play.offset(0);
}
}
}
// shrink maxActive if possible
while(maxActive > 0 && !active[maxActive - 1].active()) {
maxActive--;
}
}
}
\ No newline at end of file
......@@ -44,28 +44,28 @@ namespace handrumr {
class SamplePlay
{
SampleFileBuffer *mSample;
int32_t index;
uint32_t offset;
uint64_t index;
uint32_t moffset;
bool mactive;
public:
SamplePlay() : index(-1) { }
bool active() { return index >= 0; }
SamplePlay() : mactive(false) { }
bool active() { return mactive; }
void activate(SampleFileBuffer *s, uint32_t off) {
mSample = s, offset = off, index = 0;
}
uint32_t start() {
uint32_t ret = offset;
offset = 0;
return ret;
}
bool hasNext() {
if(index == mSample->size()) { index = -1; }
return index >= 0;
}
float next() {
return mSample->data()[index++];
mSample = s; moffset = off; index = 0; mactive = true;
}
void cancel() { mactive = false; }
void offset(uint32_t o) { moffset = o; }
uint32_t offset() { return moffset; }
uint16_t channel() { return mSample->channel(); }
void cancel() { index = -1; }
uint64_t remaining() { return mSample->size() - index; }
inline float next() { return mSample->data()[index++]; }
bool finished() {
if(index == mSample->size()) {
mactive = false;
return true;
}
return false;
}
};
struct PluginURIs {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment