Audio output doesn't work

Jul 30, 2010 at 10:04 AM
Edited Jul 30, 2010 at 10:12 AM
Hi, I'm writing an VST instrument. I've implemented both MidiProcessor and AudioProcessor according to samples codes and documentation. I tested MidiProcessor and it works correctly. Then I copied code from documentation (sends data from input channel to output channel) but in host application (Cubase SX 3), it doesn't produce any sound. I'm pasting my code. Please, could you help me and tell me where's the problem? Thanks very much.

internal class Plugin : VstPluginWithInterfaceManagerBase
{
public Core Core { get; private set; }

public Plugin(): base(
"VSTi", new VstProductInfo("VSTi", "olesh", 0900), VstPluginCategory.Synth, VstPluginCapabilities.NoSoundInStop, 0, 36373435)
{
Core = new Core();
}
protected override IVstPluginAudioProcessor CreateAudioProcessor(IVstPluginAudioProcessor instance)
{
if (instance == null) return new AudioProcessor(this);
return base.CreateAudioProcessor(instance);
}

protected override IVstMidiProcessor CreateMidiProcessor(IVstMidiProcessor instance)
{
if (instance == null) return new MidiProcessor(this);
return base.CreateMidiProcessor(instance);
}
}

internal class AudioProcessor : IVstPluginAudioProcessor
{
private Plugin plugin;

public AudioProcessor(Plugin plugin)
{
this.plugin = plugin;
}

public void Process(VstAudioBuffer[] inputs, VstAudioBuffer[] outputs)
{
VstAudioBuffer input = inputs[0];
VstAudioBuffer output = outputs[0];

for (int index = 0; index < output.SampleCount; index++)
{
output[index] = input[index];
}

input = inputs[1];
output = outputs[1];

for (int index = 0; index < output.SampleCount; index++)
{
output[index] = input[index];
}

}

public bool SetPanLaw(VstPanLaw vpl, float f)
{
return false;
}

public int BlockSize { get; set; }
public int InputCount
{
get { return 2; }
}
public int OutputCount
{
get { return 2; }
}
public float SampleRate { get; set; }
public int TailSize
{
get { return 0; }
}
}
Coordinator
Jul 30, 2010 at 10:22 AM
olesh wrote:
Hi, I'm writing an VST instrument. I've implemented both MidiProcessor and AudioProcessor according to samples codes and documentation. I tested MidiProcessor and it works correctly.

Then I copied code from documentation (sends data from input channel to output channel) but in host application, it doesn't produce any sound.
I'm pasting my code. Please, could you help me and tell me where's the problem?

Thanks very much.

internal class Plugin : VstPluginWithInterfaceManagerBase
{
   public Core Core { get; private set; }
   public Plugin(): base( "VSTi", new VstProductInfo("VSTi", "olesh", 0900), VstPluginCategory.Synth, VstPluginCapabilities.NoSoundInStop, 0, 36373435)
   { Core = new Core(); } 
   protected override IVstPluginAudioProcessor CreateAudioProcessor(IVstPluginAudioProcessor instance)
   {
     if (instance == null) return new AudioProcessor(this);
     return base.CreateAudioProcessor(instance);
   }
   protected override IVstMidiProcessor CreateMidiProcessor(IVstMidiProcessor instance)
   {
     if (instance == null) return new MidiProcessor(this);
    return base.CreateMidiProcessor(instance);
   }
}

internal class AudioProcessor : IVstPluginAudioProcessor
{
   private Plugin plugin;
   public AudioProcessor(Plugin plugin)
  { this.plugin = plugin; }
   public void Process(VstAudioBuffer[] inputs, VstAudioBuffer[] outputs)
   {
     VstAudioBuffer input = inputs[0];
     VstAudioBuffer output = outputs[0];
     for (int index = 0; index < output.SampleCount; index++)
     {
       output[index] = input[index];
     }
     input = inputs[1];
     output = outputs[1];
     for (int index = 0; index < output.SampleCount; index++)
     { output[index] = input[index]; }
    }
   public bool SetPanLaw(VstPanLaw vpl, float f)
   { return false; }
  public int BlockSize { get; set; }
  public int InputCount { get { return 2; } }
  public int OutputCount { get { return 2; } }
   public float SampleRate { get; set; }
   public int TailSize { get { return 0; } }
}

I took the liberty to format the text a bit, otherwise it was impossible to read.

Well, a VST instrument is a Plugin that converts midi notes to audio. So you have to generate audio in the AudioProcessor. I don't think many host applications will supply audio to a VSTi (although they should when it has inputs) so copying input to output will not likely result in sound. You have to queue up those midi events that your plugin receives (ProcessEvents) and produce sounds for those events during AudioProcessor.Process. The MidiNoteSampler sample sort of does this (and it also records).

One easy way to check if all is working is to fill the output buffers with random numbers (this will sound terrible) when you receive midi input. Then at least you can check if the host wires your plugin correctly.

Hope it helps.

Jul 30, 2010 at 11:43 AM
Hi, I tried it but it also doesn't work. Do you have any idea where the problem could be?
Coordinator
Jul 30, 2010 at 11:48 AM

No sorry, not without seeing more code...

Jul 30, 2010 at 1:32 PM
Edited Jul 30, 2010 at 1:33 PM
Here is all of it:
Core
Plugin
Soundfont
Coordinator
Jul 31, 2010 at 7:08 AM

In your Core class you set the canPlay flag to false in ProcessNoteOnEvent (last statement). So during the Core.PlayAudio method (called from the AudioProcessor) all logic for playing the sound is skipped.

Did I interpret this correcly?

Hope it helps.

Jul 31, 2010 at 2:57 PM

Hi, I re-writed my code, because after reading your answer I realised that it doesn't make sense. I tried the simplest function you recommanded (random numbers) and now it plays something. Thank you very much.

By the way, your work is brilliant ;-) thanks also for that.