Skip to content

Commit e267578

Browse files
committed
Remove un-needed mutex, up the latency
1 parent 132726d commit e267578

4 files changed

Lines changed: 14 additions & 21 deletions

File tree

presets/metal.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"gain": 2.0,
2+
"gain": 5.0,
33
"drive": 50.0,
44
"gate_threshold": 0.02,
55
"lowpass_cutoff": 6000.0,
66
"highpass_cutoff": 120.0,
7-
"mode": "Polynomial",
8-
"level": 0.5
7+
"mode": "DiodeLike",
8+
"level": 1
99
}

src/amp.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,14 @@ impl Amp {
103103
DistortionMode::WaveFold => foldback(gated, 1.0),
104104
};
105105

106-
// Highpass filter (removing DC or very low freq)
107106
let highpassed =
108107
self.highpass_alpha * (self.highpass_prev + distorted - self.distorted_prev);
109108
self.distorted_prev = distorted;
110109
self.highpass_prev = highpassed;
111110

112-
// Lowpass filter (smooth out harshness at very high freq)
113111
let filtered = self.lowpass_prev + self.lowpass_alpha * (highpassed - self.lowpass_prev);
114112
self.lowpass_prev = filtered;
115113

116-
// Apply final level
117114
filtered * self.level
118115
}
119116
}

src/main.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::io::BufReader;
55
use std::{
66
env,
77
sync::{
8-
Arc, Mutex,
8+
Arc,
99
atomic::{AtomicBool, Ordering},
1010
},
1111
thread,
@@ -34,7 +34,7 @@ struct Args {
3434

3535
fn main() {
3636
unsafe {
37-
env::set_var("PIPEWIRE_LATENCY", "64/48000");
37+
env::set_var("PIPEWIRE_LATENCY", "128/48000");
3838
env::set_var("JACK_PROMISCUOUS_SERVER", "pipewire");
3939
}
4040

@@ -57,8 +57,7 @@ fn main() {
5757
let sample_rate = client.sample_rate() as f32;
5858
let amp = Amp::new(config, sample_rate);
5959

60-
let amp = Arc::new(Mutex::new(amp));
61-
let (processor, writer) = Processor::new(&client, Arc::clone(&amp), recording);
60+
let (processor, writer) = Processor::new(&client, amp, recording);
6261
let process = processor.into_process_handler();
6362

6463
let _active_client = client

src/processor.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ use rubato::{
66
};
77
use std::fs::File;
88
use std::io::BufWriter;
9-
use std::sync::{Arc, Mutex, MutexGuard};
9+
use std::sync::{Arc, Mutex};
1010

1111
pub type RecordingWriter = Option<Arc<Mutex<Option<WavWriter<BufWriter<File>>>>>>;
1212

1313
pub struct Processor {
14-
amp: Arc<Mutex<Amp>>,
14+
amp: Amp,
1515
writer: RecordingWriter,
1616
in_port: Port<AudioIn>,
1717
out_l: Port<AudioOut>,
@@ -21,7 +21,7 @@ pub struct Processor {
2121
}
2222

2323
impl Processor {
24-
pub fn new(client: &Client, amp: Arc<Mutex<Amp>>, recording: bool) -> (Self, RecordingWriter) {
24+
pub fn new(client: &Client, amp: Amp, recording: bool) -> (Self, RecordingWriter) {
2525
let in_port = client.register_port("in", AudioIn).unwrap();
2626
let out_l = client.register_port("out_l", AudioOut).unwrap();
2727
let out_r = client.register_port("out_r", AudioOut).unwrap();
@@ -53,7 +53,7 @@ impl Processor {
5353
let channels = 1;
5454
let oversample_factor: f32 = 2.0;
5555

56-
let max_chunk_size = 64;
56+
let max_chunk_size = 128;
5757

5858
let interp_params = SincInterpolationParameters {
5959
sinc_len: 256,
@@ -106,7 +106,7 @@ impl Processor {
106106
self,
107107
) -> impl FnMut(&Client, &ProcessScope) -> Control + Send + 'static {
108108
let Processor {
109-
amp,
109+
mut amp,
110110
writer,
111111
in_port,
112112
mut out_l,
@@ -137,12 +137,9 @@ impl Processor {
137137
eprintln!("Upsampler returned an empty buffer");
138138
}
139139

140-
{
141-
let mut amp_guard: MutexGuard<'_, Amp> = amp.lock().unwrap();
142-
let upsampled_channel = &mut upsampled[0];
143-
for sample in upsampled_channel.iter_mut() {
144-
*sample = amp_guard.process_sample(*sample);
145-
}
140+
let upsampled_channel = &mut upsampled[0];
141+
for sample in upsampled_channel.iter_mut() {
142+
*sample = amp.process_sample(*sample);
146143
}
147144

148145
let downsampled = match downsampler.process(&upsampled, None) {

0 commit comments

Comments
 (0)