RustAudio / dasp

The fundamentals for Digital Audio Signal Processing. Formerly `sample`.
Other
867 stars 63 forks source link

[Question] What is the Rusty way to make an additive synth with dasp? #165

Open gcentauri opened 2 years ago

gcentauri commented 2 years ago

Hello all!

This is a question for anyone who may have some suggestions. I have a decent understanding of DSP, but I'm very new to Rust. I'm probably getting ahead of myself trying to learn it with digital audio, but its what is inspiring me to learn Rust so here i am.

I'd like to build an example additive synth, with as many Sine oscillators as I can handle. Ideally, I'd like to have a function to call where I could have a base frequency and N partials as some multiple of the base.

So far I can do this in a naive way by hard coding in each sine wave and then using add_amp to sum them all together like so:

sine_0.add_amp(sine_1).add_amp(sine_2). ... .add_amp(sine_N)

but this isn't very nice and it isn't flexible. I'm looking for a way to do something like

sines.reduce(|acc, sine| acc.add_amp(sine))

but I can't seem to figure out how to manage the types.

Perhaps I'm going about this the wrong way?

Any input would be welcome, and if there's a better forum than an issue on this repo I'm happy to move the discussion elsewhere.

Thank you!

chaosprint commented 2 years ago

I would suggest you check the dasp graph module in this repo. Build a sine node, put two of the sine nodes in a graph. Then you are ready to go. Both OOP or FP either do not work well or hard to implement. You can check on my project Glicol to see how dasp graph is used: https://github.com/chaosprint/glicol

gcentauri commented 2 years ago

@chaosprint - thanks for the feedback. i was aiming to learn a bit by digging as low-level as I dared, but I see what you're saying. Glicol looks cool!