//I'm instantiating AudioContext
var audio_context = new AudioContext();
//creating oscillator
var oscillator = audio_context.createOscillator();
//hooking up the oscillator
oscillator.connect(audio_context.destination);
我知道air_pressure=sin(2pi·frequency·time)
代表标准oscillator.type="sine"
因此,正弦波的波形表为:
real = [0, 0], imaginary = [0, 1];
我希望我的振荡器同时发出“频率”频率和高于其的大三分音,即'frequency'·2^(4/12)'
,然后
air_pressure=sin(2pi·frequency·time)+sin(2pi·2^(4/12)·frequency·time)
波表现在应该是什么样? 我是否应该转换成傅立叶级数以得到形式为
的方程air_pressure=a_0·cos(0)+b_0·sin(0)+a_1·cos(1)+b_1·sin(1)+a_2·cos(2)+b_2·sin(2)+...+a_n·cos(n)+b_n·sin(n)?
我应该怎么做? 还是有更简单的方法?
注意:我不想创建多个振荡器,我想设置单个振荡器的自定义类型来实现策略性
/*'real' is an array of cosine coefficients,
'imaginary is an array of sine coefficients in Fourier series representation of a soundwave */
var wave = audio_context.createPeriodicWave(real, imaginary);
//setting custom type of the oscillator:
oscillator.setPeriodicWave(wave);
//frequency manipulation:
oscillator.frequency.value = 110;
//making the oscillator sound:
oscillator.start();