Skip to content

Instantly share code, notes, and snippets.

@Xenakios
Created May 10, 2019 14:23
Show Gist options
  • Save Xenakios/360bdf5f99dd9d99b3cae800be35ca34 to your computer and use it in GitHub Desktop.
Save Xenakios/360bdf5f99dd9d99b3cae800be35ca34 to your computer and use it in GitHub Desktop.
// Requires the Juce audio_utils module for AudioProcessorPlayer
class MyAudioProcessor : public AudioProcessor
{
public:
MyAudioProcessor() {}
const String getName() const override { return "MyAudioProcessor"; }
void prepareToPlay(double sampleRate, int maximumExpectedSamplesPerBlock) override {}
void releaseResources() override {}
void processBlock(AudioBuffer<float>& buffer, MidiBuffer & midiMessages) override
{
for (int i = 0; i < buffer.getNumSamples(); ++i)
{
float sample = jmap(m_rnd.nextFloat(), 0.0f, 1.0f, -0.1f, 0.1f);
for (int j = 0; j < buffer.getNumChannels(); ++j)
{
buffer.setSample(j, i, sample);
}
}
}
double getTailLengthSeconds() const override { return 0.0; }
bool acceptsMidi() const override { return false; }
bool producesMidi() const override { return false; }
AudioProcessorEditor * createEditor() override { return nullptr; }
bool hasEditor() const override { return false; }
int getNumPrograms() override { return 0; }
int getCurrentProgram() override { return 0; }
void setCurrentProgram(int index) override {}
const String getProgramName(int index) override { return String(); }
void changeProgramName(int index, const String & newName) override {}
void getStateInformation(juce::MemoryBlock & destData) override {}
void setStateInformation(const void * data, int sizeInBytes) override {}
private:
Random m_rnd;
};
class MainComponent : public Component
{
public:
MainComponent()
{
m_adman.initialiseWithDefaultDevices(0, 2);
m_processorplayer.setProcessor(&m_aproc);
m_adman.addAudioCallback(&m_processorplayer);
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:
MyAudioProcessor m_aproc;
AudioProcessorPlayer m_processorplayer;
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