Skip to content

Commit

Permalink
tweakable grain size, fix midi, lpf closed on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
vk2seb committed Dec 13, 2023
1 parent 1691bb5 commit c384a12
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
6 changes: 6 additions & 0 deletions firmware/polyvec-hal/src/gw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub trait WavetableOscillator {
pub trait PitchShift {
fn set_pitch(&self, value: FixedI32<U16>);
fn pitch(&self) -> FixedI32<U16>;
fn set_window_sz(&self, value: u16);
}

pub trait KarlsenLpf {
Expand Down Expand Up @@ -132,6 +133,11 @@ macro_rules! pitch_shift {
fn pitch(&self) -> FixedI32<U16> {
FixedI32::<U16>::from_bits(self.csr_pitch().read().bits() as i32)
}
fn set_window_sz(&self, value: u16) {
unsafe {
self.csr_window_sz().write(|w| w.csr_window_sz().bits(value));
}
}
})+
};
}
Expand Down
14 changes: 7 additions & 7 deletions firmware/polyvec-lib/src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub struct AdsrOptions {
#[derive(Clone)]
pub struct ScopeOptions {
pub selected: Option<usize>,
pub delay_len: NumOption<u32>,
pub grain_sz: NumOption<u32>,
pub trig_lvl: NumOption<i32>,
pub trig_sns: NumOption<i32>,
}
Expand Down Expand Up @@ -110,7 +110,7 @@ impl_option_view!(AdsrOptions,
attack_ms, decay_ms, release_ms, resonance);

impl_option_view!(ScopeOptions,
delay_len, trig_lvl, trig_sns);
grain_sz, trig_lvl, trig_sns);

impl_option_view!(TouchOptions,
note_control, led_mirror);
Expand Down Expand Up @@ -167,12 +167,12 @@ impl Options {
},
scope: ScopeOptions {
selected: None,
delay_len: NumOption{
name: "delayln".into(),
value: 511,
grain_sz: NumOption{
name: "grainsz".into(),
value: 1023,
step: 1,
min: 128,
max: 511,
min: 512,
max: 1023,
},
trig_lvl: NumOption{
name: "trig lvl".into(),
Expand Down
12 changes: 5 additions & 7 deletions firmware/polyvec/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,20 +253,19 @@ impl State {
}
}

/*
if opts.touch.note_control.value == opt::NoteControl::Midi {
while let Ok(event) = self.midi_in.read() {
self.voice_manager.event(event, uptime_ms);
}
self.voice_manager.tick(uptime_ms, opts);
for n_voice in 0..N_VOICES {
let voice = &self.voice_manager.voices[n_voice];
shifter[n_voice].set_pitch(voice.pitch);
lpf[n_voice].set_cutoff((voice.amplitude * 8000f32) as i16);
lpf[n_voice].set_resonance(opts.adsr.resonance.value);
shifter[n_voice].set_pitch(FixedI32::<U16>::from_num(voice.pitch));
shifter[n_voice].set_window_sz(opts.scope.grain_sz.value as u16);
lpf[n_voice].set_cutoff(FixedI32::<U16>::from_num(voice.amplitude));
lpf[n_voice].set_resonance(FixedI32::<U16>::from_num(0));
}
} else {
*/
let pmod1 = &peripherals.EURORACK_PMOD1;
let pmod2 = &peripherals.EURORACK_PMOD2;
let pmod3 = &peripherals.EURORACK_PMOD3;
Expand Down Expand Up @@ -302,6 +301,7 @@ impl State {
let ampl = (touch_raw as f32) / 256.0f32;
let pitch = note_to_pitch(midi_note);
shifter[n_voice].set_pitch(FixedI32::<U16>::from_num(pitch));
shifter[n_voice].set_window_sz(opts.scope.grain_sz.value as u16);

// Low-pass filter to smooth touch on/off
let ampl_old: f32 = lpf[n_voice].cutoff().to_num();
Expand Down Expand Up @@ -351,9 +351,7 @@ impl State {
update_hw_voice(n_voice, voices_old[n_voice].note, 0);
}
}
/*
}
*/

self.last_control_type = Some(opts.touch.note_control.value);
}
Expand Down
2 changes: 1 addition & 1 deletion rtl/dsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ def __init__(self, n_lpfs=2):

class LpfDecorator(Module, AutoCSR):
def __init__(self, lpf, dw=32):
self.csr_g = CSRStorage(dw, reset=Constant(float_to_fp(1.0), (32, True)))
self.csr_g = CSRStorage(dw, reset=Constant(float_to_fp(0.0), (32, True)))
self.csr_resonance = CSRStorage(dw, reset=Constant(float_to_fp(0.0), (32, True)))
self.comb += [
lpf.g.eq(self.csr_g.storage),
Expand Down

0 comments on commit c384a12

Please sign in to comment.