50
edits
Notmasteryet (talk | contribs) |
|||
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( | tailPosition += written; | ||
if(tailPosition < tail.length) { | |||
// Not all the data was written, saving the tail... | // Not all the data was written, saving the tail... | ||
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 | tail = soundData; | ||
tailPosition = written; | |||
} | } | ||
currentWritePosition += written; | currentWritePosition += written; |
edits