我对这整个编码工作很陌生,我正在开发一个交互式在线音乐视频,可以选择通过使用滤镜来混合和编辑音频。
我试图连接低通滤波器
在鲍里斯的帮助下http://www.html5rocks.com/en/tutorials/webaudio/intro/
我设法让这段代码失效:
var FilterSample = {
FREQ_MUL: 7000,
QUAL_MUL: 30,
playing: false
};
FilterSample.play = function () {
var source = context.createBufferSource();
source.buffer = BUFFERS.techno;
var filter = context.createBiquadFilter();
filter.type = 0; // LOW PASS
filter.frequency.value = 5000;
source.connect(filter);
filter.connect(context.destination);
if (!source.start) source.start = source.noteOn;
source.start(0);
source.loop = true;
this.source = source;
this.filter = filter;
};
FilterSample.stop = function () {
if (!this.source.stop) this.source.stop = source.noteOff;
this.source.stop(0);
this.source.noteOff(0);
};
FilterSample.toggle = function () {
this.playing ? this.stop() : this.play();
this.playing = !this.playing;
};
FilterSample.changeFrequency = function (element) {
var minValue = 40;
var maxValue = context.sampleRate / 2;
var numberOfOctaves = Math.log(maxValue / minValue) / Math.LN2;
var multiplier = Math.pow(2, numberOfOctaves * (element.value - 1.0));
this.filter.frequency.value = maxValue * multiplier;
};
FilterSample.changeQuality = function (element) {
this.filter.Q.value = element.value * this.QUAL_MUL;
};
FilterSample.toggleFilter = function (element) {
this.source.disconnect(0);
this.filter.disconnect(0);
if (element.checked) {
this.source.connect(this.filter);
this.filter.connect(context.destination);
} else {
this.source.connect(context.destination);
}
};
我的问题从一开始就开始,我想将自己的音频文件连接到我相信的FilterSample函数。
我创建了一个播放/暂停按钮,它运行FilterSample.toggle()onClick和2个范围的滑块,但我不能让它播放我自己的音频。