Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
583
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function PushBuffer (AudioBuffer)
  2.     {
  3.         // Create new audio source for the buffer
  4.         var SourceNode = Self.SoundContext.createBufferSource();
  5.        
  6.         // Make sure the node deletes itself after playback
  7.         SourceNode.onended = function () {
  8.             var ThisNode = SourceNode;
  9.             ThisNode.disconnect();
  10.             ThisNode = null;
  11.         }
  12.        
  13.         // Prevent looping (the standard says that it should be off by default)
  14.         SourceNode.loop = false;
  15.        
  16.         // Pass audio data to source
  17.         SourceNode.buffer = AudioBuffer;
  18.        
  19.         //Connect the source to the gain node
  20.         SourceNode.connect(Self.GainNode);
  21.        
  22.         // Check if this is the first buffer we received
  23.         if (Self.NextTime == 0.0)
  24.         {
  25.             // Start playing now
  26.             Self.NextTime = Self.SoundContext.currentTime;
  27.         }
  28.        
  29.         // Schedule playback
  30.         console.log("Current time: "+Self.SoundContext.currentTime);
  31.         console.log("Duration: "+AudioBuffer.duration);
  32.         end = Self.NextTime+AudioBuffer.duration
  33.         console.log("Play at: "+Self.NextTime+" End at: "+end);
  34.         SourceNode.start(Self.NextTime);
  35.         //SourceNode.start(Self.SoundContext.currentTime);
  36.         //SourceNode.start(0);
  37.  
  38.         // Move time forward
  39.         Self.NextTime += AudioBuffer.duration;
  40.  
  41.         return;
  42.     } // end push buffer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement