Browse Source

Move samplerate broadcast out of hot code

Ernest Wong 7 years ago
parent
commit
833bc52df1
2 changed files with 9 additions and 1 deletions
  1. 7 1
      src/browser/speaker.js
  2. 2 0
      src/sb16.js

+ 7 - 1
src/browser/speaker.js

@@ -66,6 +66,13 @@ function SpeakerAdapter(bus)
         this.dac_buffer1 = data[1];
     }, this);
 
+    bus.register("speaker-request-samplerate", function()
+    {
+        bus.send("speaker-tell-samplerate", this.audio_context.sampleRate);
+    }, this);
+
+    bus.send("speaker-tell-samplerate", this.audio_context.sampleRate);
+
     if(DEBUG)
     {
         this.debug_dac = false;
@@ -108,7 +115,6 @@ SpeakerAdapter.prototype.dac_process = function(event)
     out.copyToChannel(this.dac_buffer0, 0);
     out.copyToChannel(this.dac_buffer1, 1);
 
-    this.bus.send("speaker-tell-samplerate", this.audio_context.sampleRate);
     this.bus.send("speaker-request-data", out.length);
 
     if(DEBUG)

+ 2 - 0
src/sb16.js

@@ -238,6 +238,8 @@ function SB16(cpu, bus)
         this.audio_samplerate = rate;
     }, this);
 
+    bus.send("speaker-request-samplerate");
+
     bus.register("speaker-request-data", function(size)
     {
         this.audio_send(size);