From cbc19c88d133c604e3b1a26517569346bf1340c1 Mon Sep 17 00:00:00 2001 From: Elias Holzer Date: Fri, 1 Nov 2024 19:24:11 +0100 Subject: [PATCH 1/3] Adds ContinousSamplePosition to timer - needed for VST --- VL.Audio/src/Core/AudioEngineTimer.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/VL.Audio/src/Core/AudioEngineTimer.cs b/VL.Audio/src/Core/AudioEngineTimer.cs index ee0b471..facabda 100644 --- a/VL.Audio/src/Core/AudioEngineTimer.cs +++ b/VL.Audio/src/Core/AudioEngineTimer.cs @@ -8,6 +8,7 @@ namespace VL.Audio public class AudioEngineTimer { protected long FSamplePosition = 0; + protected long FContinousSamplePosition = 0; public AudioEngineTimer(int sampleRate) { FSampleRate = sampleRate; @@ -19,7 +20,8 @@ public AudioEngineTimer(int sampleRate) public void Progress(int samplesCount) { FSamplePosition += samplesCount; - + FContinousSamplePosition += samplesCount; + if (Loop && FLoopSampleLength > 0) { while(FSamplePosition >= (FLoopStartSample + FLoopSampleLength)) @@ -75,6 +77,8 @@ public long BufferStart return FSamplePosition; } } + + public long ContinousSamplePosition => FContinousSamplePosition; double FTime = 0; public double Time From 6da003c467b07c8b024453b8c471d5cab176f00b Mon Sep 17 00:00:00 2001 From: Elias Holzer Date: Fri, 1 Nov 2024 19:25:33 +0100 Subject: [PATCH 2/3] Allocates buffers on POC to avoid pinning overhead in audio thread (only did it for those used by VST) --- VL.Audio/src/Core/AudioSignal.cs | 22 ++++++++++++---------- VL.Audio/src/Core/MultiChannelSignal.cs | 9 +++++---- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/VL.Audio/src/Core/AudioSignal.cs b/VL.Audio/src/Core/AudioSignal.cs index 6bc5f36..5ccf8e1 100644 --- a/VL.Audio/src/Core/AudioSignal.cs +++ b/VL.Audio/src/Core/AudioSignal.cs @@ -1,8 +1,8 @@ - -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Reflection; +using System.Runtime.InteropServices; using NAudio.Wave; namespace VL.Audio @@ -123,15 +123,17 @@ public WaveFormat WaveFormat /// protected int SampleRate; protected int BufferSize; - protected float[] FReadBuffer = new float[1]; + protected float[] FReadBuffer; // used by tooltip public void GetInternalReadBuffer(out IReadOnlyList internalReadBuffer, out int lastReadCount) { - internalReadBuffer = FReadBuffer; + internalReadBuffer = FReadBuffer ?? Array.Empty(); lastReadCount = BufferSize; - } - + } + + public float[] ReadBuffer => FReadBuffer; + public bool NeedsBufferCopy { get; @@ -145,9 +147,9 @@ public int Read(float[] buffer, int offset, int count) if(true || NeedsBufferCopy) { //ensure internal buffer size and shrink size if too large - if (FReadBuffer.Length < count || FReadBuffer.Length > (count * 2)) + if (FReadBuffer is null || FReadBuffer.Length < count || FReadBuffer.Length > (count * 2)) { - FReadBuffer = new float[count]; + FReadBuffer = GC.AllocateArray(count, pinned: true); } //first call per frame @@ -167,11 +169,11 @@ public int Read(float[] buffer, int offset, int count) return count; } - + /// /// This method should be overwritten in the sub class to do the actual processing work /// - /// The buffer to fill + /// The buffer to fill. It is allocated on the POC and can therefor be used with /// Write offset for the buffer /// Count of samples need protected virtual void FillBuffer(float[] buffer, int offset, int count) diff --git a/VL.Audio/src/Core/MultiChannelSignal.cs b/VL.Audio/src/Core/MultiChannelSignal.cs index a163f4d..af4041f 100644 --- a/VL.Audio/src/Core/MultiChannelSignal.cs +++ b/VL.Audio/src/Core/MultiChannelSignal.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.InteropServices; #endregion usings @@ -51,7 +52,7 @@ public MultiChannelSignal() SetOutputCount(2); } - protected void SetOutputCount(int newCount) + public void SetOutputCount(int newCount) { //recreate output signals? if(FOutputCount != newCount) @@ -84,7 +85,7 @@ protected void ManageBuffers(int count) FReadBuffers = new float[FOutputCount][]; for (int i = 0; i < FOutputCount; i++) { - FReadBuffers[i] = new float[count]; + FReadBuffers[i] = GC.AllocateArray(count, pinned: true); (Outputs[i] as SingleSignal).SetBuffer(FReadBuffers[i]); } } @@ -101,11 +102,11 @@ protected void Read(int offset, int count) //since the buffers are already assigned to the SingleSignals nothing more to do } - + /// /// Does the actual work /// - /// + /// The buffers are allocated on the POC and therefor already pinned. /// /// protected virtual void FillBuffers(float[][] buffers, int offset, int count) From 1dd38ea5ff3352eecdcd0d98a18c8b269e7fe73f Mon Sep 17 00:00:00 2001 From: Elias Holzer Date: Fri, 8 Nov 2024 15:02:41 +0100 Subject: [PATCH 3/3] Version bump --- VL.Audio.UI/deployment/VL.Audio.UI.nuspec | 4 ++-- VL.Audio/deployment/VL.Audio.nuspec | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/VL.Audio.UI/deployment/VL.Audio.UI.nuspec b/VL.Audio.UI/deployment/VL.Audio.UI.nuspec index cfde61a..1130c73 100644 --- a/VL.Audio.UI/deployment/VL.Audio.UI.nuspec +++ b/VL.Audio.UI/deployment/VL.Audio.UI.nuspec @@ -2,7 +2,7 @@ VL.Audio.UI - 1.9.1 + 1.9.2 VL.Audio.UI vvvv vvvv @@ -11,7 +11,7 @@ Extension pack for VL.Audio that brings in UI's for driver configuration and more VL - + LGPL-3.0-only diff --git a/VL.Audio/deployment/VL.Audio.nuspec b/VL.Audio/deployment/VL.Audio.nuspec index d6e6699..a09acec 100644 --- a/VL.Audio/deployment/VL.Audio.nuspec +++ b/VL.Audio/deployment/VL.Audio.nuspec @@ -2,7 +2,7 @@ VL.Audio - 1.9.1 + 1.9.2 VL.Audio NAudio, vvvv vvvv