From 0a9ce64cefa7c166e9d39bddcd7044fb626f4729 Mon Sep 17 00:00:00 2001 From: Quake4 Date: Sat, 27 May 2023 23:31:50 +0300 Subject: [PATCH 1/2] fix time conversion --- NAudio.Core/Wave/WaveStreams/WaveStream.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NAudio.Core/Wave/WaveStreams/WaveStream.cs b/NAudio.Core/Wave/WaveStreams/WaveStream.cs index 42a60cc9..00e66ed5 100644 --- a/NAudio.Core/Wave/WaveStreams/WaveStream.cs +++ b/NAudio.Core/Wave/WaveStreams/WaveStream.cs @@ -101,7 +101,7 @@ public virtual TimeSpan CurrentTime { get { - return TimeSpan.FromSeconds((double)Position / WaveFormat.AverageBytesPerSecond); + return TimeSpan.FromSeconds((double)(Position / WaveFormat.AverageBytesPerSecond)); } set { @@ -116,7 +116,7 @@ public virtual TimeSpan TotalTime { get { - return TimeSpan.FromSeconds((double) Length / WaveFormat.AverageBytesPerSecond); + return TimeSpan.FromSeconds((double)(Length / WaveFormat.AverageBytesPerSecond)); } } From fbf5a1ba2766d0cf83f1a17b817005f3995d0046 Mon Sep 17 00:00:00 2001 From: Quake4 Date: Sun, 28 May 2023 00:00:16 +0300 Subject: [PATCH 2/2] move to integer arifmetic --- NAudio.Core/Wave/WaveStreams/WaveStream.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/NAudio.Core/Wave/WaveStreams/WaveStream.cs b/NAudio.Core/Wave/WaveStreams/WaveStream.cs index 00e66ed5..839d2bd0 100644 --- a/NAudio.Core/Wave/WaveStreams/WaveStream.cs +++ b/NAudio.Core/Wave/WaveStreams/WaveStream.cs @@ -101,11 +101,11 @@ public virtual TimeSpan CurrentTime { get { - return TimeSpan.FromSeconds((double)(Position / WaveFormat.AverageBytesPerSecond)); + return TimeSpan.FromTicks(Position * 1000 / WaveFormat.AverageBytesPerSecond * 10000); } set { - Position = (long) (value.TotalSeconds * WaveFormat.AverageBytesPerSecond); + Position = value.Ticks / 10000 * WaveFormat.AverageBytesPerSecond / 1000; } } @@ -116,7 +116,7 @@ public virtual TimeSpan TotalTime { get { - return TimeSpan.FromSeconds((double)(Length / WaveFormat.AverageBytesPerSecond)); + return TimeSpan.FromTicks(Length * 1000 / WaveFormat.AverageBytesPerSecond * 10000); } }