Skip to content

Commit

Permalink
Merge branch 'swesterfeld-resampler-reset', closes #121
Browse files Browse the repository at this point in the history
* swesterfeld-resampler-reset:
  BSE: add Resampler2 function to reset state

Signed-off-by: Tim Janik <timj@gnu.org>
  • Loading branch information
tim-janik committed Sep 7, 2019
2 parents e9878d4 + f641cd8 commit 6c82539
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
4 changes: 4 additions & 0 deletions bse/bseresampler.hh
Expand Up @@ -83,6 +83,10 @@ public:
* output[10] and output[11], and the second input sample equates output[11].
*/
virtual double delay() const = 0;
/**
* clear internal history, reset resampler state to zero values
*/
virtual void reset() = 0;
protected:
static const double halfband_fir_linear_coeffs[2];
static const double halfband_fir_48db_coeffs[16];
Expand Down
24 changes: 18 additions & 6 deletions bse/bseresamplerimpl.hh
Expand Up @@ -4,6 +4,7 @@

#include <vector>
#include <bse/bseresampler.hh>
#include <bse/bseblockutils.hh>
#include <bse/sfi.hh>
#include <math.h>
#include <string.h>
Expand Down Expand Up @@ -296,7 +297,7 @@ public:
void
process_block (const float *input,
guint n_input_samples,
float *output)
float *output) override
{
const uint history_todo = min (n_input_samples, ORDER - 1);

Expand All @@ -320,15 +321,20 @@ public:
* Returns the FIR filter order.
*/
guint
order() const
order() const override
{
return ORDER;
}
double
delay() const
delay() const override
{
return order() - 1;
}
void
reset() override
{
Bse::Block::fill (history.size(), &history[0], 0.0);
}
};

/**
Expand Down Expand Up @@ -435,7 +441,7 @@ public:
void
process_block (const float *input,
guint n_input_samples,
float *output)
float *output) override
{
BSE_ASSERT_RETURN ((n_input_samples & 1) == 0);

Expand Down Expand Up @@ -497,15 +503,21 @@ public:
* Returns the filter order.
*/
guint
order() const
order() const override
{
return ORDER;
}
double
delay() const
delay() const override
{
return order() / 2 - 0.5;
}
void
reset() override
{
Bse::Block::fill (history_even.size(), &history_even[0], 0.0);
Bse::Block::fill (history_odd.size(), &history_odd[0], 0.0);
}
};

template<bool USE_SSE> Resampler2*
Expand Down

0 comments on commit 6c82539

Please sign in to comment.