31 #include "../include/AudioBufferSource.h"
37 AudioBufferSource::AudioBufferSource(juce::AudioSampleBuffer *audio_buffer)
38 : position(0), start(0), repeat(false), buffer(audio_buffer)
51 int buffer_samples = buffer->getNumSamples();
52 int buffer_channels = buffer->getNumChannels();
54 if (info.numSamples > 0) {
56 int number_to_copy = 0;
59 if (start + info.numSamples <= buffer_samples)
62 number_to_copy = info.numSamples;
64 else if (start > buffer_samples)
69 else if (buffer_samples - start > 0)
72 number_to_copy = buffer_samples - start;
81 if (number_to_copy > 0)
84 for (
int channel = 0; channel < buffer_channels; channel++)
85 info.buffer->copyFrom(channel, info.startSample, *buffer, channel, start, number_to_copy);
88 position += number_to_copy;
104 if (newPosition >= 0 && newPosition < buffer->getNumSamples())
105 position = newPosition;
119 return buffer->getNumSamples();
139 buffer = audio_buffer;
~AudioBufferSource()
Destructor.
void prepareToPlay(int, double)
Prepare to play this audio source.
void releaseResources()
Release all resources.
void setBuffer(juce::AudioSampleBuffer *audio_buffer)
Update the internal buffer used by this source.
void getNextAudioBlock(const juce::AudioSourceChannelInfo &info)
Get the next block of audio samples.
bool isLooping() const
Determines if this audio source should repeat when it reaches the end.
void setNextReadPosition(juce::int64 newPosition)
Set the next read position of this source.
juce::int64 getNextReadPosition() const
Get the next read position of this source.
juce::int64 getTotalLength() const
Get the total length (in samples) of this audio source.
void setLooping(bool shouldLoop)
Set if this audio source should repeat when it reaches the end.
This namespace is the default namespace for all code in the openshot library.