Skip to content

Commit 09d8c84

Browse files
Share code with setAmplitudeU10.
Stop and clear the field in both cases.
1 parent 5a338ef commit 09d8c84

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/board/audio/index.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,7 @@ export class Audio {
125125
}
126126

127127
setAmplitudeU10(amplitudeU10: number) {
128-
if (this.oscillator) {
129-
this.oscillator.stop();
130-
this.oscillator = undefined;
131-
}
128+
this.stopOscillator();
132129
if (amplitudeU10) {
133130
this.oscillator = this.context!.createOscillator();
134131
this.oscillator.type = "sine";
@@ -139,7 +136,14 @@ export class Audio {
139136
}
140137

141138
boardStopped() {
142-
this.oscillator?.stop();
139+
this.stopOscillator();
140+
}
141+
142+
private stopOscillator() {
143+
if (this.oscillator) {
144+
this.oscillator.stop();
145+
this.oscillator = undefined;
146+
}
143147
}
144148
}
145149

0 commit comments

Comments
 (0)