Questions about wavManipulation, Synthesizer and Midi Issues



Im working on a sampler Plug-in. I have already built a simple Plugin with Juce and have basic C++ knowledge, but still I would call myself a newbie… In this Thread I will post some questions which (maybe 8) 8) ) come up while writing my Sampler.

Thanks in anticipation for ur help!

Here is my first question:

All I want to do is to read a .wav File from a certain Directory (like ‘C:/…’), to put it into a SynthesiserVoice.
I tried to figure out how WavAudioFormat Class works, but I dont get the point what a stream is.
The Demo is loading a MemoryInputStream from a namespace called “BinaryData” - and in BinaryData.cpp there is a char array if the cello.wav . Whats going on there?

And what do I have to do? Do I need to use a ScopedPointer too, or is a normal c++ Pointer sufficient (deleted in the Destructor of the Audioprocessor)?
Due to the fact, that I will use the wav File for a sampler, It would be ok if I put the Sample(s) in some kind of “Binary Data” Folder, like it is done by the JUCE demo. But for the beginng an absolut path would be OK too - my goal for this week is to click on a MidiKeyboardComponent and hear a sound…

Greetz equinox


The BinaryData class is only used because in that case because the sample data is directly embedded with the app.

If you want to load a sample from the filesystem, create a FileInputStream instead of a MemoryInputStream and pass that to wavFormat.createReaderFor


Ah, thanks, this problem is fixed.

I tried the hole day getting this thing make some sound - but it is not working ahh.
Is the SamplerSound Class doing all the Pitch Issues you can hear in the Juce demo?

So my AudioProcessor (hope this is the right place for the code…) looks like this:

File MeinSample = “C:\cello.wav”;
WavAudioFormat wavFormat;

ScopedPointer<AudioFormatReader> audioReader (wavFormat.createReaderFor (new FileInputStream (MeinSample),true));

    // Initialise the synth...
for (int i = 4; --i >= 0;)
meinSynth.addVoice (new myVoice());

BigInteger allNotes;
allNotes.setRange (0, 128, true);
meinSynth.addSound (new SamplerSound ("Mein_Sound",
                                      74,   // root midi note
                                      0.1,  // attack time
                                      0.1,  // release time
                                      10.0  // maximum sample length

Copied from the Juce Demo my canPlaySound Method looks like this:
(I dont have a mySound class so the Type in the dynamic_cast ist Sampler_Sound, hope this is legal…)

bool canPlaySound (SynthesiserSound* sound) { return dynamic_cast <SamplerSound*> (sound) != 0; }

My StartNote Method is empty, in the demo it is only neccessary as a part of the generated sin wav, am i right?

In my StopNote Method theres just written clearCurrentNote();

The processBlock Method of the Audioprocessor Class looks like this:

[code] const int numSamples = buffer.getNumSamples();
int channel = 0;

// Now pass any incoming midi messages to our keyboard state object, and let it
// add messages to the buffer if the user is clicking on the on-screen keys
keyboardState.processNextMidiBuffer (midiMessages, 0, numSamples, true);

// and now get the synth to process these midi events and generate its output.
meinSynth.renderNextBlock (buffer, midiMessages, 0, numSamples);

// In case we have more outputs than inputs, we'll clear any output
// channels that didn't contain input data, (because these aren't
// guaranteed to be empty - they may contain garbage).
for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
    buffer.clear (i, 0, buffer.getNumSamples());[/code]

In prepareToPlay is written
meinSynth.setCurrentPlaybackSampleRate (sampleRate);

What is missing / What Im doing wrong?

Thaaaaaanks folks! 8)


OK i spezified my problem… admitted the text above was a little bit long :slight_smile:

So because i recently discovered the Juce Plugin-Host for Debugging (my world is a better place now) I figured out that my a problem has sth to deal with SynthesiserVoices.

when I hit a key in the Plug-In Host or on my KeyboardComponent the Visual Studio Debugger stops in the method “findFreeVoices” of Synthesiser here:

jassert (oldest != 0);

this means that voice != 0 .

My SynthesiserVoice is copied from the demo now…
SamplerSound seems to work, due to the fact that in soundToPlay in findeFreeVoices has the right Samplerate.

stealIfNoneAvailable is also true, so sth with the stealing is not working.
Where could I find the key to this problem?

Hope somebody can help me,



Have you actually added your voices to the synth?


yes, in the AudioProcessor Constructor:

for (int i = 4; --i >= 0;)
meinSynth.addVoice (new myVoice());

the i variable in findFreeVoices seems very big, here the findFreeVoices with StopPoint:

	i	37025248	int
  •   this	0x02507b18 {lock={...} voices={...} sounds={...} ...}	const juce::Synthesiser * const
  •   soundToPlay	0x02508000 {name={...} data={...} sourceSampleRate=44100.000000000000 ...}	juce::SynthesiserSound *
      stealIfNoneAvailable	true	const bool
  •   sl	{lock_={...} }	const juce::ScopedLock

and here when the Debugging stops the program:
i -1 int

  •   oldest	0x00000000 {currentSampleRate=??? currentlyPlayingNote=??? noteOnTime=??? ...}	juce::SynthesiserVoice *
      i	-1	int
  •   this	0x02807b18 {lock={...} voices={...} sounds={...} ...}	const juce::Synthesiser * const
  •   soundToPlay	0x02808000 {name={...} data={...} sourceSampleRate=44100.000000000000 ...}	juce::SynthesiserSound *
      stealIfNoneAvailable	true	const bool
  •   sl	{lock_={...} }	const juce::ScopedLock

hope this helps…


Looks like a dangling pointer to me - if the i variable is garbage, then so is the synth object that you’re trying to use.


my last problem is fixed, i rebuild my project and did everything step by step… and yeah, it worked!

No I want to loop a sampled sound (the sound starts to play from beginning when the midikey is pressed down…) - I searched in this forum for this issue, but found no way which worked for me…

Has anyone some basic ideas how to implemente a looper in the SamplerSound/Voice Classes?
In which functions do I have to write this stuff?

I tried to create a sampleBuffer and copy the wav-data, in the startNote function.
but when do i need to call this samplebuffer? when --numSamples<= 0 in the renderNextBlock function?

I am thankful vor ANY kind of help!