Search code examples
c++vb.netvst

What is VST inputs value range


I'm trying to learn how DSPs work by porting some simple open source VST (writen in C++) to VB.NET language.
(I'm not familiar with C language much, I can read it only.)
Although I've copy line-by-line the VST processing code, it not works, the sound result is very terrible.
I don't know whether my translated code was wrong or the VST inputs value range is diffirent from mine.

I found that the processReplacing method in VST is almost writen in the same format

<!-- language: cpp -->
void Compressor::processReplacing(float **inputs, float **outputs, VstInt32 sampleFrames) {
    float *inputsL = inputs[0];
    float *inputsR = inputs[1];
    float *outputsL = outputs[0];
    float *outputsR = outputs[1];
    while(--sampleFrames >= 0) {
        float inL = *inputsL++;
        float inR = *inputsR++;
        // some code here
        *outputsL++ = outL;
        *outputsR++ = outR;
    }
}

and I translated it into VB.NET likes this:

<!-- language: vb -->
Public Sub processReplacing(inputs As Single(), count As Integer)
    For i = 0 To count - 1 Step 2
        inL = inputs(i)
        inR = inputs(i + 1)
        ' some code here
        inputs(i) = outL
        inputs(i + 1) = outR
    Next
End Sub

My VB.NET input values is between [-1..1] (32 bit IEEE float format), and it's 1-d array (L,R,L,R...)
I want to clarify 2 things:

  1. Does VST input and my VB.NET input is the same format?
  2. My VB.NET code is translated correctly or am I mistaken?

Solution

  • You are using a single - single dimension array, but the processReplacing C++ code has two (inputs/outputs) multi dimension arrays. Each channel (L/R) is in a different (sub) array and the samples are sequential with a range of [-1.0,1.0]

    float *inputsL = inputs[0];
    float *inputsR = inputs[1];
    float *outputsL = outputs[0];
    float *outputsR = outputs[1];
    

    These extract the channels from the multi dimensional arrays. Statements like this:

    *outputsL++
    

    Will increment the index and access the value (in one statement - thats C++ ;-)

    You should use VST.NET that takes care of all these details so you can focus on the DSP logic you are trying to learn.

    Hope it helps, Marc