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

compute overlap between sample and current period

parent 68199a50
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
* along with handrumr.lv2. If not, see <http://www.gnu.org/licenses/>. * along with handrumr.lv2. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <jsoncpp/json/json.h> #include <jsoncpp/json/json.h>
#include <algorithm>
#include "plugin.h" #include "plugin.h"
...@@ -33,7 +34,7 @@ SamplePlay *Plugin::nextSlot() ...@@ -33,7 +34,7 @@ SamplePlay *Plugin::nextSlot()
} }
Plugin::Plugin(const LV2_Feature* const* features, uint16_t channelCount) 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]; outputPort = new float*[channelCount];
const char* missing = lv2_features_query(features, const char* missing = lv2_features_query(features,
...@@ -271,17 +272,25 @@ void Plugin::run(uint32_t sampleCount) ...@@ -271,17 +272,25 @@ void Plugin::run(uint32_t sampleCount)
SamplePlay &play = active[counter]; SamplePlay &play = active[counter];
if(play.active()) { if(play.active()) {
uint16_t channel = play.channel(); uint16_t channel = play.channel();
uint32_t i = play.start(); // compute overlap
while(play.hasNext() && i < sampleCount) { uint32_t start = play.offset();
outputPort[channel][i++] += play.next(); 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 { ...@@ -44,28 +44,28 @@ namespace handrumr {
class SamplePlay class SamplePlay
{ {
SampleFileBuffer *mSample; SampleFileBuffer *mSample;
int32_t index; uint64_t index;
uint32_t offset; uint32_t moffset;
bool mactive;
public: public:
SamplePlay() : index(-1) { } SamplePlay() : mactive(false) { }
bool active() { return index >= 0; } bool active() { return mactive; }
void activate(SampleFileBuffer *s, uint32_t off) { void activate(SampleFileBuffer *s, uint32_t off) {
mSample = s, offset = off, index = 0; mSample = s; moffset = off; index = 0; mactive = true;
}
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++];
} }
void cancel() { mactive = false; }
void offset(uint32_t o) { moffset = o; }
uint32_t offset() { return moffset; }
uint16_t channel() { return mSample->channel(); } 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 { 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