29template <
typename Value>
36 Value*
const* data =
nullptr;
74 const auto numBytes = (
size_t) numSamples *
sizeof (
float);
78 if (ins.numChannels == 0)
136AudioProcessorPlayer::NumChannels AudioProcessorPlayer::findMostSuitableLayout (
const AudioProcessor&
proc)
const
138 if (
proc.isMidiEffect())
143 if (deviceChannels.ins == 0 || deviceChannels.ins == 1)
145 layouts.emplace_back (defaultProcessorChannels.ins, deviceChannels.outs);
146 layouts.emplace_back (deviceChannels.outs, deviceChannels.outs);
151 return proc.checkBusesLayoutSupported (chans.toLayout());
157void AudioProcessorPlayer::resizeChannels()
161 actualProcessorChannels.ins,
162 actualProcessorChannels.outs);
175 currentWorkgroup.
reset();
179 defaultProcessorChannels = NumChannels {
processorToPlay->getBusesLayout() };
186 actualProcessorChannels.outs,
193 : AudioProcessor::singlePrecision);
200 oldOne = isPrepared ? processor :
nullptr;
206 oldOne->releaseResources();
211 if (doublePrecision != isDoublePrecision)
215 currentWorkgroup.
reset();
217 if (processor !=
nullptr)
224 : AudioProcessor::singlePrecision);
229 isDoublePrecision = doublePrecision;
244 const int numInputChannels,
246 const int numOutputChannels,
247 const int numSamples,
252 jassert (currentDevice !=
nullptr);
255 jassert (sampleRate > 0 && blockSize > 0);
257 incomingMidi.
clear();
263 actualProcessorChannels.ins,
264 actualProcessorChannels.outs,
271 if (processor !=
nullptr)
290 hostTimeNs (hostTimeIn),
291 sampleCount (sampleCountIn),
292 seconds ((
double) sampleCountIn / sampleRateIn)
295 processor.setPlayHead (
this);
301 processor.setPlayHead (
nullptr);
308 info.setHostTimeNs (hostTimeNs);
309 info.setTimeInSamples ((
int64_t) sampleCount);
310 info.setTimeInSeconds (seconds);
318 bool useThisPlayhead = processor.
getPlayHead() ==
nullptr;
326 sampleCount += (
uint64_t) numSamples;
333 processor->
processBlock (conversionBuffer, incomingMidi);
341 if (midiOutput !=
nullptr)
359 for (
int i = 0; i < numOutputChannels; ++i)
365 currentDevice = device;
379 messageCollector.
reset (sampleRate);
381 currentWorkgroup.
reset();
383 if (processor !=
nullptr)
398 if (processor !=
nullptr && isPrepared)
406 currentDevice =
nullptr;
407 currentWorkgroup.
reset();
424 void runTest()
override
437 beginTest (
"Buffers are prepared correctly for a variety of channel layouts");
443 const int numSamples = 256;
446 AudioBuffer<float> tempBuffer (
jmax (layout.numIns, layout.numOuts), numSamples);
449 initialiseIoBuffers ({
systemIns.getArrayOfReadPointers(),
systemIns.getNumChannels() },
457 int channelIndex = 0;
459 for (
const auto& channel : channels)
461 const auto value = [&]
464 if (layout.numIns <= channelIndex)
474 return (
float) (channelIndex + 1);
477 expect (FloatVectorOperations::findMinAndMax (channel, numSamples) == Range<float> (value, value));
486 static AudioBuffer<float>
getTestBuffer (
int numChannels,
int numSamples)
488 AudioBuffer<float> result (numChannels, numSamples);
490 for (
int i = 0; i < result.getNumChannels(); ++i)
491 FloatVectorOperations::fill (result.getWritePointer (i), (
float) i + 1, result.getNumSamples());
A multi-channel buffer containing floating point audio samples.
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 makeCopyOf(const AudioBuffer< OtherType > &other, bool avoidReallocating=false)
Resizes this buffer to match the given one, and copies all of its content across.
Type * getWritePointer(int channelNumber) noexcept
Returns a writeable pointer to one of the buffer's channels.
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.
Base class for an audio device with synchronised input and output channels.
virtual double getCurrentSampleRate()=0
Returns the sample rate that the device is currently using.
virtual AudioWorkgroup getWorkgroup() const
Returns the workgroup for this device.
virtual BigInteger getActiveInputChannels() const =0
Returns a mask showing which of the available input channels are currently enabled.
virtual BigInteger getActiveOutputChannels() const =0
Returns a mask showing which of the available output channels are currently enabled.
virtual int getCurrentBufferSizeSamples()=0
Returns the buffer size that the device is currently using.
A subclass of AudioPlayHead can supply information about the position and status of a moving play hea...
void handleIncomingMidiMessage(MidiInput *, const MidiMessage &) override
Receives an incoming message.
void audioDeviceAboutToStart(AudioIODevice *) override
Called to indicate that the device is about to start calling back.
void setProcessor(AudioProcessor *processorToPlay)
Sets the processor that should be played.
~AudioProcessorPlayer() override
Destructor.
void audioDeviceStopped() override
Called to indicate that the device has stopped.
void setMidiOutput(MidiOutput *midiOutputToUse)
Sets the MIDI output that should be used, if required.
void setDoublePrecisionProcessing(bool doublePrecision)
Switch between double and single floating point precisions processing.
void audioDeviceIOCallbackWithContext(const float *const *, int, float *const *, int, int, const AudioIODeviceCallbackContext &) override
Processes a block of incoming and outgoing audio data.
Base class for audio processing classes or plugins.
void setProcessingPrecision(ProcessingPrecision newPrecision) noexcept
Changes the processing precision of the receiver.
bool isUsingDoublePrecision() const noexcept
Returns true if the current precision is set to doublePrecision.
virtual bool supportsDoublePrecisionProcessing() const
Returns true if the Audio processor supports double precision floating point processing.
virtual void prepareToPlay(double sampleRate, int maximumExpectedSamplesPerBlock)=0
Called before playback starts, to let the processor prepare itself.
virtual void processBlock(AudioBuffer< float > &buffer, MidiBuffer &midiMessages)=0
Renders the next block.
const CriticalSection & getCallbackLock() const noexcept
This returns a critical section that will automatically be locked while the host is calling the proce...
bool isSuspended() const noexcept
Returns true if processing is currently suspended.
virtual void audioWorkgroupContextChanged(const AudioWorkgroup &workgroup)
This is called by the host when the thread workgroup context has changed.
AudioPlayHead * getPlayHead() const noexcept
Returns the current AudioPlayHead object that should be used to find out the state and position of th...
virtual bool isMidiEffect() const
Returns true if this is a MIDI effect plug-in and does no audio processing.
virtual void releaseResources()=0
Called after playback has stopped, to let the object free up any resources it no longer needs.
void reset()
Disengages this instance so that it no longer represents a workgroup.
int countNumberOfSetBits() const noexcept
Returns the total number of set bits in the value.
Automatically locks and unlocks a mutex object.
void clear() noexcept
Removes all events from the buffer.
void removeNextBlockOfMessages(MidiBuffer &destBuffer, int numSamples)
Removes all the pending messages from the queue as a buffer.
void reset(double sampleRate)
Clears any messages from the queue.
void addMessageToQueue(const MidiMessage &message)
Takes an incoming real-time message and adds it to the queue.
Encapsulates a MIDI message.
Represents a midi output device.
void sendBlockOfMessagesNow(const MidiBuffer &buffer)
Sends out a sequence of MIDI messages immediately.
bool isBackgroundThreadRunning() const noexcept
Returns true if the background thread used to send blocks of data is running.
void sendBlockOfMessages(const MidiBuffer &buffer, double millisecondCounterToStartAt, double samplesPerSecondForBuffer)
This lets you supply a block of messages that will be sent out at some point in the future.
static double getMillisecondCounterHiRes() noexcept
Returns the number of millisecs since a fixed event (usually system startup).
This is a base class for classes that perform a unit test.
Represents a shared variant value.
constexpr Type jmax(Type a, Type b)
Returns the larger 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...
const uint64_t * hostTimeNs
If the host provides this information, this field will be set to point to an integer holding the curr...
void zeromem(void *memory, size_t numBytes) noexcept
Fills a block of memory with zeros.
Additional information that may be passed to the AudioIODeviceCallback.