]> git.earman.xyz Git - sensor-watch.git/commitdiff
Make the simulator play beeps a lot more reliably.
authorAlessandro Genova <ales.genova@gmail.com>
Fri, 15 Aug 2025 01:40:02 +0000 (21:40 -0400)
committerAlessandro Genova <ales.genova@gmail.com>
Sat, 3 Jan 2026 01:07:56 +0000 (20:07 -0500)
watch-library/simulator/watch/watch_tcc.c

index 5e5dd0138bd6bdfd21288a2e1652586f1348f347..c7b1182def8a9a50f4bd6da2085797593c4092bd 100644 (file)
@@ -150,7 +150,11 @@ void watch_enable_buzzer(void) {
     buzzer_period = NotePeriods[BUZZER_NOTE_A4];
 
     EM_ASM({
-        Module['audioContext'] = new (window.AudioContext || window.webkitAudioContext)();
+        // "It's recommended to create one AudioContext and reuse it instead of initializing a new one each time."
+        // https://developer.mozilla.org/en-US/docs/Web/API/AudioContext
+        if (!Module['audioContext']) {
+            Module['audioContext'] = new (window.AudioContext || window.webkitAudioContext)();
+        }
     });
 }
 
@@ -163,13 +167,6 @@ void watch_set_buzzer_period_and_duty_cycle(uint32_t period, uint8_t duty_cycle)
 void watch_disable_buzzer(void) {
     buzzer_enabled = false;
     buzzer_period = NotePeriods[BUZZER_NOTE_A4];
-
-    EM_ASM({
-        if (Module['audioContext']) {
-            Module['audioContext'].close();
-            Module['audioContext'] = null;
-        }
-    });
 }
 
 void watch_set_buzzer_on(void) {