Created
May 10, 2019 13:47
-
-
Save Xenakios/613b19e886d9cda44cc883688b091eb0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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