Skip to content

Instantly share code, notes, and snippets.

@Xenakios
Created May 10, 2019 13:47
Show Gist options
  • Save Xenakios/613b19e886d9cda44cc883688b091eb0 to your computer and use it in GitHub Desktop.
Save Xenakios/613b19e886d9cda44cc883688b091eb0 to your computer and use it in GitHub Desktop.
class MyAudioSource : public AudioSource
{
public:
MyAudioSource() {}
void prepareToPlay(int samplesPerBlockExpected, double sampleRate) override
{}
void releaseResources() override
{}
void getNextAudioBlock(const AudioSourceChannelInfo & bufferToFill) override
{
for (int i = 0; i < bufferToFill.numSamples; ++i)
{
float sample = jmap(m_rnd.nextFloat(), 0.0f, 1.0f, -0.1f, 0.1f);
bufferToFill.buffer->setSample(0, bufferToFill.startSample + i, sample);
bufferToFill.buffer->setSample(1, bufferToFill.startSample + i, sample);
}
}
private:
Random m_rnd;
};
class MainComponent : public Component
{
public:
MainComponent()
{
m_adman.initialiseWithDefaultDevices(0, 2);
m_aplayer.setSource(&m_asource);
m_adman.addAudioCallback(&m_aplayer);
setSize (600, 400);
}
~MainComponent()
{
}
void paint (Graphics& g) override
{
g.fillAll (getLookAndFeel().findColour (ResizableWindow::backgroundColourId));
g.setFont (Font (16.0f));
g.setColour (Colours::white);
g.drawText ("Hello World!", getLocalBounds(), Justification::centred, true);
}
void resized() override
{}
private:
MyAudioSource m_asource;
AudioSourcePlayer m_aplayer;
AudioDeviceManager m_adman;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainComponent)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment