Skip to content

Commit

Permalink
Tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiasBuelens committed Oct 16, 2023
1 parent ab6ea4f commit 7cbc2a7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export function arrayRemoveAt<T>(array: T[], index: number): void {
}
}

export function sumWith<T>(array: T[], cb: (element: T) => number): number {
return array.reduce((total, element) => total + cb(element), 0);
}

export function queueTask(fn: () => void): void {
setTimeout(fn, 0);
}
Expand Down
6 changes: 2 additions & 4 deletions src/video-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
Deferred,
Direction,
queueTask,
sumWith,
waitForEvent
} from "./util";
import { TimeRange, TimeRanges } from "./time-ranges";
Expand Down Expand Up @@ -1113,10 +1114,7 @@ export class BabyVideoElement extends HTMLElement {
const { numberOfChannels, sampleRate } = frames[0];
const audioBuffer = new AudioBuffer({
numberOfChannels,
length: frames.reduce(
(totalFrames, frame) => totalFrames + frame.numberOfFrames,
0
),
length: sumWith(frames, (frame) => frame.numberOfFrames),
sampleRate
});
for (let channel = 0; channel < numberOfChannels; channel++) {
Expand Down

0 comments on commit 7cbc2a7

Please sign in to comment.