This repository was archived by the owner on Sep 11, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import {arrayFastResample, arraySeed} from "../utils/arrays";
2020import { SimpleObservable } from "matrix-widget-api" ;
2121import { IDestroyable } from "../utils/IDestroyable" ;
2222import { PlaybackClock } from "./PlaybackClock" ;
23+ import { clamp } from "../utils/numbers" ;
2324
2425export 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 }
You can’t perform that action at this time.
0 commit comments