Cette traduction est incomplète. Aidez à traduire cet article depuis l'anglais.
L'object PeriodicWave
permet de définir une forme d'onde personnalisée, pouvant être utilisée comme sortie d'un OscillatorNode
.
PeriodicWave
n'a ni entrée ni sortie; elle doit être créée avec AudioContext.createPeriodicWave()
et être assignée à un OscillatorNode avec OscillatorNode.setPeriodicWave()
.
Constructeur
PeriodicWave.PeriodicWave()
- Crée une
PeriodicWave
(onde périodique) avec toutes les valeurs optionelles mises par défaut. Pour établir des valeurs personnalisées, il faut utiliser le constructeurAudioContext.createPeriodicWave()
.
Propriétés
Aucune; par ailleurs, PeriodicWave
n'hérite d'aucune propriété.
Méthodes
Aucune; par ailleurs, PeriodicWave
n'hérite d'aucune méthode.
Exemple
The following example illustrates simple usage of createPeriodicWave()
, to create a PeriodicWave
object containing a simple sine wave.
var real = new Float32Array(2); var imag = new Float32Array(2); var ac = new AudioContext(); var osc = ac.createOscillator(); real[0] = 0; imag[0] = 0; real[1] = 1; imag[1] = 0; var wave = ac.createPeriodicWave(real, imag, {disableNormalization: true}); osc.setPeriodicWave(wave); osc.connect(ac.destination); osc.start(); osc.stop(2);
This works because a sound that contains only a fundamental tone is by definition a sine wave
Here, we create a PeriodicWave
with two values. The first value is the DC offset, which is the value at which the oscillator starts. 0 is good here, because we want to start the curve at the middle of the [-1.0; 1.0] range.
The second and subsequent values are sine and cosine components. You can think of it as the result of a Fourier transform, where you get frequency domain values from time domain value. Here, with createPeriodicWave()
, you specify the frequencies, and the browser performs an inverse Fourier transform to get a time domain buffer for the frequency of the oscillator. Here, we only set one component at full volume (1.0) on the fundamental tone, so we get a sine wave.
The coefficients of the Fourier transform should be given in ascending order (i.e. etc.) and can be positive or negative. A simple way of manually obtaining such coefficients (though not the best) is to use a graphing calculator.
Spécifications
Specification | Status | Comment |
---|---|---|
Web Audio API La définition de 'PeriodicWave' dans cette spécification. |
Version de travail |
Compatibilité des navigateurs
Ordinateur | Mobile | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Support simple | Chrome Support complet 14 | Edge Support complet Oui | Firefox Support complet 25 | IE Aucun support Non | Opera Support complet 15 | Safari Support complet 6 | WebView Android Support complet Oui | Chrome Android Support complet 18 | Edge Mobile Support complet Oui | Firefox Android Support complet 26 | Opera Android Support complet 15 | Safari iOS ? | Samsung Internet Android Support complet Oui |
PeriodicWave() constructor | Chrome
Support complet
55
| Edge ? | Firefox Support complet 53 | IE Aucun support Non | Opera Support complet 42 | Safari ? | WebView Android
Support complet
55
| Chrome Android
Support complet
55
| Edge Mobile ? | Firefox Android Support complet 53 | Opera Android Support complet 42 | Safari iOS ? | Samsung Internet Android Support complet 6.0 |
Légende
- Support complet
- Support complet
- Aucun support
- Aucun support
- Compatibilité inconnue
- Compatibilité inconnue
- Voir les notes d'implémentation.
- Voir les notes d'implémentation.