diff --git a/chowdsp_convolution.cpp b/chowdsp_convolution.cpp index 28d41e1..7e5d165 100644 --- a/chowdsp_convolution.cpp +++ b/chowdsp_convolution.cpp @@ -88,16 +88,15 @@ void load_ir (const Config* config, IR_Uniform* ir, const float* ir_data, int ir for (int seg_idx = 0; seg_idx < ir->num_segments; ++seg_idx) { float* segment = get_segment (config, ir->segments, seg_idx); - memcpy (segment, - ir_data + current_ptr, - std::min (config->fft_size - config->block_size, ir_num_samples - current_ptr) * sizeof (float)); + const auto segment_n = std::min (config->fft_size - config->block_size, ir_num_samples - current_ptr); + memcpy (segment, ir_data + current_ptr, segment_n * sizeof (float)); + memset (segment + segment_n, 0, (config->fft_size - segment_n) * sizeof (float)); fft::fft_transform_unordered (config->fft, segment, segment, fft_scratch, fft::FFT_FORWARD); - - current_ptr += config->fft_size - config->block_size; + current_ptr += segment_n; } } @@ -129,6 +128,7 @@ void load_multichannel_ir (const Config* config, IR_Uniform* ir, const float* co { assert (num_channels == ir->num_channels); + int new_num_segments = 0; for (int ch = 0; ch < num_channels; ++ch) { IR_Uniform this_channel_ir { @@ -138,7 +138,9 @@ void load_multichannel_ir (const Config* config, IR_Uniform* ir, const float* co .num_channels = 1, }; load_ir (config, &this_channel_ir, ir_data[ch], ir_num_samples, fft_scratch); + new_num_segments = this_channel_ir.num_segments; } + ir->num_segments = new_num_segments; } //================================================================================================================ @@ -214,6 +216,18 @@ void reset_process_state (const Config* config, Process_Uniform_State* state) } } +void reset_process_state_segments (const Convolution_Config* config, Process_Uniform_State* state, const IR_Uniform* ir) +{ + const auto segment_num_samples = config->fft_size; + for (int ch = 0; ch < state->num_channels; ++ch) + { + auto& state_data = state->state_data[ch]; + memset (state_data.segments + segment_num_samples * ir->num_segments, + 0, + segment_num_samples * (state->max_num_segments - ir->num_segments) * sizeof (float)); + } +} + void destroy_process_state (Process_Uniform_State* state) { if (state->state_data != nullptr) diff --git a/chowdsp_convolution.h b/chowdsp_convolution.h index 2f0e0f9..738cc38 100644 --- a/chowdsp_convolution.h +++ b/chowdsp_convolution.h @@ -142,6 +142,9 @@ void create_multichannel_process_state (const struct Convolution_Config*, const /** Zeros the process state. */ void reset_process_state (const struct Convolution_Config*, struct Process_Uniform_State*); +/** Zeros the process state. */ +void reset_process_state_segments (const struct Convolution_Config*, struct Process_Uniform_State*, const struct IR_Uniform*); + /** De-allocates the state's internal data. */ void destroy_process_state (struct Process_Uniform_State*);