瀏覽代碼

Move samplerate broadcast out of hot code

Ernest Wong 7 年之前
父節點
當前提交
833bc52df1
共有 2 個文件被更改,包括 9 次插入1 次删除
  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);