Skip to content

Commit

Permalink
integrated into SoC and compiles
Browse files Browse the repository at this point in the history
  • Loading branch information
vk2seb committed Dec 12, 2023
1 parent da902c4 commit 06604f1
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 82 deletions.
17 changes: 2 additions & 15 deletions example-colorlight-i5.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from rtl.dsp_wrapper import *
from rtl.spi_dma import Wishbone2SPIDMA
from rtl.dma_router import *
from rtl.dsp import create_voices

_io_eurolut_proto1 = [
("eurorack_pmod_clk0", 0,
Expand Down Expand Up @@ -122,21 +123,7 @@ def into_shifter(soc, eurorack_pmod):

N_VOICES = 4

for voice in range(N_VOICES):
pitch_shift = PitchShift(soc.platform)
lpf = KarlsenLowPass(soc.platform)
dc_block = DcBlock(soc.platform)

soc.comb += [
pitch_shift.sample_in.eq(eurorack_pmod.cal_in0),
lpf.sample_in.eq(pitch_shift.sample_out),
dc_block.sample_in.eq(lpf.sample_out),
getattr(eurorack_pmod, f"cal_out{voice}").eq(dc_block.sample_out),
]

soc.add_module(f"pitch_shift{voice}", pitch_shift)
soc.add_module(f"karlsen_lpf{voice}", lpf)
soc.add_module(f"dc_block{voice}", dc_block)
create_voices(soc, eurorack_pmod, N_VOICES)

add_dma_router(soc, eurorack_pmod, output_capable=False)

Expand Down
41 changes: 41 additions & 0 deletions firmware/polyboot/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions firmware/polyvec-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ paste = "1.0.14"
riscv = { version = "0.10.1", features = ["critical-section-single-hart"] }
riscv-rt = { path = "../deps/riscv-rt", features = ["single-hart"] }
vexriscv = "0.0.3"
fixed = "1.24.0"

[profile.release]
lto = true
Expand Down
44 changes: 17 additions & 27 deletions firmware/polyvec-hal/src/gw.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![allow(unused_macros)]

use fixed::{FixedI32, types::extra::U16};

use litex_hal::prelude::*;
use litex_pac as pac;
use litex_hal::uart::UartError;
Expand All @@ -25,14 +27,14 @@ pub trait WavetableOscillator {
}

pub trait PitchShift {
fn set_pitch(&self, value: i16);
fn pitch(&self) -> i16;
fn set_pitch(&self, value: FixedI32<U16>);
fn pitch(&self) -> FixedI32<U16>;
}

pub trait KarlsenLpf {
fn set_cutoff(&self, value: i16);
fn cutoff(&self) -> i16;
fn set_resonance(&self, value: i16);
fn set_cutoff(&self, value: FixedI32<U16>);
fn cutoff(&self) -> FixedI32<U16>;
fn set_resonance(&self, value: FixedI32<U16>);
}

macro_rules! eurorack_pmod_reset {
Expand Down Expand Up @@ -119,28 +121,16 @@ macro_rules! eurorack_pmod {
}


macro_rules! wavetable_oscillator {
($($t:ty),+ $(,)?) => {
$(impl WavetableOscillator for $t {
fn set_skip(&self, value: u32) {
unsafe {
self.csr_wavetable_inc().write(|w| w.csr_wavetable_inc().bits(value));
}
}
})+
};
}

macro_rules! pitch_shift {
($($t:ty),+ $(,)?) => {
$(impl PitchShift for $t {
fn set_pitch(&self, value: i16) {
fn set_pitch(&self, value: FixedI32<U16>) {
unsafe {
self.csr_pitch().write(|w| w.csr_pitch().bits(value as u16));
self.csr_pitch().write(|w| w.csr_pitch().bits(value.to_bits() as u32));
}
}
fn pitch(&self) -> i16 {
(self.csr_pitch().read().bits() as u16) as i16
fn pitch(&self) -> FixedI32<U16> {
FixedI32::<U16>::from_bits(self.csr_pitch().read().bits() as i32)
}
})+
};
Expand All @@ -149,17 +139,17 @@ macro_rules! pitch_shift {
macro_rules! karlsen_lpf {
($($t:ty),+ $(,)?) => {
$(impl KarlsenLpf for $t {
fn set_cutoff(&self, value: i16) {
fn set_cutoff(&self, value: FixedI32<U16>) {
unsafe {
self.csr_g().write(|w| w.csr_g().bits(value as u16));
self.csr_g().write(|w| w.csr_g().bits(value.to_bits() as u32));
}
}
fn cutoff(&self) -> i16 {
(self.csr_g().read().bits() as u16) as i16
fn cutoff(&self) -> FixedI32<U16> {
FixedI32::<U16>::from_bits(self.csr_g().read().bits() as i32)
}
fn set_resonance(&self, value: i16) {
fn set_resonance(&self, value: FixedI32<U16>) {
unsafe {
self.csr_resonance().write(|w| w.csr_resonance().bits(value as u16));
self.csr_resonance().write(|w| w.csr_resonance().bits(value.to_bits() as u32));
}
}
})+
Expand Down
42 changes: 42 additions & 0 deletions firmware/polyvec/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions firmware/polyvec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ litex-interrupt = { path = "../deps/litex-interrupt" }
critical-section = "1.1.2"
strum_macros = "0.25.3"
strum = {version = "0.25.0", features = ["derive"], default-features=false}
fixed = "1.24.0"

[profile.release]
lto = true
Expand Down
14 changes: 10 additions & 4 deletions firmware/polyvec/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use core::cell::RefCell;
use critical_section::Mutex;
use irq::{handler, scope, scoped_interrupts};
use litex_interrupt::return_as_is;
use fixed::{FixedI32, types::extra::U16};

use ssd1322 as oled;

Expand Down Expand Up @@ -252,6 +253,7 @@ 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);
Expand All @@ -264,6 +266,7 @@ impl State {
lpf[n_voice].set_resonance(opts.adsr.resonance.value);
}
} else {
*/
let pmod1 = &peripherals.EURORACK_PMOD1;
let pmod2 = &peripherals.EURORACK_PMOD2;
let pmod3 = &peripherals.EURORACK_PMOD3;
Expand Down Expand Up @@ -298,13 +301,14 @@ impl State {
let mut update_hw_voice = |n_voice: usize, midi_note: u8, touch_raw: u8| {
let ampl = (touch_raw as f32) / 256.0f32;
let pitch = note_to_pitch(midi_note);
shifter[n_voice].set_pitch(pitch);
//shifter[n_voice].set_pitch(pitch);
shifter[n_voice].set_pitch(FixedI32::<U16>::from_num(0.0f32));

// Low-pass filter to smooth touch on/off
let ampl_old = (lpf[n_voice].cutoff() as f32) / 8000f32;
let ampl_old: f32 = lpf[n_voice].cutoff().to_num();
let ampl_new = ampl*0.05 + ampl_old*0.95;
lpf[n_voice].set_cutoff((ampl_new * 8000f32) as i16);
lpf[n_voice].set_resonance(opts.adsr.resonance.value);
lpf[n_voice].set_cutoff(FixedI32::<U16>::from_num(ampl_new));
lpf[n_voice].set_resonance(FixedI32::<U16>::from_num(0));

// Push to voice manager to visualizations work
self.voice_manager.voices[n_voice].amplitude = ampl_new;
Expand Down Expand Up @@ -349,7 +353,9 @@ impl State {
}
}

/*
}
*/

self.last_control_type = Some(opts.touch.note_control.value);
}
Expand Down
Loading

0 comments on commit 06604f1

Please sign in to comment.