OpenShot Library | libopenshot-audio
0.2.0
|
37 if (source != newSource)
39 auto* oldSource = source;
41 if (newSource !=
nullptr && bufferSize > 0 && sampleRate > 0)
49 if (oldSource !=
nullptr)
60 int totalNumInputChannels,
61 float** outputChannelData,
62 int totalNumOutputChannels,
66 jassert (sampleRate > 0 && bufferSize > 0);
70 if (source !=
nullptr)
72 int numActiveChans = 0, numInputs = 0, numOutputs = 0;
76 for (
int i = 0; i < totalNumInputChannels; ++i)
78 if (inputChannelData[i] !=
nullptr)
80 inputChans [numInputs++] = inputChannelData[i];
81 if (numInputs >= numElementsInArray (inputChans))
86 for (
int i = 0; i < totalNumOutputChannels; ++i)
88 if (outputChannelData[i] !=
nullptr)
90 outputChans [numOutputs++] = outputChannelData[i];
91 if (numOutputs >= numElementsInArray (outputChans))
96 if (numInputs > numOutputs)
101 tempBuffer.
setSize (numInputs - numOutputs, numSamples,
104 for (
int i = 0; i < numOutputs; ++i)
106 channels[numActiveChans] = outputChans[i];
107 memcpy (channels[numActiveChans], inputChans[i],
sizeof (
float) * (
size_t) numSamples);
111 for (
int i = numOutputs; i < numInputs; ++i)
113 channels[numActiveChans] = tempBuffer.
getWritePointer (i - numOutputs);
114 memcpy (channels[numActiveChans], inputChans[i],
sizeof (
float) * (
size_t) numSamples);
120 for (
int i = 0; i < numInputs; ++i)
122 channels[numActiveChans] = outputChans[i];
123 memcpy (channels[numActiveChans], inputChans[i],
sizeof (
float) * (
size_t) numSamples);
127 for (
int i = numInputs; i < numOutputs; ++i)
129 channels[numActiveChans] = outputChans[i];
130 zeromem (channels[numActiveChans],
sizeof (
float) * (
size_t) numSamples);
147 for (
int i = 0; i < totalNumOutputChannels; ++i)
148 if (outputChannelData[i] !=
nullptr)
149 zeromem (outputChannelData[i],
sizeof (
float) * (
size_t) numSamples);
161 sampleRate = newSampleRate;
162 bufferSize = newBufferSize;
163 zeromem (channels,
sizeof (channels));
165 if (source !=
nullptr)
171 if (source !=
nullptr)
virtual double getCurrentSampleRate()=0
Returns the sample rate that the device is currently using.
void audioDeviceIOCallback(const float **inputChannelData, int totalNumInputChannels, float **outputChannelData, int totalNumOutputChannels, int numSamples) override
Implementation of the AudioIODeviceCallback method.
void setSource(AudioSource *newSource)
Changes the current audio source to play from.
Base class for objects that can produce a continuous stream of audio.
AudioSourcePlayer()
Creates an empty AudioSourcePlayer.
void setSize(int newNumChannels, int newNumSamples, bool keepExistingContent=false, bool clearExtraSpace=false, bool avoidReallocating=false)
Changes the buffer's size or number of channels.
void setGain(float newGain) noexcept
Sets a gain to apply to the audio data.
void audioDeviceAboutToStart(AudioIODevice *device) override
Implementation of the AudioIODeviceCallback method.
Type * getWritePointer(int channelNumber) noexcept
Returns a writeable pointer to one of the buffer's channels.
virtual void getNextAudioBlock(const AudioSourceChannelInfo &bufferToFill)=0
Called repeatedly to fetch subsequent blocks of audio data.
virtual void prepareToPlay(int samplesPerBlockExpected, double sampleRate)=0
Tells the source to prepare for playing.
int startSample
The first sample in the buffer from which the callback is expected to write data.
int numSamples
The number of samples in the buffer which the callback is expected to fill with data.
virtual int getCurrentBufferSizeSamples()=0
Returns the buffer size that the device is currently using.
Base class for an audio device with synchronised input and output channels.
int getNumChannels() const noexcept
Returns the number of channels of audio data that this buffer contains.
void applyGainRamp(int channel, int startSample, int numSamples, Type startGain, Type endGain) noexcept
Applies a range of gains to a region of a channel.
AudioBuffer< float > * buffer
The destination buffer to fill with audio data.
Used by AudioSource::getNextAudioBlock().
void prepareToPlay(double sampleRate, int blockSize)
An alternative method for initialising the source without an AudioIODevice.
Automatically locks and unlocks a mutex object.
virtual void releaseResources()=0
Allows the source to release anything it no longer needs after playback has stopped.
void audioDeviceStopped() override
Implementation of the AudioIODeviceCallback method.
~AudioSourcePlayer() override
Destructor.