VST.NET vs NAUDIO (vstaudiobuffer vs pcmstream buffer)

Mar 21, 2010 at 1:03 PM

Hi,

sorry for my poor english but thank you very much for your incredible work. VST.NET is fantastic.

I've neved developer VST plugin before now and I've met a problem passing a 'WAVESTREAM' data to the VSTAUDIOBUFFER.

First of all I would like to make a VST player (WAV, MP3 etc.) so I've build a VST plugin using VST.NET and NAUDIO.
The interface works well and for my first experiment I've created a 44100 STEREO standard WAV file.

For my fist basic experiment I've opened this file with NAUDIO to obtain the WAVESTREAM (PCM STREAM) class.
This class contains the stream buffer and using the READ command I read the number of samples that VSTAUDIOBUFFER[0] could receive.

Here starts my problems:

1. how can I split my WAVESTREAM stereo buffer to 2 VSTAUDIOBUFFER mono buffer?

2. which is the right way to pass the BYTE value returned in the WAVESTREAM buffer to the FLOAT VALUES required to the VSTAUDIOBUFFER? If I simply copy them from the input buffer to the output audiobuffer obviously doesn't works!

Thank you very much for all you can do me. When I've finish I would like to post the source code here in codeplex to let other people evaluate my work.

Coordinator
Mar 22, 2010 at 7:18 AM

Thanx!

1) I seem to remember that a wave file is interlaced. That mean that the first sample is for the left channel, the second sample for the right. The third sample for the left channel and the fourth for the right and so on. Not sure if NAudio has support to 'unlace' these samples into two buffers?

2) Well, the range for the float numbers is [-1.0,+1.0] and the max value for a byte is 255. So it a relation of 2:256. So if b is the byte value, then f (the float value) would be f=b/128.0 - 1.0.

Hope it helps.

Apr 2, 2010 at 3:49 PM

Thank you very much for your useful tip (sorry for the delay of my answer).

I havn't understand that the float audio buffer can contains positive and negative values with a range of +/- 1!!

The WAVESTEAM returned by NAUDIO is in 'lace' format so I've found a very convenient function to convet the byte buffer (4 bites for right channel, 4 bites for left channel) and split it up to the 2 separate VST audio buffers:

 

for (int nIn = 0; nIn < nSamplesIn; nIn += 8)
{
rightChannel[nOut] = System.BitConverter.ToSingle(SampleBuffer, nIn);
leftChannel[nOut] = System.BitConverter.ToSingle(SampleBuffer, nIn + 4);
nOut++;
}

All works well and thanks again for your support.

 

for (int nIn = 0; nIn < nSampleIn; nIn += 8)
                     {
                         rightChannel[nOut] = System.BitConverter.ToSingle(SampleBuffer, nIn);
                         leftChannel[nOut] = System.BitConverter.ToSingle(SampleBuffer, nIn + 4);
                         nOut++;
                     }
 

 

Apr 14, 2010 at 7:47 PM

Sorry, I'm really confused here. Can you please elaborate on this code?

 

for (int nIn = 0; nIn < nSamplesIn; nIn += 8)

{
 rightChannel[nOut] = System.BitConverter.ToSingle(SampleBuffer, nIn);
 leftChannel[nOut] = System.BitConverter.ToSingle(SampleBuffer, nIn + 4);
 nOut++;
}

What is the type of rightChannel[nOut], and more generally how do I use this to input into the VST.Net framework?

Thanks!

Paul

 

Coordinator
Apr 20, 2010 at 2:49 PM
Edited Apr 20, 2010 at 2:54 PM

Sorry about the late answer, been really busy.

This is not my code and I do not think it is correct.

It grabs 4 bytes and turns those into a float. To my knowledge a single byte value represents one sample. So in effect there is resampling going on here (divided by 4), not to mention the actual value you end up with is bogus.

I would do something like this (assuming the max byte sample value can be 255):

for (int nIn = 0; nIn < nSamplesIn; nIn += 2)
{
 rightChannel[nOut] = ((float)SampleBuffer[nIn] / 128.0) - 1.0;
 leftChannel[nOut] = ((float)SampleBuffer[nIn + 1] / 128.0) - 1.0;
 nOut++;
}

Disclaimer: have not compiled the code ;-)

The typical range for a VST audio channel sample value lies between -1.0 and +1.0. So that is a range of 2.0 over the zero-axis. To create a value of max 2.0 from a byte (with max 255) I divide by 128 (perhaps 127.5 would be more correct ;-). This will get you values of min 0.0 and max 2.0. Now shift the value down by 1.0 to get to the -1.0 ans +1.0.

Is it less confusing now? ;-)

Hope it helps.

Jun 20, 2010 at 9:44 PM

I have tried all above solutions but nothing works for me.

Please send code which converts from

byte[] Buffer

to

VstAudioBufferManager inputMgr = new VstAudioBufferManager(inputCount, blockSize);
VstAudioBuffer rightInputBuffer = inputMgr.ToArray()[0];
VstAudioBuffer leftInputBuffer = inputMgr.ToArray()[1];

what should i do to populate rightInputBuffer and leftInputBuffer?

Thanks