Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use const instead of let declaration for some vars #2912

Merged
merged 1 commit into from
Mar 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ <h3 id="The_periodic_wave">The periodic wave</h3>

<p>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.:</p>

<pre class="brush: js">let wave = audioCtx.createPeriodicWave(wavetable.real, wavetable.imag);
<pre class="brush: js">const wave = audioCtx.createPeriodicWave(wavetable.real, wavetable.imag);
</pre>

<div class="note">
Expand All @@ -99,7 +99,7 @@ <h3 id="The_Oscillator">The Oscillator</h3>
<p>Now we can create an {{domxref("OscillatorNode")}} and set its wave to the one we've created:</p>

<pre class="brush: js">function playSweep(time) {
let osc = audioCtx.createOscillator();
const osc = audioCtx.createOscillator();
osc.setPeriodicWave(wave);
osc.frequency.value = 440;
osc.connect(audioCtx.destination);
Expand Down Expand Up @@ -170,20 +170,20 @@ <h3 id="Initial_oscillator">Initial oscillator</h3>

<p>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 <code>sine</code> wave:</p>

<pre class="brush: js">let osc = audioCtx.createOscillator();
<pre class="brush: js">const osc = audioCtx.createOscillator();
osc.type = 'sine';
osc.frequency.value = 880;</pre>

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

<pre class="brush: js">let amp = audioCtx.createGain();
<pre class="brush: js">const amp = audioCtx.createGain();
amp.gain.setValueAtTime(1, audioCtx.currentTime);</pre>

<h3 id="Creating_the_second_low_frequency_oscillator">Creating the second, low frequency, oscillator</h3>

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

<pre class="brush: js">let lfo = audioCtx.createOscillator();
<pre class="brush: js">const lfo = audioCtx.createOscillator();
lfo.type = 'square';
lfo.frequency.value = 30;</pre>

Expand Down Expand Up @@ -460,8 +460,8 @@ <h2 id="Playing_the_audio_in_time">Playing the audio in time</h2>

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

<pre class="brush: js">let lookahead = 25.0; // How frequently to call scheduling function (in milliseconds)
let scheduleAheadTime = 0.1; // How far ahead to schedule audio (sec)</pre>
<pre class="brush: js">const lookahead = 25.0; // How frequently to call scheduling function (in milliseconds)
const scheduleAheadTime = 0.1; // How far ahead to schedule audio (sec)</pre>

<p>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:</p>

Expand Down