Wavetable synthesis - Synthesizing a chord - periodic wave wavetable creation | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
+ 1

# Wavetable synthesis - Synthesizing a chord - periodic wave wavetable creation

``` //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); ``` I know that `air_pressure=sin(2pi·frequency·time)` represents the standard `oscillator.type="sine"` therefore the wavetable for sine would be: ``` real = [0, 0], imaginary = [0, 1]; ``` I want my oscillator to sound the 'frequency' frequency and the sound major third above it at the same time i.e. `'frequency'·2^(4/12)'`, then air_pressure=sin(2pi·frequency·time)+sin(2pi·2^(4/12)·frequency·time) How should the wavetable look like now? Should I transform to fourier series to get the equation in form of 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)? How should I do it? or is there an easier way? Note: I don't want to create multiple oscillators, I want to set custom type of single oscillator to achieve poliphony ``` /*'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(); ```

12th Apr 2019, 8:59 AM