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
Amadeus - avatar
1 芯褌胁械褌
please share your code using code playground and not the question description
2nd Mar 2021, 2:31 AM
Wilbur Jaywright
Wilbur Jaywright - avatar