From f750bcfa21392f4ea1257746f40b9cc6a2d1dbaa Mon Sep 17 00:00:00 2001 From: Vanilagy <1696106+Vanilagy@users.noreply.github.com> Date: Sun, 9 Feb 2025 14:42:08 +0100 Subject: [PATCH] Fix incorrect timestamp rounding for audio --- src/media-sink.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/media-sink.ts b/src/media-sink.ts index 038f019..83d23b6 100644 --- a/src/media-sink.ts +++ b/src/media-sink.ts @@ -888,14 +888,15 @@ class AudioDecoderWrapper extends DecoderWrapper onError: (error: DOMException) => unknown, codec: AudioCodec, decoderConfig: AudioDecoderConfig, - timeResolution: number, ) { super(onData, onError); const dataHandler = (data: AudioData) => { - // Round the microsecond timestamps to the time resolution - const timestamp = Math.round(data.timestamp / 1e6 * timeResolution) / timeResolution; - const duration = Math.round(data.duration / 1e6 * timeResolution) / timeResolution; + const sampleRate = decoderConfig.sampleRate; + + // Round the microsecond timestamps to the sample rate + const timestamp = Math.round(data.timestamp / 1e6 * sampleRate) / sampleRate; + const duration = Math.round(data.duration / 1e6 * sampleRate) / sampleRate; onData({ frame: data, @@ -1168,8 +1169,7 @@ export class AudioDataSink extends BaseMediaFrameSink