33 setBufferSize (bufferSize);
44 void pushSamples (
const float*
inputSamples,
int num)
noexcept
46 for (
int i = 0; i < num; ++i)
50 void pushSample (
float newSample)
noexcept
54 if (++nextSample == levels.size())
57 levels.getReference (nextSample) = value;
58 subSample = owner.getSamplesPerBlock();
67 void setBufferSize (
int newSize)
69 levels.removeRange (
newSize, levels.size());
70 levels.insertMultiple (-1, {},
newSize - levels.size());
87 inputSamplesPerBlock (256),
88 backgroundColour (Colours::black),
89 waveformColour (Colours::white)
104 for (
int i = 0; i < numChannels; ++i)
105 channels.add (
new ChannelInfo (*
this, numSamples));
112 for (
auto* c : channels)
118 for (
auto* c : channels)
124 numChannels =
jmin (numChannels, channels.size());
126 for (
int i = 0; i < numChannels; ++i)
127 channels.getUnchecked (i)->pushSamples (d[i], num);
141 for (
int i = 0; i < numChannels; ++i)
148 numChannels =
jmin (numChannels, channels.size());
150 for (
int i = 0; i < numChannels; ++i)
151 channels.getUnchecked (i)->pushSample (d[i]);
164void AudioVisualiserComponent::timerCallback()
171 backgroundColour =
bk;
185 for (
auto* c : channels)
187 c->levels.begin(), c->levels.size(), c->nextSample);
197 auto level = -(levels[(nextSample + i) %
numLevels].getEnd());
202 path.
lineTo ((
float) i, level);
206 path.
lineTo ((
float) i, -(levels[(nextSample + i) %
numLevels].getStart()));
Holds a resizable array of primitive or copy-by-value objects.
A multi-channel buffer containing floating point audio samples.
int getNumChannels() const noexcept
Returns the number of channels of audio data that this buffer contains.
int getNumSamples() const noexcept
Returns the number of samples allocated in each of the buffer's channels.
const Type * getReadPointer(int channelNumber) const noexcept
Returns a pointer to an array of read-only samples in one of the buffer's channels.
const Type *const * getArrayOfReadPointers() const noexcept
Returns an array of pointers to the channels in the buffer.
A simple component that can be used to show a scrolling waveform of audio data.
virtual void paintChannel(Graphics &, Rectangle< float > bounds, const Range< float > *levels, int numLevels, int nextSample)
Draws a channel of audio data in the given bounds.
void setNumChannels(int numChannels)
Changes the number of channels that the visualiser stores.
void clear()
Clears the contents of the buffers.
AudioVisualiserComponent(int initialNumChannels)
Creates a visualiser with the given number of channels.
~AudioVisualiserComponent() override
Destructor.
void setBufferSize(int bufferSize)
Changes the number of samples that the visualiser keeps in its history.
void getChannelAsPath(Path &result, const Range< float > *levels, int numLevels, int nextSample)
Creates a path which contains the waveform shape of a given set of range data.
void paint(Graphics &) override
Components can override this method to draw their content.
void pushBuffer(const AudioBuffer< float > &bufferToPush)
Pushes a buffer of channels data.
void setRepaintRate(int frequencyInHz)
Sets the frequency at which the component repaints itself.
void setColours(Colour backgroundColour, Colour waveformColour) noexcept
Sets the colours used to paint the.
void pushSample(const float *samplesForEachChannel, int numChannels)
Pushes a single sample (per channel).
Represents a colour, also including a transparency value.
void setOpaque(bool shouldBeOpaque)
Indicates whether any parts of the component might be transparent.
void repaint()
Marks the whole component as needing to be redrawn.
Rectangle< int > getLocalBounds() const noexcept
Returns the component's bounds, relative to its own origin.
A graphics context, used for drawing a component or image.
void fillPath(const Path &path) const
Fills a path using the currently selected colour or brush.
void setColour(Colour newColour)
Changes the current drawing colour.
void fillAll() const
Fills the context's entire clip region with the current colour or brush.
A path is a sequence of lines and curves that may either form a closed shape or be open-ended.
void startNewSubPath(float startX, float startY)
Begins a new subpath with a given starting position.
void preallocateSpace(int numExtraCoordsToMakeSpaceFor)
Preallocates enough space for adding the given number of coordinates to the path.
void closeSubPath()
Closes a the current sub-path with a line back to its start-point.
void lineTo(float endX, float endY)
Adds a line from the shape's last position to a new end-point.
A general-purpose range object, that simply represents any linear range with a start and end point.
constexpr Range getUnionWith(Range other) const noexcept
Returns the smallest range that contains both this one and the other one.
Manages a rectangle and allows geometric operations to be performed on it.
ValueType getRight() const noexcept
Returns the x coordinate of the rectangle's right-hand-side.
Rectangle< float > toFloat() const noexcept
Casts this rectangle to a Rectangle<float>.
ValueType getX() const noexcept
Returns the x coordinate of the rectangle's left-hand-side.
ValueType getBottom() const noexcept
Returns the y coordinate of the rectangle's bottom edge.
ValueType getY() const noexcept
Returns the y coordinate of the rectangle's top edge.
ValueType getHeight() const noexcept
Returns the height of the rectangle.
void startTimerHz(int timerFrequencyHz) noexcept
Starts the timer with an interval specified in Hertz.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Used by AudioSource::getNextAudioBlock().
int numSamples
The number of samples in the buffer which the callback is expected to fill with data.
AudioBuffer< float > * buffer
The destination buffer to fill with audio data.
int startSample
The first sample in the buffer from which the callback is expected to write data.