28 #include "../include/AudioBufferSource.h" 34 AudioBufferSource::AudioBufferSource(AudioSampleBuffer *audio_buffer)
35 : position(0), start(0), repeat(false), buffer(audio_buffer)
48 int buffer_samples = buffer->getNumSamples();
49 int buffer_channels = buffer->getNumChannels();
51 if (info.numSamples > 0) {
53 int number_to_copy = 0;
56 if (start + info.numSamples <= buffer_samples)
59 number_to_copy = info.numSamples;
61 else if (start > buffer_samples)
66 else if (buffer_samples - start > 0)
69 number_to_copy = buffer_samples - start;
78 if (number_to_copy > 0)
81 for (
int channel = 0; channel < buffer_channels; channel++)
82 info.buffer->copyFrom(channel, info.startSample, *buffer, channel, start, number_to_copy);
85 position += number_to_copy;
101 if (newPosition >= 0 && newPosition < buffer->getNumSamples())
102 position = newPosition;
116 return buffer->getNumSamples();
136 buffer = audio_buffer;
void setLooping(bool shouldLoop)
Set if this audio source should repeat when it reaches the end.
void prepareToPlay(int, double)
Prepare to play this audio source.
~AudioBufferSource()
Destructor.
void setNextReadPosition(int64 newPosition)
Set the next read position of this source.
void releaseResources()
Release all resources.
int64 getNextReadPosition() const
Get the next read position of this source.
bool isLooping() const
Determines if this audio source should repeat when it reaches the end.
void getNextAudioBlock(const AudioSourceChannelInfo &info)
Get the next block of audio samples.
int64 getTotalLength() const
Get the total length (in samples) of this audio source.
void setBuffer(AudioSampleBuffer *audio_buffer)
Update the internal buffer used by this source.
This namespace is the default namespace for all code in the openshot library.