@@ -21,30 +21,30 @@ export class NotePlaybackService {
21
21
22
22
playNote ( stringName , fret ) {
23
23
if ( this . context ) {
24
- let noteFrequency = this . getFrequency ( stringName , fret ) ;
24
+ const noteFrequency = this . getFrequency ( stringName , fret ) ;
25
25
this . pluckString ( noteFrequency ) ;
26
26
}
27
27
}
28
28
29
29
private getFrequency ( stringName , fret ) {
30
30
// We're using stringName here, the case sensitive alt to string, to differentiate E/e strings.
31
- let stringFrequency = StringFrequencies [ stringName ] ;
32
- let fretCents = fret * 100 ;
31
+ const stringFrequency = StringFrequencies [ stringName ] ;
32
+ const fretCents = fret * 100 ;
33
33
return stringFrequency * Math . pow ( 2 , ( fretCents / 1200 ) ) ;
34
34
}
35
35
36
36
private pluckString ( frequency : number ) {
37
37
// Use Karplus-Strong algo to simply synth guitar-like sounds.
38
38
// https://ccrma.stanford.edu/~jos/pasp/Karplus_Strong_Algorithm.html
39
- let processor = this . context . createScriptProcessor ( SYNTH_BUFFER_SIZE , 0 , 1 ) ;
40
- let signalPeriod = Math . round ( this . context . sampleRate / frequency ) ;
41
- let currentSample = new Float32Array ( signalPeriod ) ;
39
+ const processor = this . context . createScriptProcessor ( SYNTH_BUFFER_SIZE , 0 , 1 ) ;
40
+ const signalPeriod = Math . round ( this . context . sampleRate / frequency ) ;
41
+ const currentSample = new Float32Array ( signalPeriod ) ;
42
42
// Fill sample with random noise -1 through +1
43
43
this . fillWithNoise ( currentSample , signalPeriod ) ;
44
44
let n = 0 ;
45
45
processor . addEventListener ( 'audioprocess' , ( e ) => {
46
46
// Populate output buffer with signal
47
- let outputBuffer = e . outputBuffer . getChannelData ( 0 ) ;
47
+ const outputBuffer = e . outputBuffer . getChannelData ( 0 ) ;
48
48
for ( let i = 0 ; i < outputBuffer . length ; i ++ ) {
49
49
// Lowpass the signal by averaging it with the next point
50
50
currentSample [ n ] = ( currentSample [ n ] + currentSample [ ( n + 1 ) % signalPeriod ] ) / 2 ;
@@ -54,7 +54,7 @@ export class NotePlaybackService {
54
54
}
55
55
} ) ;
56
56
// Filter the output
57
- let bandpass = this . createBandpassFilter ( frequency ) ;
57
+ const bandpass = this . createBandpassFilter ( frequency ) ;
58
58
processor . connect ( bandpass ) ;
59
59
// Kill the processor after 2 seconds
60
60
setTimeout ( ( ) => {
@@ -70,7 +70,7 @@ export class NotePlaybackService {
70
70
}
71
71
72
72
private createBandpassFilter ( frequency ) {
73
- let bandpass = this . context . createBiquadFilter ( ) ;
73
+ const bandpass = this . context . createBiquadFilter ( ) ;
74
74
bandpass . type = "bandpass" ;
75
75
bandpass . frequency . value = Math . round ( frequency ) ;
76
76
bandpass . Q . value = 1 / 6 ;
0 commit comments