How to play white noise in a JUCE library?

I’m currently working on my first JUCE library, targeting both Android and iOS.

I try to understand how to play a simple white noise, so I read this tutorial.

But reading the demo project, I can see that the main class inherits from juce::AudioAppComponent which, as far as I understand, provides a user interface.

But since I’m working on a library, I don’t want that user interface, so I’m looking for a way to play that white noise as shown in that tutorial, but without user interface.

I found out that there are also AudioTransportSource or AudioProcessor that could help me do the job, but I don’t really know what to use and where to start.

So how can I write a very basic white noise generator for a library (without any user interface, then)?


The AudioAppComponent is simply a Component having an AudioDeviceManager and an AudioSourcePlayer.
What I would do in your case is creating a class/struct that doesn’t inherit Component:

struct MyNoisePlayer
        source = std::make_unique<juce::ToneGeneratorAudioSource>();
        source->setFrequency (440.0f);
        source->setAmplitude (0.9f);
        player = std::make_unique<juce::AudioSourcePlayer>();
        player->setSource (source.get());
        deviceManager.addCallback (player.get());
        deviceManager.initialise (0, 2);
    std::unique_ptr<AudioSource>       source;
    std::unique_ptr<AudioSourcePlayer> player;
    juce::AudioDeviceManager           deviceManager;

And then just replace the ToneGeneratorSource with a custom AudioSource that creates the sound you want to have.

Hope that helps

1 Like

I can’t try that yet because of this, but I will as soon as I find a solution.