views:

222

answers:

2

Hello, I'm trying to use the VST.Net and NAudio frameworks to build an application that processes audio using a VST plugin.

Ideally, the application should load a wav or mp3 file, process it with the VST, and then write a new file.

I have done some poking around with the VST.Net library and was able to compile and run the samples (specifically the VST Host one). What I have not figured out is how to load an audio file into the program and have it write a new file back out.

I'd like to be able to configure the properties for the VST plugin via C#, and be able to process the audio with 2 or more consecutive VSTs.

Using NAudio, I was able to create this simple script to copy an audio file. Now I just need to get the output from the WaveFileReader into the VST.Net framework somehow.

  private void processAudio()
    {
        reader = new WaveFileReader("c:/bass.wav");
        writer = new WaveFileWriter("c:/bass-copy.wav", reader.WaveFormat);
        int read;
        while ((read = reader.Read(buffer, 0, buffer.Length)) > 0)
        {
            writer.WriteData(buffer, 0, read);
        }

        textBox1.Text = "done";

        reader.Close();
        reader.Dispose();
        writer.Close();
        writer.Dispose();
    }

Please help!! Thanks

References:

http://vstnet.codeplex.com (VST.Net)

http://naudio.codeplex.com (NAudio)

+1  A: 

I think you'll find your answer here: http://vstnet.codeplex.com/Thread/View.aspx?ThreadId=205889

The conversion you need to do consists of two things:

1) convert the interlaced format to seperate channels. A Waf file combines the samples for left and right into one buffer. in a VST plugin each channel has its own buffer.

2) Convert a byte value to a float within range [-1,+1]. The byte values in the waf file need to be converted to a float value in range between -1.0 and +1.0. f=(b/128.0)-1.0

Hope it helps.

PS: the discussion list on vstnet.codeplex.com contains several answers to common questions. It is a good start to look for a solution...

obiwanjacobi
Thanks Marc. I'm still trying to figure it out. I posted a response on that thread if you think you can help. I'm almost at the point where I would be willing to pay you or someone to write the class I need
Paul
A: 

I have tried all this but unable to get anything workable please help me out.

                int inputCount = PluginContext.PluginInfo.AudioInputCount;
                int outputCount = PluginContext.PluginInfo.AudioOutputCount;
                int blockSize = bytesWritten;                    

                VstAudioBufferManager inputMgr = new VstAudioBufferManager(inputCount, blockSize);
                VstAudioBufferManager outputMgr = new VstAudioBufferManager(outputCount, blockSize);

                foreach (VstAudioBuffer buffer in inputMgr.ToArray())
                {
                    for (int i = 0; i < blockSize; i++)
                    {
                        buffer[i] = (float)destBuffer[i] / 128.0f - 1.0f;
                    }
                }

                PluginContext.PluginCommandStub.SetBlockSize(blockSize);
                PluginContext.PluginCommandStub.SetSampleRate(44.8f);

                PluginContext.PluginCommandStub.StartProcess();
                PluginContext.PluginCommandStub.ProcessReplacing(inputMgr.ToArray(), outputMgr.ToArray());
                PluginContext.PluginCommandStub.StopProcess();                   

                foreach (VstAudioBuffer buffer in outputMgr.ToArray())
                {
                    for (int i = 0; i < blockSize; i++)
                    {
                        destBuffer[i] = Convert.ToByte(((float)buffer[i] + 1.0f) * 128.0f);                           
                    }                        
                }
                inputMgr.ClearBuffer(inputMgr.ToArray()[0]);
                inputMgr.ClearBuffer(inputMgr.ToArray()[1]);
                inputMgr.Dispose();
                outputMgr.ClearBuffer(outputMgr.ToArray()[0]);
                outputMgr.ClearBuffer(outputMgr.ToArray()[1]);
                outputMgr.Dispose();