Created
October 2, 2020 19:29
-
-
Save Xenakios/74c6d1bfdd470639c0ce5d401c3ca5b9 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 Noise : public juce::AudioSource | |
{ | |
public: | |
void prepareToPlay(int samplesPerBlockExpected, double sampleRate) override | |
{ | |
// initialise the filter object | |
juce::dsp::ProcessSpec spec; | |
spec.maximumBlockSize = samplesPerBlockExpected; | |
spec.sampleRate = sampleRate; | |
spec.numChannels = 1; | |
filter.prepare(spec); | |
filter.setCutoffFrequency(500.0); // set a pretty low cut off frequency to make it really noticeable | |
} | |
void releaseResources() override | |
{ | |
// nothing to do here, we don't have anything to release | |
} | |
void getNextAudioBlock(const juce::AudioSourceChannelInfo& bufferToFill) override | |
{ | |
bufferToFill.clearActiveBufferRegion(); | |
for (int i = 0; i < bufferToFill.numSamples; ++i) | |
{ | |
float noise = juce::jmap(rgen.nextFloat(),0.0f,1.0f,-1.0f,1.0f) * 0.1f; // generate output sample | |
float out = filter.processSample(0, noise); | |
// copy to all output channels | |
for (int j=0;j<bufferToFill.buffer->getNumChannels();++j) | |
{ | |
bufferToFill.buffer->setSample(j, i, out); | |
} | |
} | |
} | |
private: | |
juce::Random rgen; | |
juce::dsp::StateVariableTPTFilter<float> filter; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment