@@ -20,6 +20,7 @@ import {arrayFastResample, arraySeed} from "../utils/arrays";
20
20
import { SimpleObservable } from "matrix-widget-api" ;
21
21
import { IDestroyable } from "../utils/IDestroyable" ;
22
22
import { PlaybackClock } from "./PlaybackClock" ;
23
+ import { clamp } from "../utils/numbers" ;
23
24
24
25
export enum PlaybackState {
25
26
Decoding = "decoding" ,
@@ -52,8 +53,6 @@ export class Playback extends EventEmitter implements IDestroyable {
52
53
this . resampledWaveform = arrayFastResample ( seedWaveform , PLAYBACK_WAVEFORM_SAMPLES ) ;
53
54
this . waveformObservable . update ( this . resampledWaveform ) ;
54
55
this . clock = new PlaybackClock ( this . context ) ;
55
-
56
- // TODO: @@ TR: Calculate real waveform
57
56
}
58
57
59
58
public get waveform ( ) : number [ ] {
@@ -93,6 +92,13 @@ export class Playback extends EventEmitter implements IDestroyable {
93
92
94
93
public async prepare ( ) {
95
94
this . audioBuf = await this . context . decodeAudioData ( this . buf ) ;
95
+
96
+ // Update the waveform to the real waveform once we have channel data to use. We don't
97
+ // exactly trust the user-provided waveform to be accurate...
98
+ const waveform = Array . from ( this . audioBuf . getChannelData ( 0 ) ) . map ( v => clamp ( v , 0 , 1 ) ) ;
99
+ this . resampledWaveform = arrayFastResample ( waveform , PLAYBACK_WAVEFORM_SAMPLES ) ;
100
+ this . waveformObservable . update ( this . resampledWaveform ) ;
101
+
96
102
this . emit ( PlaybackState . Stopped ) ; // signal that we're not decoding anymore
97
103
this . clock . durationSeconds = this . audioBuf . duration ;
98
104
}
0 commit comments