I'm using an ESP32, I would like to output a frequency to an amplifier to make a sound like a camera flash charging. Here's an example of the sound
The frequency should start at 5000Hz and increase to 12000Hz over a duration of 1500ms (I'll tweak these after I get something functional), the frequency should increase exponentially.
I'm considering using "tone()" as you can set a frequency and duration. I can't find a good way to do an exponential function to adjust the frequency (or time?)
I can add an exponentially increasing number to the initial frequency, but the output would be quite stepped. Do I "map()" between the steps giving a more linear change?
There must be a better way to do this?
for (int i = 1; i < 9000; sq(i)) {
tone(pin, 5000 + i, 10)
}
Rather than adding "i" to the frequency, you could add an exponentially increasing value. The functions to calculate exponential values, pow() or exp(), are handy for that.
I think if you study this link, you will see the real use of the exponential expression for the capacitor current which is also the frequency of the high voltage circuit you hear.
That's not exponential. @westfw provided the correct form back in Post #4. In the limit of smaller and smaller step size, it becomes exp(k * t) where k is a constant.
Hi guys
Thanks for all the input. After examining the sample sound with some better tools than just my ears it looks like it's more of a logarithmic curve (with a few harmonics I'll ignore for now), westfw was right
Experimenting last night I found some new issues. Duration set in tone has no effect on the for loop. I'm experimenting with adding a delay to give the tone some time to play before the loop continues. Currently it's not sounding very consistent, the tone melody example suggests a delay of 130% the tone duration.
The output is also sounding very stepped. I wasn't sure it would be noticeable.
I'll continue to experiment tonight
Here is westfw's code output with an added delay, and no duration (the click at before the sound is me pressing a button to trigger it) https://jumpshare.com/s/P6t7QWQxHKF1esNtE8X8
here's the output from that https://jumpshare.com/s/UxzeigGZCChxto5rb6Yx
It sounds quite good, it doesn't have quite the same rising curve (logarithmic?) feel as a flash charge