No sound for basic noise player in static library for iOS

I just created a static JUCE library for iOS that I imported in a parent iOS app.

In that library, I have two classes:

  • a noise source:
#pragma once
#include "JuceHeader.h"

class MyNoiseSource : public juce::AudioSource
{
public:
    MyNoiseSource() = default;
    void prepareToPlay(int samplesPerBlock, double sampleRate) override {}
    void releaseResources() override {}
    void getNextAudioBlock(const juce::AudioSourceChannelInfo& bufferToFill) override
    {
        for (auto channel = 0; channel < bufferToFill.buffer->getNumChannels(); ++channel)
        {
            auto* buffer = bufferToFill.buffer->getWritePointer (
                channel,
                bufferToFill.startSample);
            for (auto a = 0 ; a < bufferToFill.numSamples ; a++)
			{
				buffer[a] = random.nextFloat() * 0.25f - 0.125f;
			}
        }
    }
private:
    juce::Random random;
};
  • a noise player:
#pragma once
#include "JuceHeader.h"
#include "MyNoiseSource.h"

class MyNoisePlayer
{
public:
    MyNoisePlayer()
    {
        source = std::make_unique<MyNoiseSource>();
        player = std::make_unique<juce::AudioSourcePlayer>();
        player->setSource(source.get());
        deviceManager.addAudioCallback(player.get());
    }

    void play()
    {
        deviceManager.initialise(0, 2, nullptr, false);
        // deviceManager.playTestSound();
    }

private:
    std::unique_ptr<juce::AudioSource> source;
    std::unique_ptr<juce::AudioSourcePlayer> player;
    juce::AudioDeviceManager deviceManager;
    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MyNoisePlayer)
};

But for some reason, there is no sound when I call the play() function, even if I uncomment the deviceManager.playTestSound() line.

Did I forget something?

Thanks.

My bad, the code is perfectly working. The play() function was called from another class, that I instantiated in a function instead of making it a class attributeā€¦ :smirk: