Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include "Osc.h"
- class SpectrogramComponent : public AudioAppComponent,
- private Timer
- {
- public:
- SpectrogramComponent()
- : spectrogramImage(Image::RGB, 512, 512, true) {
- setOpaque(true);
- setAudioChannels(1, 0);
- startTimerHz(60);
- addAndMakeVisible(label, 1);
- setSize(700, 500);
- }
- ~SpectrogramComponent() override{
- shutdownAudio();
- }
- void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override {
- lfo.setSampleRate(float(sampleRate));
- osc.setSampleRate(float(sampleRate));
- }
- void releaseResources() override {}
- void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill) override {
- lfo.setFreq(.5f);
- float lfoData;
- auto* buffer = bufferToFill.buffer->getWritePointer(0, bufferToFill.startSample);
- for (auto sample = 0; sample < bufferToFill.numSamples; ++sample) {
- lfo.run();
- lfoData = (lfo.getSin() * .5f + .5f) * 420.f;
- osc.setFreq(lfoData);
- osc.run();
- wave = osc.getSin();
- buffer[sample] = wave;
- }
- }
- void paint (Graphics& g) override{
- g.fillAll (Colours::black);
- g.setOpacity (1.0f);
- g.drawImage (spectrogramImage, getLocalBounds().toFloat());
- String text = "freq: " + String(osc.getFreq()) + ", wave: " + String(wave);
- label.setText(text, NotificationType::dontSendNotification);
- label.setBounds(20, 20, 1000, 20);
- }
- void timerCallback() override {}
- void pushNextSampleIntoFifo(float) noexcept {
- // if the fifo contains enough data, set a flag to say
- // that the next line should now be rendered..
- }
- void drawNextLineOfSpectrogram() {}
- private:
- Image spectrogramImage;
- Label label;
- Osc osc;
- float wave;
- Osc lfo;
- JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SpectrogramComponent)
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement