Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 0806af0

Browse files
committed
Calculate the real waveform in the Playback class
1 parent 8dbcc85 commit 0806af0

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/voice/Playback.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {arrayFastResample, arraySeed} from "../utils/arrays";
2020
import {SimpleObservable} from "matrix-widget-api";
2121
import {IDestroyable} from "../utils/IDestroyable";
2222
import {PlaybackClock} from "./PlaybackClock";
23+
import {clamp} from "../utils/numbers";
2324

2425
export enum PlaybackState {
2526
Decoding = "decoding",
@@ -52,8 +53,6 @@ export class Playback extends EventEmitter implements IDestroyable {
5253
this.resampledWaveform = arrayFastResample(seedWaveform, PLAYBACK_WAVEFORM_SAMPLES);
5354
this.waveformObservable.update(this.resampledWaveform);
5455
this.clock = new PlaybackClock(this.context);
55-
56-
// TODO: @@ TR: Calculate real waveform
5756
}
5857

5958
public get waveform(): number[] {
@@ -93,6 +92,11 @@ export class Playback extends EventEmitter implements IDestroyable {
9392

9493
public async prepare() {
9594
this.audioBuf = await this.context.decodeAudioData(this.buf);
95+
96+
const waveform = Array.from(this.audioBuf.getChannelData(0)).map(v => clamp(v, 0, 1));
97+
this.resampledWaveform = arrayFastResample(waveform, PLAYBACK_WAVEFORM_SAMPLES);
98+
this.waveformObservable.update(this.resampledWaveform);
99+
96100
this.emit(PlaybackState.Stopped); // signal that we're not decoding anymore
97101
this.clock.durationSeconds = this.audioBuf.duration;
98102
}

0 commit comments

Comments
 (0)