All times are UTC+01:00




Post new topic  Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Mon Jan 13, 2025 5:57 pm 

Joined: Mon Jan 13, 2025 5:45 pm
Posts: 2
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;
        }
    }
}


Top
   
PostPosted: Wed Jan 15, 2025 3:11 pm 

Joined: Mon Jun 11, 2018 11:38 am
Posts: 98
It looks to me like
Code:
IVstHostCommandStub 
is in a namespace
Code:
Host
that you're not "using", so maybe changing it to
Code:
Host::IVstHostCommandStub
would help?

But this is a bit out-of-scope for the StereoTool forums. We (the ST developers) don't have experience with C# or VST.NET2, and you're not having an ST problem: you're having a problem of getting VST.NET2 to work in your application. Your best bet for help would probably be them. Or maybe StackOverflow (hate their condescending mods though).

I should point out that we also have the Windows libStereoTool plugin version of the software, which just exposes a few "simple" functions that can process an array of samples.
The (sparse) documentation for it can be found in the libStereoTool.h header file that's included in the plugin zip.


Top
   
PostPosted: Mon Jan 20, 2025 10:21 am 

Joined: Mon Jan 13, 2025 5:45 pm
Posts: 2
Thanks TJ for your input - I tried the Host:: prefix but still no joy - I still get

The type or namespace name 'IVstHostCommandStub' could not be found (are you missing a using directive or an assembly reference?)

All the documentation says that the definition for IVstHostCommandStub is in the VST libraries I am using - as in

using Jacobi.Vst.Core;
using Jacobi.Vst.Host;

So I feel perhaps there is some deeper mismatch at work here.
I will look for a VST.Net forum to see if anyone there has any insights - or put it on StackExchange if that fails.

Thanks agaiin.
Alan T


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 3 posts ] 

All times are UTC+01:00


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited