【发布时间】:2016-09-18 21:21:20
【问题描述】:
我已经为此绞尽脑汁好几天了。
我计划在一定时间内使用 PHP 和 SoX 来产生音频脉冲。在这种情况下,我使用频率来描述每秒发生多少脉冲。所以 8 的频率是每秒 8 个脉冲。
我将使用的脉冲示例(等时音)
我需要知道每个脉冲的开始时间,以便在生成音频时及时绘制它们。当频率保持恒定时,这很容易做到。但是当频率随时间变化时,我遇到了完成平均脉冲量所需时间过多或过少的问题。
这是一个 Javascript 示例(我现在使用 JS 来进行数学运算)
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.
}
我已经使用以下主题对这个主题进行了大量研究:
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
但我仍然无法弄清楚如何使用这些技术获取每个脉冲的开始时间,或者我可能完全搞错了。
任何帮助将不胜感激! :)
【问题讨论】:
-
我可能弄错了,但我认为这与不确定性原理有关:要知道波的频率,您必须观察一段时间,因此您不知道在哪里浪潮开始了。
-
pulse是什么意思?您是指具有一定数量峰值的正弦波,还是其他? -
脉冲我指的是等时音。我已经编辑了我的问题以包含一个示例..
标签: javascript php algorithm math