Professional Documents
Culture Documents
==============================================================================
The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
To use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES,
WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR
PURPOSE, ARE DISCLAIMED.
==============================================================================
*/
/*******************************************************************************
The block below describes the properties of this PIP. A PIP is a short snippet
of code that can be read by the Projucer and used to generate a JUCE project.
BEGIN_JUCE_PIP_METADATA
name: SpectrumAnalyserTutorial
version: 2.0.0
vendor: JUCE
website: http://juce.com
description: Displays an FFT spectrum analyser.
type: Component
mainClass: AnalyserComponent
useLocalCopy: 1
END_JUCE_PIP_METADATA
*******************************************************************************/
#pragma once
//==============================================================================
class AnalyserComponent : public juce::AudioAppComponent,
private juce::Timer
{
public:
AnalyserComponent()
: forwardFFT (fftOrder),
window (fftSize, juce::dsp::WindowingFunction<float>::hann)
{
setOpaque (true);
setAudioChannels (2, 0); // we want a couple of input channels but no
outputs
startTimerHz (30);
setSize (700, 500);
}
~AnalyserComponent() override
{
shutdownAudio();
}
//==============================================================================
void prepareToPlay (int, double) override {}
void releaseResources() override {}
//==============================================================================
void paint (juce::Graphics& g) override
{
g.fillAll (juce::Colours::black);
g.setOpacity (1.0f);
g.setColour (juce::Colours::white);
drawFrame (g);
}
fifoIndex = 0;
}
void drawNextFrameOfSpectrum()
{
// first apply a windowing function to our data
window.multiplyWithWindowingTable (fftData, fftSize); // [1]
enum
{
fftOrder = 11, // [1]
fftSize = 1 << fftOrder, // [2]
scopeSize = 512 // [3]
};
private:
juce::dsp::FFT forwardFFT; // [4]
juce::dsp::WindowingFunction<float> window; // [5]
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AnalyserComponent)
};