Skip to content

Commit 3a6b749

Browse files
committed
wip GR graph
1 parent 8484479 commit 3a6b749

File tree

1 file changed

+70
-47
lines changed

1 file changed

+70
-47
lines changed

src/lib.rs

+70-47
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub struct Lamb {
2222
params: Arc<LambParams>,
2323
dsp: Box<dsp::LambRs>,
2424
accum_buffer: TempBuffer,
25+
// gr_buffer: TempBuffer,
2526
temp_output_buffer_l: Box<[f64]>,
2627
temp_output_buffer_r: Box<[f64]>,
2728
temp_output_buffer_gr_l: Box<[f64]>,
@@ -56,6 +57,7 @@ impl Default for Lamb {
5657
dsp: dsp::LambRs::default_boxed(),
5758

5859
accum_buffer: TempBuffer::default(),
60+
// gr_buffer: TempBuffer::default(),
5961

6062
temp_output_buffer_l : f64::default_boxed_array::<MAX_SOUNDCARD_BUFFER_SIZE>(),
6163
temp_output_buffer_r : f64::default_boxed_array::<MAX_SOUNDCARD_BUFFER_SIZE>(),
@@ -121,6 +123,7 @@ impl Plugin for Lamb {
121123
// function if you do not need it.
122124
self.dsp.init(buffer_config.sample_rate as i32);
123125
self.accum_buffer.resize(2, MAX_SOUNDCARD_BUFFER_SIZE);
126+
// self.gr_buffer.resize(2, MAX_SOUNDCARD_BUFFER_SIZE);
124127

125128
// After `PEAK_METER_DECAY_MS` milliseconds of pure silence, the peak meter's value should
126129
// have dropped by 12 dB
@@ -199,13 +202,22 @@ impl Plugin for Lamb {
199202
.expect("no GR read") as f32,
200203
std::sync::atomic::Ordering::Relaxed,
201204
);
202-
self.peak_buffer
203-
.lock()
204-
.unwrap()
205-
.enqueue_buffer(buffer, None);
206205
}
207-
208206
let output = buffer.as_slice();
207+
208+
let mut gr_buffer = Buffer::default();
209+
210+
let mut real_buffers = vec![vec![0.0; MAX_SOUNDCARD_BUFFER_SIZE]; 2];
211+
212+
unsafe {
213+
gr_buffer.set_slices(MAX_SOUNDCARD_BUFFER_SIZE, |output_slices| {
214+
let (first_channel, other_channels) = real_buffers.split_at_mut(1);
215+
*output_slices = vec![&mut first_channel[0], &mut other_channels[0]];
216+
})
217+
};
218+
219+
let gr_output = gr_buffer.as_slice();
220+
209221
let bypass: f64 = match self.params.bypass.value() {
210222
true => 1.0,
211223
false => 0.0,
@@ -218,52 +230,63 @@ impl Plugin for Lamb {
218230
};
219231
self.dsp.set_param(LATENCY_MODE_PI, latency_mode);
220232
self.dsp
221-
.set_param(INPUT_GAIN_PI, self.params.input_gain.value() as f64);
222-
self.dsp
223-
.set_param(STRENGTH_PI, self.params.strength.value() as f64);
224-
self.dsp
225-
.set_param(THRESH_PI, self.params.thresh.value() as f64);
226-
self.dsp
227-
.set_param(ATTACK_PI, self.params.attack.value() as f64);
228-
self.dsp
229-
.set_param(ATTACK_SHAPE_PI, self.params.attack_shape.value() as f64);
230-
self.dsp
231-
.set_param(RELEASE_PI, self.params.release.value() as f64);
232-
self.dsp
233-
.set_param(RELEASE_SHAPE_PI, self.params.release_shape.value() as f64);
234-
self.dsp
235-
.set_param(RELEASE_HOLD_PI, self.params.release_hold.value() as f64);
236-
self.dsp.set_param(KNEE_PI, self.params.knee.value() as f64);
237-
self.dsp.set_param(LINK_PI, self.params.link.value() as f64);
238-
self.dsp.set_param(
239-
ADAPTIVE_RELEASE_PI,
240-
self.params.adaptive_release.value() as f64,
241-
);
242-
self.dsp
243-
.set_param(LOOKAHEAD_PI, self.params.lookahead.value() as f64);
244-
self.dsp
245-
.set_param(OUTPUT_GAIN_PI, self.params.output_gain.value() as f64);
246-
247-
self.dsp.compute(
248-
count,
249-
&self.accum_buffer.slice2d(),
250-
&mut [
251-
&mut self.temp_output_buffer_l,
252-
&mut self.temp_output_buffer_r,
253-
&mut self.temp_output_buffer_gr_l,
254-
&mut self.temp_output_buffer_gr_r,
255-
],
256-
);
233+
.set_param(INPUT_GAIN_PI, self.params.input_gain.value() as f64);
234+
self.dsp
235+
.set_param(STRENGTH_PI, self.params.strength.value() as f64);
236+
self.dsp
237+
.set_param(THRESH_PI, self.params.thresh.value() as f64);
238+
self.dsp
239+
.set_param(ATTACK_PI, self.params.attack.value() as f64);
240+
self.dsp
241+
.set_param(ATTACK_SHAPE_PI, self.params.attack_shape.value() as f64);
242+
self.dsp
243+
.set_param(RELEASE_PI, self.params.release.value() as f64);
244+
self.dsp
245+
.set_param(RELEASE_SHAPE_PI, self.params.release_shape.value() as f64);
246+
self.dsp
247+
.set_param(RELEASE_HOLD_PI, self.params.release_hold.value() as f64);
248+
self.dsp.set_param(KNEE_PI, self.params.knee.value() as f64);
249+
self.dsp.set_param(LINK_PI, self.params.link.value() as f64);
250+
self.dsp.set_param(
251+
ADAPTIVE_RELEASE_PI,
252+
self.params.adaptive_release.value() as f64,
253+
);
254+
self.dsp
255+
.set_param(LOOKAHEAD_PI, self.params.lookahead.value() as f64);
256+
self.dsp
257+
.set_param(OUTPUT_GAIN_PI, self.params.output_gain.value() as f64);
258+
259+
self.dsp.compute(
260+
count,
261+
&self.accum_buffer.slice2d(),
262+
&mut [
263+
&mut self.temp_output_buffer_l,
264+
&mut self.temp_output_buffer_r,
265+
&mut self.temp_output_buffer_gr_l,
266+
&mut self.temp_output_buffer_gr_r,
267+
],
268+
);
269+
270+
for i in 0..count as usize {
271+
output[0][i] = self.temp_output_buffer_l[i] as f32;
272+
output[1][i] = self.temp_output_buffer_r[i] as f32;
273+
gr_output[0][i] = self.temp_output_buffer_gr_l[i] as f32;
274+
gr_output[1][i] = self.temp_output_buffer_gr_r[i] as f32;
275+
}
257276

258-
for i in 0..count as usize {
259-
output[0][i] = self.temp_output_buffer_l[i] as f32;
260-
output[1][i] = self.temp_output_buffer_r[i] as f32;
277+
// To save resources, a plugin can (and probably should!) only perform expensive
278+
// calculations that are only displayed on the GUI while the GUI is open
279+
if self.params.editor_state.is_open() {
280+
self.peak_buffer
281+
.lock()
282+
.unwrap()
283+
.enqueue_buffer(&mut gr_buffer, None);
261284
}
262285

263-
let latency_samples = self.dsp.get_param(LATENCY_PI).expect("no latency read") as u32;
264-
context.set_latency_samples(latency_samples);
286+
let latency_samples = self.dsp.get_param(LATENCY_PI).expect("no latency read") as u32;
287+
context.set_latency_samples(latency_samples);
265288

266-
ProcessStatus::Normal
289+
ProcessStatus::Normal
267290
}
268291
}
269292

0 commit comments

Comments
 (0)