-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Long file spectrogram support. Fixed excessive memory use with long f…
…iles. Page down and Page up buttons now page through a file. Play button for detections - seeks timecode and plays detection region.
- Loading branch information
Showing
7 changed files
with
219 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const audioContext = new (window.AudioContext || window.webkitAudioContext); | ||
|
||
function AudioBufferSlice(buffer, begin, end, callback) { | ||
if (!(this instanceof AudioBufferSlice)) { | ||
return new AudioBufferSlice(buffer, begin, end, callback); | ||
} | ||
|
||
let error = null; | ||
|
||
const duration = buffer.duration; | ||
const channels = buffer.numberOfChannels; | ||
const rate = buffer.sampleRate; | ||
|
||
if (typeof end === 'function') { | ||
callback = end; | ||
end = duration; | ||
} | ||
|
||
// handle short clips and beginning /end of files | ||
if (end > duration) end = duration; | ||
if (begin < 0) begin = 0; | ||
|
||
if (typeof callback !== 'function') { | ||
error = new TypeError('callback must be a function'); | ||
} | ||
|
||
const startOffset = rate * begin; | ||
const endOffset = rate * end; | ||
const frameCount = endOffset - startOffset; | ||
let newArrayBuffer; | ||
|
||
try { | ||
newArrayBuffer = audioContext.createBuffer(channels, endOffset - startOffset, rate); | ||
const anotherArray = new Float32Array(frameCount); | ||
const offset = 0; | ||
|
||
for (let channel = 0; channel < channels; channel++) { | ||
buffer.copyFromChannel(anotherArray, channel, startOffset); | ||
newArrayBuffer.copyToChannel(anotherArray, channel, offset); | ||
} | ||
} catch (e) { | ||
error = e; | ||
} | ||
|
||
callback(error, newArrayBuffer); | ||
} | ||
|
||
module.exports = AudioBufferSlice; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.