Can't process an instance of Kontakt 5 offline


#1

Hello,

I’m really new into juce and I’m trying to understand why when i try to process an midifile offline by my vst it doesn’t make any sound

This is how i open my plugin

//Class Attributes:
//  std::vector< OwnedArray<juce::PluginDescription> *> Descs;
//  std::vector<AudioPluginInstance*>  Plugins;

for (int i = 0; i < Descs.size(); i++) {
  for (int u = 0; u < Descs[i]->size(); u++) {
    if ((*Descs[i])[u]->pluginFormatName != k)
      continue;
    else {
      if (v == (*Descs[i])[u]->name) {
        String s;
        Plugins.push_back( pluginManager.createPluginInstance(*(*Descs[i])[u], this->sampleRate, deviceManager.getCurrentAudioDevice()->getDefaultBufferSize(), s));
        Plugins[0]->setProcessingPrecision(AudioProcessor::singlePrecision);
        Plugins[0]->setPlayConfigDetails(2, 2, this->sampleRate, deviceManager.getCurrentAudioDevice()->getDefaultBufferSize());
        Plugins[0]->prepareToPlay(this->sampleRate, deviceManager.getCurrentAudioDevice()->getDefaultBufferSize());
        Plugins[0]->setNonRealtime(true);
        pluginid = GraphProc.addNode(Plugins[0])->nodeId;
        std::cout << "Error: [" << s << "]" << std::endl;
      }
    }
  }
}

we load kontakt 5 then in the contact 5 window we load an instrument then when the user click on a button we process a midi file

MidiBuffer *Test::ProcessMidiFile(std::string pathFile) {
  File f(pathFile);
  FileInputStream stream(f);
  MidiFile mfile;
  MidiBuffer *buff = new MidiBuffer();
  if (!mfile.readFrom(stream)) {
    std::cout << "Couldn't Read The Midi file " << pathFile << std::endl;
    exit(-1);
  }
  mfile.convertTimestampTicksToSeconds();
  for (int index = 0; index < mfile.getNumTracks(); index++) {
    const MidiMessageSequence* seq = mfile.getTrack(index);
    for (int i = 0; i < seq->getNumEvents(); i++) {
      MidiMessageSequence::MidiEventHolder *holder = seq->getEventPointer(i);
      buff->addEvent(holder->message, holder->message.getTimeStamp() * this->sampleRate);
    }
  }
  return buff;
}

void Test::ProcessMidiThroughAudioSampleBuffer(MidiBuffer* midiBuffers) {
  float numSamplesToAllocate = midiBuffers->getLastEventTime() + 1.0;
  AudioSampleBuffer* audio = new AudioSampleBuffer(2, numSamplesToAllocate);
  Plugins[0]->processBlock(*audio, *midiBuffers);
  audio->applyGain(1.0 / audio->getMagnitude(0,  audio->getNumSamples()));
  File f("/tmp/test.wav");
  FileOutputStream outputfile(f);
  WavAudioFormat format;
  StringPairArray p;
  AudioFormatWriter* writer = format.createWriterFor(&outputfile,
          format.getPossibleSampleRates()[6], 1, // 44100, Mono
          format.getPossibleBitDepths()[1], p, 0);// [] = 16, p,

  writer->writeFromAudioSampleBuffer(*audio, 0, audio->getNumSamples());

}

The size of the file is the one excepted and the duration of the wav is also the one excepting.
But the wav is empty of sound.

Does anyone has an idea ?


#2

Hey,

If my post is unclear or if i can add informations to get help… let me know.


#3

Hi.

Which plugin are you trying to load actually?

Anyway, not sure if createPluginInstance is enough to have a plugin up-and-running. I also wonder if this method called setRealtime has any influence on the behavior of the plugin.

Perhaps you should rather use AudioProcessorGraph and add your plugin as a new node as it’s done in Juce’s Plugin Host. You could then use the regular AudioProcessorPlayer and AudioDeviceManager altogether to see if you’re at least able to process anything in real-time. Then the offline processing shouldn’t be an issue.

Hope it helps but perhaps guys who’re used to using AudioProcessorGraph could show up here?


#4

Hello,

So i’m trying to load Kontakt 5.

After getting some help i changed a few lines of codes.

void Test::MyLoadPlugin(const String k, const String v) {
  for (int i = 0; i < Descs.size(); i++) {
    for (int u = 0; u < Descs[i]->size(); u++) {
      if ((*Descs[i])[u]->pluginFormatName != k)
        continue;
      else {
        String s;
        if (v == (*Descs[i])[u]->name) {
          Plugins.push_back( pluginManager.createPluginInstance(*(*Descs[i])[u], this->sampleRate, deviceManager.getCurrentAudioDevice()->getDefaultBufferSize(), s));
          // For now we are only loading one plugins so we can directly use Plugins[0] during test.
          Plugins[0]->setProcessingPrecision(AudioProcessor::singlePrecision);
          Plugins[0]->setPlayConfigDetails(2, 2, this->sampleRate, deviceManager.getCurrentAudioDevice()->getDefaultBufferSize());
          Plugins[0]->prepareToPlay(this->sampleRate, deviceManager.getCurrentAudioDevice()->getDefaultBufferSize());
          Plugins[0]->setNonRealtime(true);
          std::cout << "Error: [" << s << "]" << std::endl;
        }
      }
    }
  }
}


void Test::ProcessMidiThroughAudioSampleBuffer(MidiBuffer* midiBuffers) {
  float numSamplesToAllocate = midiBuffers->getLastEventTime() + 1.0;
  AudioSampleBuffer* audio = new AudioSampleBuffer(8, numSamplesToAllocate);
  audio->clear();
  Plugins[0]->processBlock(*audio, *midiBuffers);
  //audio->applyGain(1.0 / audio->getMagnitude(0,  audio->getNumSamples()));

  File f("/tmp/test.wav");
  FileOutputStream outputfile(f);
  WavAudioFormat format;
  StringPairArray p;
  AudioFormatWriter* writer = format.createWriterFor(&outputfile, format.getPossibleSampleRates()[6], 1, // 44100, Mono
                                                     format.getPossibleBitDepths()[1], p, 0);// [] = 16, p,

   writer->writeFromAudioSampleBuffer(*audio, 0, audio->getNumSamples());
}

But i still got no sound going process in my file


#5

Perhaps renaming the title to something like “Cannot manage to process an instance of Kontakt 5 offline” might bring further people aboard.