From 50c486572faaca2d4d1125e9dbe1e654b8210567 Mon Sep 17 00:00:00 2001 From: Hamir Mahal Date: Sun, 7 Mar 2021 13:49:43 -0800 Subject: [PATCH] use const instead of let declaration for some vars In the live version of the sequencer this page describes how to create, there exists a commit that does the same thing as this commit does for this page, except it does it for all applicable variable declarations, instead of the subset I verified on this page. There are probably more variable declarations that can use `const` instead of `let` on this page. See https://github.com/mdn/webaudio-examples/commit/1217eb894d4a1865058939df211e4209bcb9205d. --- .../web_audio_api/advanced_techniques/index.html | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/files/en-us/web/api/web_audio_api/advanced_techniques/index.html b/files/en-us/web/api/web_audio_api/advanced_techniques/index.html index 470a19804dfbb47..e06d34f5f92fdaf 100644 --- a/files/en-us/web/api/web_audio_api/advanced_techniques/index.html +++ b/files/en-us/web/api/web_audio_api/advanced_techniques/index.html @@ -87,7 +87,7 @@

The periodic wave

First of all, we'll create our periodic wave. To do so, We need to pass real and imaginary values into the {{domxref("BaseAudioContext.createPeriodicWave()")}} method.:

-
let wave = audioCtx.createPeriodicWave(wavetable.real, wavetable.imag);
+
const wave = audioCtx.createPeriodicWave(wavetable.real, wavetable.imag);
 
@@ -99,7 +99,7 @@

The Oscillator

Now we can create an {{domxref("OscillatorNode")}} and set its wave to the one we've created:

function playSweep(time) {
-     let osc = audioCtx.createOscillator();
+     const osc = audioCtx.createOscillator();
      osc.setPeriodicWave(wave);
      osc.frequency.value = 440;
      osc.connect(audioCtx.destination);
@@ -170,20 +170,20 @@ 

Initial oscillator

We'll set up our first {{domxref("OscillatorNode")}} the same way as our sweep sound, except we won't use a wavetable to set a bespoke wave — we'll just use the default sine wave:

-
let osc = audioCtx.createOscillator();
+
const osc = audioCtx.createOscillator();
 osc.type = 'sine';
 osc.frequency.value = 880;

Now we're going to create a {{domxref("GainNode")}}, as it's the gain value that we will oscillate with our second, low frequency oscillator:

-
let amp = audioCtx.createGain();
+
const amp = audioCtx.createGain();
 amp.gain.setValueAtTime(1, audioCtx.currentTime);

Creating the second, low frequency, oscillator

We'll now create a second — square — wave (or pulse) oscillator, to alter the amplification of our first sine wave:

-
let lfo = audioCtx.createOscillator();
+
const lfo = audioCtx.createOscillator();
 lfo.type = 'square';
 lfo.frequency.value = 30;
@@ -460,8 +460,8 @@

Playing the audio in time

Then we'll create variables to define how far ahead we want to look, and how far ahead we want to schedule:

-
let lookahead = 25.0; // How frequently to call scheduling function (in milliseconds)
-let scheduleAheadTime = 0.1; // How far ahead to schedule audio (sec)
+
const lookahead = 25.0; // How frequently to call scheduling function (in milliseconds)
+const scheduleAheadTime = 0.1; // How far ahead to schedule audio (sec)

Let's create a function that moves the note forwards by one beat, and loops back to the first when it reaches the 4th (last) one: