Plucked Strings Demos - Potential Add-Ons

Hi, I was experimenting with the PluckedStringsDemo in the DemoRunner in the Projucer and I was wondering if there was any way to produce the same effect, but instead use a different sound file instead of the standard string pluck sound. If so, could someone please point me to any resources to learn how to do this? Thanks!

Hello Rohansuresh,

The “PluckedStringsDemo” in JUCE is not using a sound file.
It is actually using some form of “physical modelling”.

That means: there is no sound file. Only an algorithm. More specifically: The Karplus-Strong algorithm. You can read more about the algorithm on Wikipedia:

In order to get a different sound, you have to change the algorithm.
As far as I understand, the Karplus-Strong algorithm is a simple form of digital waveguide synthesis. So you could also read up more on waveguides. Short introduction to digital waveguides by Julius O Smith:

Hope that helps!

1 Like

Maybe you are actually looking for a sampler demo? Then you have to open the “AudioSynthesiserDemo” in the DemoRunner. In the AudioSynthesiserDemo you can click on “use sampled” sound. Then you get a sampler. And the sampler really is loading a sound file. Have a look at the line

std::unique_ptr<AudioFormatReader> audioReader (wavFormat.createReaderFor (createAssetInputStream ("cello.wav"), true));

There the file loading happens

1 Like

Hi Alatar, thanks for your response it was very helpful. I tried using the AudioSynthesiserDemo but noticed that the app kept crashing every time I clicked the “Use Sampled Sound” button. Do you know what might be causing this issue? Thanks!

And to follow up on my previous question, would it be possible to use the “Build a MIDI synthesizer” demo to create something like the AudioSynthesiserDemo, and how would I allow for different files to be input as the sampled sound instead of the sin wave generator? Thanks in advance!

It does not do that for me. You should debug the demo and check, where the crash is coming from.

1 Like

Yes, that is possible.
You should be able to do it in the same way, as it is done in the “AudioSynthesiserDemo”.
Cant tell you any details right away, because I would need to take a closer look at the tutorial first.

1 Like

The SamplerSound and SamplerVoice classes inherit from SynthesiserSound and SynthesiserVoice, so the interface stays the same with a few additions, like the AudioFormatReader for the sample

1 Like

Thanks Alatar and daniel for your replies, I’ve definitely got a better understanding of how to make what I’m trying to make now. I am having issues with this line however:

std::unique_ptr<AudioFormatReader>audioReader (wavFormat.createReaderFor (createAssetInputStream ("Sound1.wav"), true));

I keep getting this error: Use of undeclared identifier ‘createAssetInputStream’.
I tried changing the file path to a file that I have on my laptop but that didn’t resolve the issue. Could this issue be linked to the fact that in the AudioSynthesiserDemo had these two include statements at the start of the code:
#include "../Assets/DemoUtilities.h"
#include "../Assets/AudioLiveScrollingDisplay.h"
but the code that I’m writing does not? I tried keeping the include statements but the files could not be found and the code would only build when I removed the include statements (and the function with the above code). Do you have any advice on how to resolve this issue?

seems to be a function. You must declare it somewhere. If it is not part of the JUCE class, which you are in.
If you are in Visual Studio, you can right-click on any function and select “Go To Definition”. If you do that in the demo, you can see, where it is declared.
Not sure how things work on XCode.

1 Like

Indeed, it is a free function, that is included from here:

But you can replace it with any function, that returns a pointer to an InputStream, can be FileInputStream from disk, MemoryInputStream from BinaryData or from a zipfile using ZipFile::createStreamForEntry()

1 Like

Thanks a lot for all the replies! I downloaded the DemoUtilities and included it in my program, and now everything is working.