Skip to content

Commit

Permalink
Adjustments to the r2c plan creation, for speed and correctness
Browse files Browse the repository at this point in the history
  • Loading branch information
sboukortt committed Feb 16, 2019
1 parent 099ed6a commit 4ba4a80
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
18 changes: 15 additions & 3 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,21 @@ void intersect_activate(LV2_Handle handle) {

for (i = 0; i < 2; ++i) {
memset(intersect->input_buffer[i], 0, intersect->fft_size * sizeof(float));
intersect->plan_r2c[i] = fftwf_plan_dft_r2c_1d(intersect->fft_size, intersect->input_buffer[i], intersect->transformed[i], FFTW_MEASURE | FFTW_DESTROY_INPUT);
}
intersect->plan_r2c = fftwf_plan_many_dft_r2c(
/*rank=*/1,
/*n=*/&intersect->fft_size,
/*howmany=*/2,
/*in*/intersect->input_buffer[LEFT],
/*inembed=*/NULL,
/*istride=*/1,
/*idist=*/intersect->input_buffer[RIGHT] - intersect->input_buffer[LEFT],
/*out=*/intersect->transformed[LEFT],
/*onembed=*/NULL,
/*ostride=*/1,
/*odist=*/intersect->transformed[RIGHT] - intersect->transformed[LEFT],
FFTW_PATIENT
);
intersect->plan_c2r = fftwf_plan_dft_c2r_1d(intersect->fft_size, intersect->pre_output, intersect->ifft_result, FFTW_MEASURE | FFTW_DESTROY_INPUT);
}

Expand All @@ -82,8 +95,7 @@ void intersect_deactivate(LV2_Handle handle) {
fftwf_free(intersect->transformed[RIGHT]);
fftwf_free(intersect->pre_output);

fftwf_destroy_plan(intersect->plan_r2c[LEFT]);
fftwf_destroy_plan(intersect->plan_r2c[RIGHT]);
fftwf_destroy_plan(intersect->plan_r2c);
fftwf_destroy_plan(intersect->plan_c2r);

fftwf_cleanup();
Expand Down
4 changes: 1 addition & 3 deletions src/intersect.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ static void run(LV2_Handle handle, uint32_t sample_count, Effect effect) {
memmove(intersect->output_buffer[CENTER], intersect->output_buffer[CENTER] + intersect->fft_jump_size, (intersect->fft_size - intersect->fft_jump_size) * sizeof(float));
memset(intersect->output_buffer[CENTER] + (intersect->fft_size - intersect->fft_jump_size), 0, intersect->fft_jump_size * sizeof(float));

for (i = 0; i < 2; ++i) {
fftwf_execute(intersect->plan_r2c[i]);
}
fftwf_execute(intersect->plan_r2c);

for (i = 0; i < intersect->fft_size / 2 + 1; ++i) {
const float * const left = intersect->transformed[LEFT] [i],
Expand Down
6 changes: 3 additions & 3 deletions src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct {
float *fft_size_hint, *overlap_factor_hint;
float *latency;

uint32_t fft_size, overlap_factor, fft_jump_size;
int fft_size, overlap_factor, fft_jump_size;
float normalization_factor;

/* deviation from the “stable state” where there are `fft_jump_size`
Expand All @@ -55,7 +55,7 @@ struct {
When `deviation` = `fft_jump_size`, the output buffer is empty and
the input buffers are full. Time to refill!
*/
uint32_t deviation;
int deviation;

float *input_buffer[2],
*ifft_result,
Expand All @@ -64,7 +64,7 @@ struct {
fftwf_complex *transformed[2],
*pre_output;

fftwf_plan plan_r2c[2],
fftwf_plan plan_r2c,
plan_c2r;
}
typedef Intersect;
Expand Down

0 comments on commit 4ba4a80

Please sign in to comment.