summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndré Nusser <andre.nusser@googlemail.com>2018-08-02 10:49:39 +0200
committerAndré Nusser <andre.nusser@googlemail.com>2018-08-02 14:06:34 +0200
commit84730760698833df09eb8b082a5473be5fc85c85 (patch)
tree18db88656718463c3af7349637c613cf9c889e5d /src
parente39d82f5a06db9d4c4c505d30c4ac116037e1399 (diff)
Fix rampdown issue and clean up a bit while at it.
Diffstat (limited to 'src')
-rw-r--r--src/drumgizmo.cc11
-rw-r--r--src/events.h33
-rw-r--r--src/inputprocessor.cc36
3 files changed, 44 insertions, 36 deletions
diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc
index d30952e..2d3e410 100644
--- a/src/drumgizmo.cc
+++ b/src/drumgizmo.cc
@@ -319,9 +319,8 @@ void DrumGizmo::getSamples(int ch, int pos, sample_t* s, size_t sz)
}
size_t t = 0; // Internal buffer counter
- if(evt.rampdown == NO_RAMPDOWN)
+ if(!evt.rampdownInProgress())
{
-
#ifdef SSE
size_t optend = ((end - n) / N) * N + n;
@@ -352,19 +351,19 @@ void DrumGizmo::getSamples(int ch, int pos, sample_t* s, size_t sz)
}
else
{ // Ramp down in progress.
- for(; (n < end) && (t < evt.buffer_size) && evt.rampdown; ++n)
+ for(; (n < end) && (t < evt.buffer_size) && evt.rampdown_count; ++n)
{
- float scale = (float)evt.rampdown/(float)evt.ramp_start;
+ float scale = std::min((float)evt.rampdown_count/evt.ramp_length, 1.f);
s[n] += evt.buffer[t] * evt.scale * scale;
++t;
- evt.rampdown--;
+ evt.rampdown_count--;
}
}
// Add internal buffer counter to "global" event counter.
evt.t += evt.buffer_size;
- if((evt.t < af.size) && (evt.rampdown != 0))
+ if((evt.t < af.size) && (evt.rampdown_count != 0))
{
evt.buffer = audio_cache.next(evt.cache_id, evt.buffer_size);
}
diff --git a/src/events.h b/src/events.h
index f953031..b78dd79 100644
--- a/src/events.h
+++ b/src/events.h
@@ -42,6 +42,11 @@ typedef unsigned int timepos_t;
class Event
{
public:
+ Event(channel_t channel, timepos_t offset = 0)
+ : channel(channel), offset(offset)
+ {
+ }
+
virtual ~Event()
{
}
@@ -57,22 +62,21 @@ public:
timepos_t offset; //< Global position (ie. not relative to buffer)
};
-#define NO_RAMPDOWN -1
class EventSample : public Event
{
public:
EventSample(channel_t c, float g, AudioFile* af,
const std::string& grp, void* instr)
+ : Event(c)
+ , cache_id(CACHE_NOID)
+ , gain(g)
+ , t(0)
+ , file(af)
+ , group(grp)
+ , instrument(instr)
+ , rampdown_count(-1)
+ , ramp_length(0)
{
- cache_id = CACHE_NOID;
- channel = c;
- gain = g;
- t = 0;
- file = af;
- group = grp;
- instrument = instr;
- rampdown = NO_RAMPDOWN;
- ramp_start = 0;
}
Event::type_t getType() const
@@ -80,6 +84,11 @@ public:
return Event::sample;
}
+ bool rampdownInProgress() const
+ {
+ return rampdown_count != -1;
+ }
+
cacheid_t cache_id;
sample_t* buffer;
size_t buffer_size;
@@ -89,8 +98,8 @@ public:
AudioFile* file;
std::string group;
void* instrument;
- int rampdown;
- int ramp_start;
+ int rampdown_count;
+ int ramp_length;
float scale{1.0f};
};
diff --git a/src/inputprocessor.cc b/src/inputprocessor.cc
index 3af203c..1421d43 100644
--- a/src/inputprocessor.cc
+++ b/src/inputprocessor.cc
@@ -109,43 +109,43 @@ bool InputProcessor::processOnset(event_t& event,
return false;
}
+ auto orig_level = event.velocity;
+ for(auto& filter : filters)
+ {
+ // This line might change the 'event' variable
+ bool keep = filter->filter(event, event.offset + pos);
+
+ if(!keep)
+ {
+ return false; // Skip event completely
+ }
+ }
+
if(instr->getGroup() != "")
{
// Add event to ramp down all existing events with the same groupname.
for(Channel& ch: kit.channels)
{
- for(Event* event: activeevents[ch.num])
+ for(Event* active_event: activeevents[ch.num])
{
- if(event->getType() == Event::sample)
+ if(active_event->getType() == Event::sample)
{
- auto& event_sample = *static_cast<EventSample*>(event);
+ auto& event_sample = *static_cast<EventSample*>(active_event);
if(event_sample.group == instr->getGroup() &&
event_sample.instrument != instr)
{
// Fixed ramp of 68ms, independent of samplerate
- std::size_t ramp_length = (68./1000.)*settings.samplerate.load();
- event_sample.rampdown = ramp_length;
// TODO: This must be configurable at some point...
// ... perhaps even by instrument (ie. in the xml file)
- event_sample.ramp_start = event_sample.rampdown;
+ std::size_t ramp_length = (68./1000.)*settings.samplerate.load();
+ event_sample.rampdown_count = event.offset + ramp_length;
+ event_sample.ramp_length = ramp_length;
}
}
}
}
}
- auto orig_level = event.velocity;
- for(auto& filter : filters)
- {
- // This line might change the 'event' variable
- bool keep = filter->filter(event, event.offset + pos);
-
- if(!keep)
- {
- return false; // Skip event completely
- }
- }
-
Sample* sample = instr->sample(event.velocity, event.offset + pos);
if(sample == nullptr)