如何在 Javascript 中创建一个数组,每个变量的值都不同?
How do I create an array in Javascript with different values in each variable?
不确定问题是否解释得很好,但我想将这些 Tone.JS 过滤器放在一个数组中。问题是它们都有不同的频率和增益值,最终也会有不同的Q值。
查看下面的代码,让我知道这是否可行。感谢任何帮助,谢谢!
var noise = new Tone.Noise();
for (counter = 0; counter < 6; counter+=1) {
var hipass[counter] = new Tone.Filter();
}
for (counter = 0; counter < 6; counter+=1) {
var lowpass[counter] = new Tone.Filter();
}
var hipass1 = new Tone.Filter(8, "highpass", -12, -77.8);
var hipass2 = new Tone.Filter(16, "highpass", -12, -56.7);
var hipass3 = new Tone.Filter(31.5, "highpass", -12, -39.4);
var hipass4 = new Tone.Filter(63, "highpass", -12, -26.2);
var hipass5 = new Tone.Filter(125, "highpass", -12, -16.1);
var hipass6 = new Tone.Filter(250, "highpass", -12, -8.6);
var lowpass1 = new Tone.Filter(500, "lowpass", -12, -3.2);
var lowpass2 = new Tone.Filter(1000, "lowpass", -12);
var lowpass3 = new Tone.Filter(2000, "lowpass", -12, 1.2);
var lowpass4 = new Tone.Filter(4000, "lowpass", -12, 1.0);
var lowpass5 = new Tone.Filter(8000, "lowpass", -12, -1.1);
var lowpass6 = new Tone.Filter(1200, "lowpass", -12, -6.6);
noise.chain(hipass[counter], lowpass[counter], Tone.Master);
noise.volume = -20;
noise.stop();
使用 javascript 的 .push()
方法将新值附加到您的数组:
var noise = new Tone.Noise();
var hipass[counter] = new Array();
var lowpass[counter] = new Array();
hipass.push(new Tone.Filter(8, "highpass", -12, -77.8));
hipass.push(new Tone.Filter(16, "highpass", -12, -56.7));
hipass.push(new Tone.Filter(31.5, "highpass", -12, -39.4));
hipass.push(new Tone.Filter(63, "highpass", -12, -26.2));
hipass.push(new Tone.Filter(125, "highpass", -12, -16.1));
hipass.push(new Tone.Filter(250, "highpass", -12, -8.6));
lowpass.push(new Tone.Filter(500, "lowpass", -12, -3.2));
lowpass.push(new Tone.Filter(1000, "lowpass", -12));
lowpass.push(new Tone.Filter(2000, "lowpass", -12, 1.2));
lowpass.push(new Tone.Filter(4000, "lowpass", -12, 1.0));
lowpass.push(new Tone.Filter(8000, "lowpass", -12, -1.1));
lowpass.push(new Tone.Filter(1200, "lowpass", -12, -6.6));
noise.chain(hipass[counter], lowpass[counter], Tone.Master);
noise.volume = -20;
noise.stop();
不确定问题是否解释得很好,但我想将这些 Tone.JS 过滤器放在一个数组中。问题是它们都有不同的频率和增益值,最终也会有不同的Q值。
查看下面的代码,让我知道这是否可行。感谢任何帮助,谢谢!
var noise = new Tone.Noise();
for (counter = 0; counter < 6; counter+=1) {
var hipass[counter] = new Tone.Filter();
}
for (counter = 0; counter < 6; counter+=1) {
var lowpass[counter] = new Tone.Filter();
}
var hipass1 = new Tone.Filter(8, "highpass", -12, -77.8);
var hipass2 = new Tone.Filter(16, "highpass", -12, -56.7);
var hipass3 = new Tone.Filter(31.5, "highpass", -12, -39.4);
var hipass4 = new Tone.Filter(63, "highpass", -12, -26.2);
var hipass5 = new Tone.Filter(125, "highpass", -12, -16.1);
var hipass6 = new Tone.Filter(250, "highpass", -12, -8.6);
var lowpass1 = new Tone.Filter(500, "lowpass", -12, -3.2);
var lowpass2 = new Tone.Filter(1000, "lowpass", -12);
var lowpass3 = new Tone.Filter(2000, "lowpass", -12, 1.2);
var lowpass4 = new Tone.Filter(4000, "lowpass", -12, 1.0);
var lowpass5 = new Tone.Filter(8000, "lowpass", -12, -1.1);
var lowpass6 = new Tone.Filter(1200, "lowpass", -12, -6.6);
noise.chain(hipass[counter], lowpass[counter], Tone.Master);
noise.volume = -20;
noise.stop();
使用 javascript 的 .push()
方法将新值附加到您的数组:
var noise = new Tone.Noise();
var hipass[counter] = new Array();
var lowpass[counter] = new Array();
hipass.push(new Tone.Filter(8, "highpass", -12, -77.8));
hipass.push(new Tone.Filter(16, "highpass", -12, -56.7));
hipass.push(new Tone.Filter(31.5, "highpass", -12, -39.4));
hipass.push(new Tone.Filter(63, "highpass", -12, -26.2));
hipass.push(new Tone.Filter(125, "highpass", -12, -16.1));
hipass.push(new Tone.Filter(250, "highpass", -12, -8.6));
lowpass.push(new Tone.Filter(500, "lowpass", -12, -3.2));
lowpass.push(new Tone.Filter(1000, "lowpass", -12));
lowpass.push(new Tone.Filter(2000, "lowpass", -12, 1.2));
lowpass.push(new Tone.Filter(4000, "lowpass", -12, 1.0));
lowpass.push(new Tone.Filter(8000, "lowpass", -12, -1.1));
lowpass.push(new Tone.Filter(1200, "lowpass", -12, -6.6));
noise.chain(hipass[counter], lowpass[counter], Tone.Master);
noise.volume = -20;
noise.stop();