Skip to content

Commit c3327b9

Browse files
Corrected calculation of AdjustedPosition by removing a stray division by 100.
Added conversion of result of AdjustedPosition from device position units into bytes to WasapiOut.GetPosition.
1 parent 4362fa3 commit c3327b9

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

NAudio/CoreAudioApi/AudioClockClient.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ public ulong AdjustedPosition
6262
{
6363
get
6464
{
65-
// figure out ticks per byte (for later)
66-
var byteLatency = (TimeSpan.TicksPerSecond / Frequency);
67-
6865
ulong pos, qpos;
6966
int cnt = 0;
7067
while (!GetPosition(out pos, out qpos))
@@ -83,14 +80,14 @@ public ulong AdjustedPosition
8380
// get the current qpc count (in ticks)
8481
var qposNow = (ulong)((Stopwatch.GetTimestamp() * 10000000M) / Stopwatch.Frequency);
8582

86-
// find out how many ticks has passed since the device reported the position
87-
var qposDiff = (qposNow - qpos) / 100;
83+
// find out how many ticks have passed since the device reported the position
84+
var qposDiff = qposNow - qpos;
8885

89-
// find out how many byte would have played in that time span
90-
var bytes = qposDiff / byteLatency;
86+
// find out how many device position units (usually bytes) would have played in that time span
87+
var posDiff = (qposDiff * Frequency) / TimeSpan.TicksPerSecond;
9188

9289
// add it to the position
93-
pos += bytes;
90+
pos += posDiff;
9491
}
9592
return pos;
9693
}

NAudio/Wave/WaveOutputs/WasapiOut.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@ public long GetPosition()
274274
{
275275
return 0;
276276
}
277-
return (long)audioClient.AudioClockClient.AdjustedPosition;
277+
var clock = audioClient.AudioClockClient;
278+
return ((long)clock.AdjustedPosition * outputFormat.AverageBytesPerSecond) / (long)clock.Frequency;
278279
}
279280

280281
/// <summary>

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"msbuild-sdks": {
3-
"MSBuild.Sdk.Extras": "2.0.31"
3+
"MSBuild.Sdk.Extras": "2.0.54"
44
}
55
}

0 commit comments

Comments
 (0)