use systick event system to drive synthesis
This commit is contained in:
parent
58579ae6c2
commit
0836fc58df
4 changed files with 229 additions and 31 deletions
|
|
@ -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<SimpleWavetable<'static, u8>>,
|
||||
|
|
@ -21,11 +22,30 @@ impl<'a, T: GeneralInstance16bit> AppSynthesizers<'a, T> {
|
|||
Self { square, output }
|
||||
}
|
||||
|
||||
pub fn service(&mut self) {
|
||||
pub fn tick(&mut self) {
|
||||
self.square.tick();
|
||||
if self.square.has_new_output() {
|
||||
let out = self.square.get_output();
|
||||
// println!("OUTPUT: {out}");
|
||||
|
||||
// println!("new out");
|
||||
self.output.write_amplitude(
|
||||
ch32_hal::timer::Channel::Ch4,
|
||||
out / 2,
|
||||
// (out as f32 * (u8::MAX as f32 / u32::MAX as f32)) as u8,
|
||||
);
|
||||
}
|
||||
|
||||
// println!("{}{}", self.square.counter, self.square.has_new_output());
|
||||
}
|
||||
|
||||
pub fn service(&mut self) {
|
||||
// println!("HERE");
|
||||
if self.square.has_new_output() {
|
||||
let out = self.square.get_output();
|
||||
// println!("OUTPUT: {out}");
|
||||
|
||||
// println!("new out");
|
||||
self.output.write_amplitude(
|
||||
ch32_hal::timer::Channel::Ch4,
|
||||
out / 2,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue