I've been racking my brain for days over this.
I'm planning on using PHP with SoX to produce audio pulses over a certain amount of time. In this case i'm using frequency as a way to describe how many pulses occur per second. So a frequency of 8 is 8 pulses per second.
Example of the pulse I'll be using (Isochronic tone)
I need to know the start time of each of these pulses so that I can plot them in time when producing the audio. This is easily done when the frequency remains constant. But when the frequency changes over time, I run into the problem that it takes too much or too little time to complete the average amount of pulses.
Here's an example in Javascript (I'm using JS for now to get the maths working)
var f0 = 8; //Start frequency
var f1 = 1; //End frequency
var interval = 30; //Total time
var average_freq = (f0 + f1) / 2; //Average frequency
var pulses = average_freq * interval; //Total number of pulses needed
var pulse_start_time = 0;
for(var i = 0; i < pulses; i++) {
var delta = i / pulses;
var this_freq = f0 + (f1 - f0) * delta;
/*
need exponential formula to find start time
*/
console.log( "pulse: "+ (i+1) + ", "+
"pulse frequency: "+ this_freq + ", "+
"start time: "+ pulse_start_time);
pulse_start_time += 1 / this_freq; //This method works fine providing
//both start and end frequency are
//the same.
}
I've done a lot of researching on this subject using topics like:
Drawing sine wave with increasing Amplitude and frequency over time
Plot Frequency Sweep In Python
sine wave that slowly ramps up frequency from f1 to f2 for a given time
sine wave that exponentialy changes between frequencies f1 and f2 at given time/amount of samples
But I'm still unable to figure out how to get the start time of each pulse using these techniques, or maybe I'm going about this all wrong.
Any help will be appreciated! :)
pulse
? Do you mean a sinusoidal wave with some number of peaks, or something else? – pingul