RustAudio / rodio

Rust audio playback library
Apache License 2.0
1.72k stars 222 forks source link

Quadratic and Sawtooth waves #492

Open anti7447 opened 1 year ago

anti7447 commented 1 year ago

Hello! Tell me, please, is it possible to create quadratic and sawtooth waves? I found only a sine wave in the documentation

smangelsdorf commented 1 year ago

Not part of the official library, but if you'd like an example to work from (or copy verbatim πŸ˜‚) I have a sawtooth wave for a toy project I'm working on.

https://github.com/smangelsdorf/rtttlsynth/blob/fcd7be5908599553b528eaf401731bcf42c02914/src/synth/oscillator.rs

If there's any interest from the project maintainers I'd be happy to tidy this up and PR it as a library feature.

smangelsdorf commented 1 year ago

I was curious, so I looked, but I couldn't find a standard definition for a quadratic wave. What do you have in mind for that?

I imagine it being something like this, but I could be way off πŸ˜…

image

anti7447 commented 1 year ago

I was curious, so I looked, but I couldn't find a standard definition for a quadratic wave. What do you have in mind for that?

I imagine it being something like this, but I could be way off πŸ˜…

image

Screenshot_20230402_155642.jpg

anti7447 commented 1 year ago

I mostly asked the AI πŸ˜…

smangelsdorf commented 1 year ago

Ah, that's interesting. I asked GPT too, but I confused it by asking the wrong question. I was expecting another fundamental wave.

Adjusting the pitch over time based on a quadratic function is trickier. Both the inbuilt SineWave and my SawWave implementation have a fixed frequency, so won't work properly for that. As far as I know, the oscillators would need to support being modulated by some function, or else accept a pitch envelope describing the pitch over time.

As a random internet guy, I can't say whether that's something Rodio wants to support or whether it should be in a separate library, but it sounds like it would be fun to build. πŸ˜…

pixmusix commented 1 year ago

Hi! I know a little about Quadratic Waves. They are related BΓ©zier curves.

I'm not sure if this is what @anti7447 meant. It does come up in computer music, usually used as envelopes. Rodio is open source, so If people want to throw it in, awesome. I would consider quadratic enveloping outside the scope of Rodio.

I really liked this animation.

If @anti7447 would like to implement a sawtooth wave with rodio in it's current form, he could consider this formula. Rust is totally fast enough to handle this.

dvdsk commented 5 months ago

Hello! Tell me, please, is it possible to create quadratic and sawtooth waves? I found only a sine wave in the documentation

@anti7447 Did you figure it out? If not let me know! And if you did ill close this issue.

Rodio is open source, so If people want to throw it in, awesome. I would consider quadratic enveloping outside the scope of Rodio.

It would be a great fit for a third party crate extending Rodio by providing more Source's. If something like that grows and becomes popular it could even be taken over by the RustAudio group. Feel free to begin something like that and add all the waves you need :) It think we would happily link to it from the Readme.