faiface / beep

A little package that brings sound to any Go application. Suitable for playback and audio-processing.
MIT License
2.07k stars 152 forks source link

Add additional waveform generators #140

Closed Alextopher closed 2 years ago

Alextopher commented 2 years ago

I was experimenting with some simple waveform generators. I noticed the generators sub package could generate a sine wave. Is there any interest in adding some other classic waveforms? Proposing adding Sine, Square, Triangle, Sawtooth, and Reversed Sawtooth generators.

I updated the tone-player example. It's not just an example on using the new waveforms, it also using many of the compositors.

A breaking change: the frequency argument to the previous sine generator was an integer which was then casted to a float. There's no particular reason to not accept a float as the argument other than it would now introduce a breaking change.

malparty commented 2 years ago

Thanks @Alextopher, I like the idea as this might motivate some people who want to build synthesizers! :D I'll try to have a deeper review after work and test it!

malparty commented 2 years ago

@Alextopher while testing the example, I could hear some volume differences, so I recorded each sound wave, and here is the result:

Sine Triangle Square Saw Saw reversed
Seems all good! Volume lower, from the image we can see it does not span across the [-1,0[ value range. We might want to fix that All good! :) All good! This one is easy to fix: just substract 1 to the final values (return currentValue - 1) ;-)
image image image image image

Sorry for the delay to answer~

Alextopher commented 2 years ago

Awesome catches! I'm not big into this audio stuff and thought I heard some off sounds. It never occurred to me to use something like Audacity to debug them. If I contribute again I'll keep that trick in mind.