Audio Data API: Difference between revisions

Line 374: Line 374:
         var currentWritePosition = 0;
         var currentWritePosition = 0;
         var prebufferSize = sampleRate / 2; // buffer 500ms
         var prebufferSize = sampleRate / 2; // buffer 500ms
         var tail = null;
         var tail = null, tailPosition;


         // The function called with regular interval to populate  
         // The function called with regular interval to populate  
Line 381: Line 381:
           var written;
           var written;
           // Check if some data was not written in previous attempts.
           // Check if some data was not written in previous attempts.
           if(tail) {
           if(tail) {
             written = audio.mozWriteAudio(tail);
             written = audio.mozWriteAudio(tail.subarray(tailPosition));
             currentWritePosition += written;
             currentWritePosition += written;
             if(written < tail.length) {
            tailPosition += written;
             if(tailPosition < tail.length) {
               // Not all the data was written, saving the tail...
               // Not all the data was written, saving the tail...
              tail = tail.slice(written);
               return; // ... and exit the function.
               return; // ... and exit the function.
             }
             }
Line 404: Line 404:
             if(written < soundData.length) {
             if(written < soundData.length) {
               // Not all the data was written, saving the tail.
               // Not all the data was written, saving the tail.
               tail = soundData.slice(written);
               tail = soundData;
              tailPosition = written;
             }
             }
             currentWritePosition += written;
             currentWritePosition += written;
50

edits