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