From c58b327c5405d84c04eee10b2c9a626192a14285 Mon Sep 17 00:00:00 2001 From: sigil-03 Date: Tue, 28 Oct 2025 18:58:43 -0600 Subject: [PATCH] some more fiddling --- ch32v-insert-coin/audio/sequences | 18 ++++++++++++++++++ ch32v-insert-coin/ext/wavetable-synth | 2 +- ch32v-insert-coin/src/main.rs | 19 +++++++++++++++---- ch32v-insert-coin/src/synthesizer.rs | 9 +++++---- 4 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 ch32v-insert-coin/audio/sequences diff --git a/ch32v-insert-coin/audio/sequences b/ch32v-insert-coin/audio/sequences new file mode 100644 index 0000000..edef1a1 --- /dev/null +++ b/ch32v-insert-coin/audio/sequences @@ -0,0 +1,18 @@ +"wahwahwahwah" sound - let play a few times +note timing: 6hz +data: let freqs = [100, 200, 300, 400, 500, 600, 700, 800, 900]; + +"falling" sound +note timing: 6hz +[ +1000, +990, 980, 970, 960, 950, 940, 930, 920, 910, 900, +890, 880, 870, 860, 850, 840, 830, 820, 810, 800, +790, 780, 770, 760, 750, 740, 730, 720, 710, 700, +690, 680, 670, 660, 650, 640, 630, 620, 610, 600, +590, 580, 570, 560, 550, 540, 530, 520, 510, 500, +490, 480, 470, 460, 450, 440, 430, 420, 410, 400, +390, 380, 370, 360, 350, 340, 330, 320, 310, 300, +290, 280, 270, 260, 250, 240, 230, 220, 210, 200, +190, 180, 170, 160, 150, 140, 130, 120, 110, 100, +] diff --git a/ch32v-insert-coin/ext/wavetable-synth b/ch32v-insert-coin/ext/wavetable-synth index aa57096..e6ca9c7 160000 --- a/ch32v-insert-coin/ext/wavetable-synth +++ b/ch32v-insert-coin/ext/wavetable-synth @@ -1 +1 @@ -Subproject commit aa57096e4b560ee4f65149ddf5ef6c4c8f82e4ce +Subproject commit e6ca9c7ed8b9af193333be793983df5e48cb961a diff --git a/ch32v-insert-coin/src/main.rs b/ch32v-insert-coin/src/main.rs index 1bcb438..ed5e986 100644 --- a/ch32v-insert-coin/src/main.rs +++ b/ch32v-insert-coin/src/main.rs @@ -253,7 +253,7 @@ fn SysTick() { NOTE_TICK_FLAG = true; } - if SYSTICK_COUNT % 5000 == 0 { + if SYSTICK_COUNT % 50000 == 0 { TICK_FLAG = true; // if let Some(ref mut led) = LED { // let toggle = TOGGLE_COUNT; @@ -317,7 +317,7 @@ fn debug_main(mut p: hal::Peripherals) -> ! { riscv::asm::delay(20_000_000); println!("post2"); - let tick_rate_hz = 50000; // 50khz + let tick_rate_hz = 100000; // 50khz // DAC output setup let dac_pin = PwmPin::new_ch4::<0>(p.PC4); @@ -330,7 +330,7 @@ fn debug_main(mut p: hal::Peripherals) -> ! { None, None, Some(dac_pin), - Hertz::khz(200), + Hertz::khz(500), CountingMode::default(), ); @@ -363,7 +363,16 @@ fn debug_main(mut p: hal::Peripherals) -> ! { } let mut index = 0; - let freqs = [110, 440]; + let freqs = [1567, 1396, 1318, 1174, 1046, 987, 880, 783, 698]; + // let freqs = [100, 200, 300, 400, 500, 600, 700, 800, 900]; + // let freqs = [ + // 1000, 990, 980, 970, 960, 950, 940, 930, 920, 910, 900, 890, 880, 870, 860, 850, 840, 830, + // 820, 810, 800, 790, 780, 770, 760, 750, 740, 730, 720, 710, 700, 690, 680, 670, 660, 650, + // 640, 630, 620, 610, 600, 590, 580, 570, 560, 550, 540, 530, 520, 510, 500, 490, 480, 470, + // 460, 450, 440, 430, 420, 410, 400, 390, 380, 370, 360, 350, 340, 330, 320, 310, 300, 290, + // 280, 270, 260, 250, 240, 230, 220, 210, 200, 190, 180, 170, 160, 150, 140, 130, 120, 110, + // 100, + // ]; loop { if flag() { @@ -377,6 +386,8 @@ fn debug_main(mut p: hal::Peripherals) -> ! { if note_flag() { clear_note_flag(); synth.square.set_freq(freqs[index]); + // println!("{}", { freqs[index] }); + // println!("{}", freqs[index]); index += 1; if index > freqs.len() - 1 { index = 0; diff --git a/ch32v-insert-coin/src/synthesizer.rs b/ch32v-insert-coin/src/synthesizer.rs index bc2aec6..ad265c1 100644 --- a/ch32v-insert-coin/src/synthesizer.rs +++ b/ch32v-insert-coin/src/synthesizer.rs @@ -3,10 +3,11 @@ use ch32_hal::println; use ch32_hal::timer::GeneralInstance16bit; use wavetable_synth::{synthesizer::SimpleWavetableSynthesizer, wavetable::SimpleWavetable}; -const SQUARE_WAVETABLE: [u8; 32] = [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 100, 100, 100, 100, 100, 100, 100, 100, - 100, 100, 100, 100, 100, 100, 100, -]; +const SQUARE_WAVETABLE: [u8; 2] = [0, 100]; +// const SQUARE_WAVETABLE: [u8; 32] = [ +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 100, 100, 100, 100, 100, 100, 100, 100, +// 100, 100, 100, 100, 100, 100, 100, +// ]; pub struct AppSynthesizers<'a, T: GeneralInstance16bit> { pub square: SimpleWavetableSynthesizer>,