Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 29 additions & 14 deletions plugins/Xpressive/ExprSynth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ struct IntegrateFunction : public exprtk::ifunction<T>

IntegrateFunction(const unsigned int* frame, unsigned int sample_rate,unsigned int max_counters) :
exprtk::ifunction<T>(1),
m_firstValue(0),
m_frame(frame),
m_sample_rate(sample_rate),
m_max_counters(max_counters),
m_sampleRate(sample_rate),
m_maxCounters(max_counters),
m_nCounters(0),
m_nCountersCalls(0),
m_cc(0)
Expand All @@ -96,15 +97,26 @@ struct IntegrateFunction : public exprtk::ifunction<T>

inline T operator()(const T& x) override
{
if (*m_frame == 0)
if (m_frame)
{
++m_nCountersCalls;
if (m_nCountersCalls > m_max_counters)
if (m_nCountersCalls == 0)
{
m_firstValue = *m_frame;
}
if (m_firstValue == *m_frame)
{
return 0;
++m_nCountersCalls;
if (m_nCountersCalls > m_maxCounters)
{
return 0;
}
m_cc = m_nCounters;
++m_nCounters;
}
else // we moved to the next frame
{
m_frame = 0; // this will indicate that we are no longer in init phase.
}
m_cc = m_nCounters;
++m_nCounters;
}

T res = 0;
Expand All @@ -114,13 +126,16 @@ struct IntegrateFunction : public exprtk::ifunction<T>
m_counters[m_cc] += x;
}
m_cc = (m_cc + 1) % m_nCountersCalls;
return res / m_sample_rate;
}

const unsigned int* const m_frame;
const unsigned int m_sample_rate;
const unsigned int m_max_counters;
return res / m_sampleRate;
}
unsigned int m_firstValue;
const unsigned int* m_frame;
const unsigned int m_sampleRate;
// number of counters allocated
const unsigned int m_maxCounters;
// number of integrate instances that has counters allocated
unsigned int m_nCounters;
// real number of integrate instances
unsigned int m_nCountersCalls;
unsigned int m_cc;
double *m_counters;
Expand Down
20 changes: 12 additions & 8 deletions plugins/Xpressive/Xpressive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ void XpressiveView::expressionChanged() {
ExprFront expr(text.constData(),sample_rate);
float t=0;
const float f=10,key=5,v=0.5;
unsigned int i;
unsigned int frame_counter = 0;
expr.add_variable("t", t);

if (m_output_expr)
Expand All @@ -572,20 +572,24 @@ void XpressiveView::expressionChanged() {
expr.add_cyclic_vector("W2",e->graphW2().samples(),e->graphW2().length());
expr.add_cyclic_vector("W3",e->graphW3().samples(),e->graphW3().length());
}
expr.setIntegrate(&i,sample_rate);
expr.setIntegrate(&frame_counter,sample_rate);
expr.add_constant("srate",sample_rate);

const bool parse_ok=expr.compile();

if (parse_ok) {
e->exprValid().setValue(0);
const auto length = static_cast<std::size_t>(m_raw_graph->length());
const unsigned int length = static_cast<unsigned int>(m_raw_graph->length());
auto const samples = new float[length];
for (auto i = std::size_t{0}; i < length; i++) {
t = i / (float) length;
samples[i] = expr.evaluate();
if (std::isinf(samples[i]) != 0 || std::isnan(samples[i]) != 0)
samples[i] = 0;
// frame_counter's reference is used in the integrate function.
for (frame_counter = 0; frame_counter < length; ++frame_counter)
{
t = frame_counter / (float) length;
samples[frame_counter] = expr.evaluate();
if (std::isinf(samples[frame_counter]) != 0 || std::isnan(samples[frame_counter]) != 0)
{
samples[frame_counter] = 0;
}
}
m_raw_graph->setSamples(samples);
delete[] samples;
Expand Down
Loading