#include "../JuceLibraryCode/JuceHeader.h" class MainContentComponent : public AudioAppComponent{ public: MainContentComponent() : random(Random()) { addAndMakeVisible(levelslider); addAndMakeVisible(levellabel); levelslider.setRange(0.0, 1.0); levelslider.setValue(0.5); levelslider.setTextBoxStyle(Slider::TextBoxRight, false, 100, 20); levellabel.setText("Level", dontSendNotification); setSize(800, 600); setAudioChannels(2, 2); } ~MainContentComponent() { shutdownAudio(); } void prepareToPlay(int, double) override {} void getNextAudioBlock(const AudioSourceChannelInfo& buf) override { AudioIODevice* device = deviceManager.getCurrentAudioDevice(); const BigInteger ic = device->getActiveInputChannels(); const BigInteger oc = device->getActiveOutputChannels(); const int mic = ic.getHighestBit() + 1; const int moc = oc.getHighestBit() + 1; const float l = (float) levelslider.getValue(); for (int c = 0; c < moc; ++c) { if (!oc[c] || !moc) buf.buffer->clear (c, buf.startSample, buf.numSamples); else { const int ac = c % mic; if (!ic[c]) buf.buffer->clear(c, buf.startSample, buf.numSamples); else { const float* ib = buf.buffer->getReadPointer(ac, buf.startSample); float* ob = buf.buffer->getWritePointer(c, buf.startSample); for (int s = 0; s < buf.numSamples; ++s) ob[s] = ib[s] * random.nextFloat() * l; } } } } void releaseResources() override {} void paint(Graphics& g) override { g.fillAll(getLookAndFeel().findColour (ResizableWindow::backgroundColourId)); } void resized() override { levellabel.setBounds(10, 10, 90, 20); levelslider.setBounds(100, 10, getWidth() - 110, 20); } private: JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainContentComponent) Random random; Slider levelslider; Label levellabel; }; Component* createMainContentComponent() { return new MainContentComponent(); }