38 usesFloatingPointData (
false),
53 usesFloatingPointData (
false),
65static void convertFloatsToInts (
int* dest,
const float*
src,
int numSamples)
noexcept
67 while (--numSamples >= 0)
72 *dest = std::numeric_limits<int>::min();
74 *dest = std::numeric_limits<int>::max();
76 *dest = roundToInt (std::numeric_limits<int>::max() *
samp);
86 const int bufferSize = 16384;
89 int*
buffers[128] = {
nullptr };
91 for (
int i = tempBuffer.getNumChannels(); --i >= 0;)
92 buffers[i] =
reinterpret_cast<int*
> (tempBuffer.getWritePointer (i, 0));
115 convertFloatsToInts ((
int*)
b, (
float*)
b,
numToDo);
138 info.clearActiveBufferRegion();
157 return write ((
const int**) channels, numSamples);
171 while (numSamples > 0)
176 convertFloatsToInts (
chans[i], channels[i] + startSample,
numToDo);
191 jassert (startSample >= 0 && startSample + numSamples <= source.getNumSamples() &&
numSourceChannels > 0);
193 if (startSample == 0)
196 const float*
chans[256];
200 chans[i] = source.getReadPointer (i, startSample);
218 buffer (channels, numSamples),
219 timeSliceThread (
tst),
230 while (writePendingData() == 0)
234 bool write (
const float*
const* data,
int numSamples)
236 if (numSamples <= 0 || ! isRunning)
260 return writePendingData();
263 int writePendingData()
273 writer->writeFromAudioSampleBuffer (buffer,
start1,
size1);
277 if (receiver !=
nullptr)
278 receiver->addBlock (samplesWritten, buffer,
start1,
size1);
280 samplesWritten +=
size1;
284 writer->writeFromAudioSampleBuffer (buffer,
start2,
size2);
286 if (receiver !=
nullptr)
287 receiver->addBlock (samplesWritten, buffer,
start2,
size2);
289 samplesWritten +=
size2;
294 if (samplesPerFlush > 0)
298 if (flushSampleCounter <= 0)
300 flushSampleCounter = samplesPerFlush;
308 void setDataReceiver (IncomingDataReceiver* newReceiver)
310 if (newReceiver !=
nullptr)
311 newReceiver->reset (buffer.
getNumChannels(), writer->getSampleRate(), 0);
313 const ScopedLock sl (thumbnailLock);
314 receiver = newReceiver;
318 void setFlushInterval (
int numSamples)
noexcept
320 samplesPerFlush = numSamples;
325 AudioBuffer<float> buffer;
326 TimeSliceThread& timeSliceThread;
327 std::unique_ptr<AudioFormatWriter> writer;
328 CriticalSection thumbnailLock;
329 IncomingDataReceiver* receiver = {};
330 int64 samplesWritten = 0;
331 int samplesPerFlush = 0, flushSampleCounter = 0;
332 std::atomic<bool> isRunning {
true };
334 JUCE_DECLARE_NON_COPYABLE (Buffer)
348 return buffer->write (data, numSamples);
353 buffer->setDataReceiver (receiver);
void prepareToWrite(int numToWrite, int &startIndex1, int &blockSize1, int &startIndex2, int &blockSize2) const noexcept
Returns the location within the buffer at which an incoming block of data should be written.
int getTotalSize() const noexcept
Returns the total size of the buffer being managed.
void prepareToRead(int numWanted, int &startIndex1, int &blockSize1, int &startIndex2, int &blockSize2) const noexcept
Returns the location within the buffer from which the next block of data should be read.
void finishedRead(int numRead) noexcept
Called after reading from the FIFO, to indicate that this many items have now been consumed.
void finishedWrite(int numWritten) noexcept
Called after writing from the FIFO, to indicate that this many items have been added.
Holds a resizable array of primitive or copy-by-value objects.
int getNumChannels() const noexcept
Returns the number of channels of audio data that this buffer contains.
void copyFrom(int destChannel, int destStartSample, const AudioBuffer &source, int sourceChannel, int sourceStartSample, int numSamples) noexcept
Copies samples from another buffer to this one.
Represents a set of audio channel types.
Base class for objects that can produce a continuous stream of audio.
virtual void getNextAudioBlock(const AudioSourceChannelInfo &bufferToFill)=0
Called repeatedly to fetch subsequent blocks of audio data.
static void JUCE_CALLTYPE convertFixedToFloat(float *dest, const int *src, float multiplier, int numValues) noexcept
Converts a stream of integers to floats, multiplying each one by the given multiplier.
The base class for streams that write data to some kind of destination.
void notify() const
Wakes up the thread.
bool isThreadRunning() const
Returns true if the thread is currently active.
Used by the TimeSliceThread class.
A thread that keeps a list of clients, and calls each one in turn, giving them all a chance to run so...
void removeTimeSliceClient(TimeSliceClient *clientToRemove)
Removes a client from the list.
void addTimeSliceClient(TimeSliceClient *clientToAdd, int millisecondsBeforeStarting=0)
Adds a client to the list.
Used by AudioSource::getNextAudioBlock().