Skip to content

Commit 2d92fb9

Browse files
Fixes for multichannel IR processing (#8)
1 parent 27aaead commit 2d92fb9

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

chowdsp_convolution.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,15 @@ void load_ir (const Config* config, IR_Uniform* ir, const float* ir_data, int ir
8888
for (int seg_idx = 0; seg_idx < ir->num_segments; ++seg_idx)
8989
{
9090
float* segment = get_segment (config, ir->segments, seg_idx);
91-
memcpy (segment,
92-
ir_data + current_ptr,
93-
std::min (config->fft_size - config->block_size, ir_num_samples - current_ptr) * sizeof (float));
91+
const auto segment_n = std::min (config->fft_size - config->block_size, ir_num_samples - current_ptr);
92+
memcpy (segment, ir_data + current_ptr, segment_n * sizeof (float));
93+
memset (segment + segment_n, 0, (config->fft_size - segment_n) * sizeof (float));
9494
fft::fft_transform_unordered (config->fft,
9595
segment,
9696
segment,
9797
fft_scratch,
9898
fft::FFT_FORWARD);
99-
100-
current_ptr += config->fft_size - config->block_size;
99+
current_ptr += segment_n;
101100
}
102101
}
103102

@@ -129,6 +128,7 @@ void load_multichannel_ir (const Config* config, IR_Uniform* ir, const float* co
129128
{
130129
assert (num_channels == ir->num_channels);
131130

131+
int new_num_segments = 0;
132132
for (int ch = 0; ch < num_channels; ++ch)
133133
{
134134
IR_Uniform this_channel_ir {
@@ -138,7 +138,9 @@ void load_multichannel_ir (const Config* config, IR_Uniform* ir, const float* co
138138
.num_channels = 1,
139139
};
140140
load_ir (config, &this_channel_ir, ir_data[ch], ir_num_samples, fft_scratch);
141+
new_num_segments = this_channel_ir.num_segments;
141142
}
143+
ir->num_segments = new_num_segments;
142144
}
143145

144146
//================================================================================================================
@@ -214,6 +216,18 @@ void reset_process_state (const Config* config, Process_Uniform_State* state)
214216
}
215217
}
216218

219+
void reset_process_state_segments (const Convolution_Config* config, Process_Uniform_State* state, const IR_Uniform* ir)
220+
{
221+
const auto segment_num_samples = config->fft_size;
222+
for (int ch = 0; ch < state->num_channels; ++ch)
223+
{
224+
auto& state_data = state->state_data[ch];
225+
memset (state_data.segments + segment_num_samples * ir->num_segments,
226+
0,
227+
segment_num_samples * (state->max_num_segments - ir->num_segments) * sizeof (float));
228+
}
229+
}
230+
217231
void destroy_process_state (Process_Uniform_State* state)
218232
{
219233
if (state->state_data != nullptr)

chowdsp_convolution.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ void create_multichannel_process_state (const struct Convolution_Config*, const
142142
/** Zeros the process state. */
143143
void reset_process_state (const struct Convolution_Config*, struct Process_Uniform_State*);
144144

145+
/** Zeros the process state. */
146+
void reset_process_state_segments (const struct Convolution_Config*, struct Process_Uniform_State*, const struct IR_Uniform*);
147+
145148
/** De-allocates the state's internal data. */
146149
void destroy_process_state (struct Process_Uniform_State*);
147150

0 commit comments

Comments
 (0)