UNPKG

standardized-audio-context

Version:

A cross-browser wrapper for the Web Audio API which aims to closely follow the standard.

17 lines 1.08 kB
export const wrapAudioBufferSourceNodeStartMethodOffsetClamping = (nativeAudioBufferSourceNode) => { nativeAudioBufferSourceNode.start = ((start) => { return (when = 0, offset = 0, duration) => { const buffer = nativeAudioBufferSourceNode.buffer; // Bug #154: Safari does not clamp the offset if it is equal to or greater than the duration of the buffer. const clampedOffset = buffer === null ? offset : Math.min(buffer.duration, offset); // Bug #155: Safari does not handle the offset correctly if it would cause the buffer to be not be played at all. if (buffer !== null && clampedOffset > buffer.duration - 0.5 / nativeAudioBufferSourceNode.context.sampleRate) { start.call(nativeAudioBufferSourceNode, when, 0, 0); } else { start.call(nativeAudioBufferSourceNode, when, clampedOffset, duration); } }; })(nativeAudioBufferSourceNode.start); }; //# sourceMappingURL=wrap-audio-buffer-source-node-start-method-offset-clamping.js.map