Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
105
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma once
  2. #include "Osc.h"
  3.  
  4. class SpectrogramComponent   : public AudioAppComponent,
  5.                                private Timer
  6. {
  7. public:
  8.     SpectrogramComponent()
  9.         : spectrogramImage(Image::RGB, 512, 512, true) {
  10.         setOpaque(true);
  11.         setAudioChannels(1, 0);
  12.         startTimerHz(60);
  13.         addAndMakeVisible(label, 1);
  14.         setSize(700, 500);
  15.     }
  16.  
  17.     ~SpectrogramComponent() override{
  18.         shutdownAudio();
  19.     }
  20.  
  21.     void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override {
  22.         lfo.setSampleRate(float(sampleRate));
  23.         osc.setSampleRate(float(sampleRate));
  24.     }
  25.     void releaseResources() override          {}
  26.  
  27.     void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill) override {
  28.        
  29.         lfo.setFreq(.5f);
  30.         float lfoData;
  31.  
  32.         auto* buffer = bufferToFill.buffer->getWritePointer(0, bufferToFill.startSample);
  33.         for (auto sample = 0; sample < bufferToFill.numSamples; ++sample) {
  34.             lfo.run();
  35.             lfoData = (lfo.getSin() * .5f + .5f) * 420.f;
  36.             osc.setFreq(lfoData);
  37.             osc.run();
  38.             wave = osc.getSin();
  39.  
  40.             buffer[sample] = wave;
  41.         }
  42.     }
  43.  
  44.     void paint (Graphics& g) override{
  45.         g.fillAll (Colours::black);
  46.  
  47.         g.setOpacity (1.0f);
  48.         g.drawImage (spectrogramImage, getLocalBounds().toFloat());
  49.  
  50.         String text = "freq: " + String(osc.getFreq()) + ", wave: " + String(wave);
  51.         label.setText(text, NotificationType::dontSendNotification);
  52.         label.setBounds(20, 20, 1000, 20);
  53.     }
  54.  
  55.     void timerCallback() override {}
  56.  
  57.     void pushNextSampleIntoFifo(float) noexcept {
  58.         // if the fifo contains enough data, set a flag to say
  59.         // that the next line should now be rendered..
  60.     }
  61.  
  62.     void drawNextLineOfSpectrogram() {}
  63.  
  64. private:
  65.     Image spectrogramImage;
  66.     Label label;
  67.     Osc osc;
  68.     float wave;
  69.     Osc lfo;
  70.  
  71.     JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SpectrogramComponent)
  72. };
Advertisement
RAW Paste Data Copied
Advertisement