mirror of
https://github.com/element-hq/element-web
synced 2024-11-23 17:56:01 +03:00
Merge pull request #5956 from matrix-org/travis/voicemessages/waveform2
Calculate the real waveform in the Playback class for voice messages
This commit is contained in:
commit
34c735e4d9
1 changed files with 8 additions and 2 deletions
|
@ -20,6 +20,7 @@ import {arrayFastResample, arraySeed} from "../utils/arrays";
|
|||
import {SimpleObservable} from "matrix-widget-api";
|
||||
import {IDestroyable} from "../utils/IDestroyable";
|
||||
import {PlaybackClock} from "./PlaybackClock";
|
||||
import {clamp} from "../utils/numbers";
|
||||
|
||||
export enum PlaybackState {
|
||||
Decoding = "decoding",
|
||||
|
@ -52,8 +53,6 @@ export class Playback extends EventEmitter implements IDestroyable {
|
|||
this.resampledWaveform = arrayFastResample(seedWaveform, PLAYBACK_WAVEFORM_SAMPLES);
|
||||
this.waveformObservable.update(this.resampledWaveform);
|
||||
this.clock = new PlaybackClock(this.context);
|
||||
|
||||
// TODO: @@ TR: Calculate real waveform
|
||||
}
|
||||
|
||||
public get waveform(): number[] {
|
||||
|
@ -93,6 +92,13 @@ export class Playback extends EventEmitter implements IDestroyable {
|
|||
|
||||
public async prepare() {
|
||||
this.audioBuf = await this.context.decodeAudioData(this.buf);
|
||||
|
||||
// Update the waveform to the real waveform once we have channel data to use. We don't
|
||||
// exactly trust the user-provided waveform to be accurate...
|
||||
const waveform = Array.from(this.audioBuf.getChannelData(0)).map(v => clamp(v, 0, 1));
|
||||
this.resampledWaveform = arrayFastResample(waveform, PLAYBACK_WAVEFORM_SAMPLES);
|
||||
this.waveformObservable.update(this.resampledWaveform);
|
||||
|
||||
this.emit(PlaybackState.Stopped); // signal that we're not decoding anymore
|
||||
this.clock.durationSeconds = this.audioBuf.duration;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue