x Posted from the NAudio Github forum.
Does anyone have a working c# example of using NAudio passing audio direct to StereoTool via VST?
This is a hobby project - not a commercial one making my own priivate "radio" intranet station. After a learning curve, I have a working NAudio player which schedules and plays audio files perfectly. I now need to take the output from that application and feed it into StereoTool which does volume levelling and various other processing. StereoTool supports VST.
https://www.thimeo.com/stereo-tool/
I am running on Windows 10.0 using Visual Studio 2022 (community edition) and (in accordance with the VST.NET2 instructions have set the target environment to be NET6.0. My project uses Winforms (with .net) template. CPU type is set to "x64;x86" in the project file XML.
So, as this is all new to me I asked CoPilot to find me code that would give me a simple-as-possible working example of this and the code it found/suggested is down below. My issue is that - even after installing NAudio and VST.NET2-Plugin using Nuget I am seeing a lot of errors which make me think that perhaps this code is old and out of date.
For example in the line
Code:
public class HostCommandStub : IVstHostCommandStub
{
I get error "IVstHostCommandStub could not be found" - even though have included the "using" statements indicated. It all smacks to me of version mismatches but I don't know enough to sort this out without help.
So, can anyone lighten my darkness or provide a working example. Thanks in advance.
==================
Instruction and Code from CoPilot AI: (yes, I did replace the WAV file name and the DLL location with my own).
Install-Package VST.NET2-Plugin
Code:
using System;
using NAudio.Wave;
using Jacobi.Vst.Core;
using Jacobi.Vst.Host.Interop;
public class HostCommandStub : IVstHostCommandStub
{
public IVstPluginContext PluginContext { get; set; }
public bool BeginEdit(int index) => false;
public VstCanDoResult CanDo(string cando) => VstCanDoResult.Unknown;
public bool CloseFileSelector(VstFileSelect fileSelect) => false;
public bool EndEdit(int index) => false;
public VstAutomationStates GetAutomationState() => VstAutomationStates.Off;
public int GetBlockSize() => 1024;
public string GetDirectory() => string.Empty;
public int GetInputLatency() => 0;
public VstHostLanguage GetLanguage() => VstHostLanguage.NotSupported;
public int GetOutputLatency() => 0;
public VstProcessLevels GetProcessLevel() => VstProcessLevels.Unknown;
public string GetProductString() => "VST.NET";
public float GetSampleRate() => 44100f;
public VstTimeInfo GetTimeInfo(VstTimeInfoFlags filterFlags) => null;
public string GetVendorString() => "VendorString";
public int GetVendorVersion() => 2400;
public bool IoChanged() => false;
public bool OpenFileSelector(VstFileSelect fileSelect) => false;
public bool ProcessEvents(VstEvent[] events) => false;
public bool SizeWindow(int width, int height) => false;
public bool UpdateDisplay() => true;
}
using System;
using NAudio.Wave;
using Jacobi.Vst.Core;
using Jacobi.Vst.Host.Interop;
namespace AudioApp
{
class Program
{
static void Main(string[] args)
{
// Initialize the audio engine
using (var waveOut = new WaveOutEvent())
{
// Create the host command stub
var hostCommandStub = new HostCommandStub();
// Load the VST plugin
var vstPluginContext = VstPluginContext.Create("path_to_stereotool_vst.dll", hostCommandStub);
// Create a wave provider from your existing audio source
var audioFileReader = new AudioFileReader("path_to_your_audio_file.wav");
// Create a VST wave provider
var vstWaveProvider = new VstWaveProvider(vstPluginContext, audioFileReader);
// Set the wave provider to the output device
waveOut.Init(vstWaveProvider);
// Play the audio
waveOut.Play();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}
}
public class VstWaveProvider : IWaveProvider
{
private readonly VstPluginContext vstPluginContext;
private readonly IWaveProvider sourceProvider;
public VstWaveProvider(VstPluginContext vstPluginContext, IWaveProvider sourceProvider)
{
this.vstPluginContext = vstPluginContext;
this.sourceProvider = sourceProvider;
}
public WaveFormat WaveFormat => sourceProvider.WaveFormat;
public int Read(byte[] buffer, int offset, int count)
{
// Read audio data from the source provider
int bytesRead = sourceProvider.Read(buffer, offset, count);
// Process the audio through the VST plugin
vstPluginContext.PluginCommandStub.ProcessReplacing(buffer, offset, bytesRead);
return bytesRead;
}
}
}