Created
October 2, 2020 19:00
-
-
Save Xenakios/4a4cfc3a66311cb1511da26ea57d6cea to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#include <JuceHeader.h> | |
class Noise : public juce::AudioSource | |
{ | |
public: | |
void prepareToPlay(int samplesPerBlockExpected, double sampleRate) override | |
{ | |
// nothing to do here, we can generate the noise without preparing anything | |
} | |
void releaseResources() override | |
{ | |
// nothing to do here, we didn't use anything to release | |
} | |
void getNextAudioBlock(const juce::AudioSourceChannelInfo& bufferToFill) override | |
{ | |
bufferToFill.clearActiveBufferRegion(); | |
auto bufferPointers = bufferToFill.buffer->getArrayOfWritePointers(); | |
for (int i = 0; i < bufferToFill.numSamples; ++i) | |
{ | |
float out = juce::jmap(rgen.nextFloat(),0.0f,1.0f,-1.0f,1.0f) * 0.1f; // generate output sample | |
// copy to all output channels | |
for (int j=0;j<bufferToFill.buffer->getNumChannels();++j) | |
{ | |
bufferPointers[j][i+bufferToFill.startSample] = out; | |
} | |
} | |
} | |
private: | |
juce::Random rgen; | |
}; | |
//============================================================================== | |
int main (int argc, char* argv[]) | |
{ | |
juce::ScopedJuceInitialiser_GUI gui_init; // even if this isn't a GUI app, the Juce message manager needs to be running | |
juce::AudioDeviceManager aman; | |
aman.initialiseWithDefaultDevices(0, 2); // 0 inputs, 2 outputs for the audio | |
juce::AudioSourcePlayer player; | |
Noise noiseSource; | |
player.setSource(&noiseSource); | |
aman.addAudioCallback(&player); | |
juce::Thread::sleep(1000); // keep the audio playing for 1 second (1000 milliseconds) | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment