Skip to content

Commit

Permalink
Do not panic if it is possible to recover
Browse files Browse the repository at this point in the history
Signed-off-by: Petr Horacek <petr@zlosynth.com>
  • Loading branch information
phoracek committed Nov 10, 2023
1 parent 1b619d0 commit 0d047cf
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
6 changes: 6 additions & 0 deletions dsp/src/wow_flutter/flutter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ impl Pops {
fn friction(&self) -> f32 {
let phase = self.phase.fract();

// NOTE: Unwrap is unreachable. Tick moves phase. If phase is above
// the amount of pops, `tick` would return `None` and it won't be
// queried for friction.
let intensity = self.pops[(self.phase * 0.96) as usize]
.as_ref()
.unwrap()
Expand All @@ -167,6 +170,9 @@ impl Pops {
fn tick(mut self, sample_rate: f32) -> Option<Self> {
let breaking = self.phase.fract() < 0.5;
let slowdown_coefficient = if breaking {
// NOTE: Unwrap is unreachable. Tick moves phase. If phase is above
// the amount of pops, `tick` would return `None` and it won't be
// queried for friction.
self.pops[(self.phase * 0.95) as usize]
.as_ref()
.unwrap()
Expand Down
19 changes: 5 additions & 14 deletions firmware/src/bin/firmware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,7 @@ mod app {
reaction = Some(processor.process(buffer, randomizer));
});

processor_reaction_producer
.enqueue(reaction.unwrap())
.ok()
.unwrap();
let _ = processor_reaction_producer.enqueue(reaction.unwrap());
}

#[task(
Expand All @@ -279,10 +276,7 @@ mod app {

inputs.sample();

input_snapshot_producer
.enqueue(inputs.snapshot())
.ok()
.unwrap();
let _ = input_snapshot_producer.enqueue(inputs.snapshot());
}

#[task(
Expand Down Expand Up @@ -316,12 +310,9 @@ mod app {
if let Some(snapshot) = dequeue_last(input_snapshot_consumer) {
let result = control.apply_input_snapshot(snapshot);
if let Some(save) = result.save {
save_producer.enqueue(save).ok().unwrap();
let _ = save_producer.enqueue(save);
}
processor_attributes_producer
.enqueue(result.dsp_attributes)
.ok()
.unwrap();
let _ = processor_attributes_producer.enqueue(result.dsp_attributes);
}

let desired_output = control.tick();
Expand Down Expand Up @@ -362,7 +353,7 @@ mod app {

cx.shared.save_cache.lock(|save_cache| {
if let Some(save) = save_cache.take() {
store::spawn(save).ok().unwrap();
store::spawn(save).unwrap_or_else(|_| defmt::warn!("Failed issuing store request"));
}
});
}
Expand Down
8 changes: 4 additions & 4 deletions firmware/src/system/inputs/cvs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ impl CVs {
pub fn sample(&mut self, adc_1: &mut Adc<ADC1, Enabled>, adc_2: &mut Adc<ADC2, Enabled>) {
adc_1.start_conversion(&mut self.pins.cv_1);
adc_2.start_conversion(&mut self.pins.cv_2);
let sample_1: u32 = block!(adc_1.read_sample()).unwrap();
let sample_2: u32 = block!(adc_2.read_sample()).unwrap();
let sample_1: u32 = block!(adc_1.read_sample()).unwrap_or_default();
let sample_2: u32 = block!(adc_2.read_sample()).unwrap_or_default();

adc_1.start_conversion(&mut self.pins.cv_3);
adc_2.start_conversion(&mut self.pins.cv_4);
let sample_3: u32 = block!(adc_1.read_sample()).unwrap();
let sample_4: u32 = block!(adc_2.read_sample()).unwrap();
let sample_3: u32 = block!(adc_1.read_sample()).unwrap_or_default();
let sample_4: u32 = block!(adc_2.read_sample()).unwrap_or_default();

self.cv[0].set(sample_1, adc_1.slope());
self.cv[1].set(sample_2, adc_2.slope());
Expand Down
6 changes: 3 additions & 3 deletions firmware/src/system/inputs/pots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ impl Pots {
) -> (f32, f32, f32) {
adc_1.start_conversion(&mut self.pins.multiplexer_1);
adc_2.start_conversion(&mut self.pins.multiplexer_2);
let sample_1: u32 = block!(adc_1.read_sample()).unwrap();
let sample_2: u32 = block!(adc_2.read_sample()).unwrap();
let sample_1: u32 = block!(adc_1.read_sample()).unwrap_or_default();
let sample_2: u32 = block!(adc_2.read_sample()).unwrap_or_default();

adc_1.start_conversion(&mut self.pins.multiplexer_3);
let sample_3: u32 = block!(adc_1.read_sample()).unwrap();
let sample_3: u32 = block!(adc_1.read_sample()).unwrap_or_default();

(
transpose_adc(sample_1, adc_1.slope()),
Expand Down
5 changes: 4 additions & 1 deletion firmware/src/system/randomizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ impl Randomizer {
impl Random for Randomizer {
#[allow(clippy::cast_lossless)]
fn normal(&mut self) -> f32 {
RngCore::<u16>::gen(&mut self.rng).unwrap() as f32 / (2 << 15) as f32
match RngCore::<u16>::gen(&mut self.rng) {
Ok(x) => x as f32 / (2 << 15) as f32,
Err(_) => 0.0,
}
}
}

0 comments on commit 0d047cf

Please sign in to comment.