I am using AudioSourcePlayer with AudioTransportSource to play wav files of drum samples when a user hits a midi note on the keyboard. When the sound plays, it sounds kind of like its clipping - this is especially evident on the kick drum samples, but affects all of the files I have tried to play. I’ve played around with setting readAheadThread thinking that would help, but it sounds exactly the same even with a buffer. When I play the same files using the SoundPlayer class the playback is perfect, so I don’t think its anything directly related to my AudioDeviceManager initialization. My understand, though, is that the SoundPlayer class will just play the sound and won’t actually pass it into the DAW when the track is bounced. Not to mention it doesn’t seem to allow setting the gain of the playback which is something I need.
This seems like a simple enough thing to do so I feel like I’m probably overlooking something obvious. It’s probably also worth noting that I’ve been testing using the Plugin Host app. When I load the plugin into Cubase, the first note i hit crashes the VST bridge and doesn’t actually play at all. This is not the case when using the SoundPlayer class though.
Here is some of the code from my Processor class’s constructor:
formatManager.registerBasicFormats();
//deviceManager.addAudioCallback(&player);
audioSourcePlayer.setSource(&transportSource);
deviceManager.addAudioCallback(&audioSourcePlayer);
deviceManager.initialise(2, 2, 0, true, String::empty, 0);
Here is the code I am using inside the handleNoteOn method - any ideas on what could be happening?:
if (file.exists()) {
AudioFormatReader* reader = formatManager.createReaderFor(file);
if (reader != nullptr)
{
ScopedPointer<AudioFormatReaderSource> newSource = new AudioFormatReaderSource(reader, true);
transportSource.setSource(newSource, 0, nullptr, reader->sampleRate);
transportSource.start();
readerSource = newSource.release();
//player.play(file);
}
}
Thanks in advance to anyone taking the time to look at this.