30 : input (in), formatName (name)
39static void convertFixedToFloat (
int*
const* channels,
int numChannels,
int numSamples)
41 constexpr auto scaleFactor = 1.0f /
static_cast<float> (0x7fffffff);
43 for (
int i = 0; i < numChannels; ++i)
44 if (
auto d = channels[i])
45 FloatVectorOperations::convertFixedToFloat (
reinterpret_cast<float*
> (d), d, scaleFactor, numSamples);
49 int64 startSampleInSource,
int numSamplesToRead)
51 auto channelsAsInt =
reinterpret_cast<int* const*
> (destChannels);
53 if (!
read (channelsAsInt, numDestChannels, startSampleInSource, numSamplesToRead,
false))
57 convertFixedToFloat (channelsAsInt, numDestChannels, numSamplesToRead);
64 int64 startSampleInSource,
66 bool fillLeftoverChannelsWithCopies)
70 auto originalNumSamplesToRead = (
size_t) numSamplesToRead;
71 int startOffsetInDestBuffer = 0;
73 if (startSampleInSource < 0)
75 auto silence = (
int)
jmin (-startSampleInSource, (
int64) numSamplesToRead);
77 for (
int i = numDestChannels; --i >= 0;)
78 if (
auto d = destChannels[i])
79 zeromem (d, (
size_t) silence *
sizeof (
int));
81 startOffsetInDestBuffer += silence;
82 numSamplesToRead -= silence;
83 startSampleInSource = 0;
86 if (numSamplesToRead <= 0)
91 startSampleInSource, numSamplesToRead))
96 if (fillLeftoverChannelsWithCopies)
98 auto lastFullChannel = destChannels[0];
102 if (destChannels[i] !=
nullptr)
104 lastFullChannel = destChannels[i];
109 if (lastFullChannel !=
nullptr)
110 for (
int i = (
int)
numChannels; i < numDestChannels; ++i)
111 if (
auto d = destChannels[i])
112 memcpy (d, lastFullChannel,
sizeof (
int) * originalNumSamplesToRead);
116 for (
int i = (
int)
numChannels; i < numDestChannels; ++i)
117 if (
auto d = destChannels[i])
118 zeromem (d,
sizeof (
int) * originalNumSamplesToRead);
126 int startSample,
int numSamples,
int64 readerStartSample,
int numTargetChannels,
129 for (
int j = 0; j < numTargetChannels; ++j)
130 chans[j] =
reinterpret_cast<int*
> (buffer->
getWritePointer (j, startSample));
132 chans[numTargetChannels] =
nullptr;
134 const bool success = reader.
read (chans, numTargetChannels, readerStartSample, numSamples,
true);
137 convertFixedToFloat (chans, numTargetChannels, numSamples);
145 int64 readerStartSample,
146 bool useReaderLeftChan,
147 bool useReaderRightChan)
150 jassert (startSample >= 0 && startSample + numSamples <= buffer->getNumSamples());
157 if (numTargetChannels <= 2)
159 int* dests[2] = {
reinterpret_cast<int*
> (buffer->
getWritePointer (0, startSample)),
160 reinterpret_cast<int*
> (numTargetChannels > 1 ? buffer->
getWritePointer (1, startSample) :
nullptr) };
163 if (useReaderLeftChan == useReaderRightChan)
174 else if (useReaderRightChan)
179 if (! read (chans, 2, readerStartSample, numSamples,
true))
183 if (numTargetChannels > 1
184 && (chans[0] ==
nullptr || chans[1] ==
nullptr)
185 && (dests[0] !=
nullptr && dests[1] !=
nullptr))
187 memcpy (dests[1], dests[0], (
size_t) numSamples *
sizeof (
float));
191 convertFixedToFloat (dests, 2, numSamples);
196 if (numTargetChannels <= 64)
199 return readChannels (*
this, chans, buffer, startSample, numSamples,
203 HeapBlock<int*> chans (numTargetChannels + 1);
205 return readChannels (*
this, chans, buffer, startSample, numSamples,
216 for (
int i = 0; i < channelsToRead; ++i)
222 auto bufferSize = (
int)
jmin (numSamples, (
int64) 4096);
226 auto intBuffer =
reinterpret_cast<int* const*
> (floatBuffer);
227 bool isFirstBlock =
true;
229 while (numSamples > 0)
231 auto numToDo = (
int)
jmin (numSamples, (
int64) bufferSize);
233 if (!
read (intBuffer, channelsToRead, startSampleInFile, numToDo,
false))
236 for (
int i = 0; i < channelsToRead; ++i)
242 r = FloatVectorOperations::findMinAndMax (floatBuffer[i], numToDo);
252 results[i] = isFirstBlock ? r : results[i].
getUnionWith (r);
255 isFirstBlock =
false;
256 numSamples -= numToDo;
257 startSampleInFile += numToDo;
262 float& lowestLeft,
float& highestLeft,
263 float& lowestRight,
float& highestRight)
270 levels[1] = levels[0];
278 highestLeft = levels[0].
getEnd();
280 highestRight = levels[1].
getEnd();
284 int64 numSamplesToSearch,
285 double magnitudeRangeMinimum,
286 double magnitudeRangeMaximum,
287 int minimumConsecutiveSamples)
289 if (numSamplesToSearch == 0)
292 const int bufferSize = 4096;
295 int* tempBuffer[3] = { tempSpace.
get(),
296 tempSpace.
get() + bufferSize,
300 int64 firstMatchPos = -1;
302 jassert (magnitudeRangeMaximum > magnitudeRangeMinimum);
306 auto intMagnitudeRangeMinimum =
roundToInt (doubleMin);
307 auto intMagnitudeRangeMaximum =
roundToInt (doubleMax);
309 while (numSamplesToSearch != 0)
311 auto numThisTime = (
int)
jmin (std::abs (numSamplesToSearch), (
int64) bufferSize);
312 int64 bufferStart = startSample;
314 if (numSamplesToSearch < 0)
315 bufferStart -= numThisTime;
320 read (tempBuffer, 2, bufferStart, numThisTime,
false);
321 auto num = numThisTime;
325 if (numSamplesToSearch < 0)
328 bool matches =
false;
329 auto index = (
int) (startSample - bufferStart);
333 const float sample1 = std::abs (((
float*) tempBuffer[0]) [index]);
335 if (sample1 >= magnitudeRangeMinimum
336 && sample1 <= magnitudeRangeMaximum)
342 const float sample2 = std::abs (((
float*) tempBuffer[1]) [index]);
344 matches = (sample2 >= magnitudeRangeMinimum
345 && sample2 <= magnitudeRangeMaximum);
350 const int sample1 = std::abs (tempBuffer[0] [index]);
352 if (sample1 >= intMagnitudeRangeMinimum
353 && sample1 <= intMagnitudeRangeMaximum)
359 const int sample2 = std::abs (tempBuffer[1][index]);
361 matches = (sample2 >= intMagnitudeRangeMinimum
362 && sample2 <= intMagnitudeRangeMaximum);
368 if (firstMatchPos < 0)
369 firstMatchPos = startSample;
371 if (++consecutive >= minimumConsecutiveSamples)
376 return firstMatchPos;
385 if (numSamplesToSearch > 0)
389 if (numSamplesToSearch > 0)
390 numSamplesToSearch -= numThisTime;
392 numSamplesToSearch += numThisTime;
407 dataChunkStart (start), dataLength (length), bytesPerFrame (frameSize)
424 if (map ==
nullptr || samplesToMap != mappedSection)
433 if (map->getData() ==
nullptr)
440 return map !=
nullptr;
443static int memoryReadDummyVariable;
447 if (map !=
nullptr && mappedSection.contains (sample))
448 memoryReadDummyVariable += *(
char*) sampleToPointer (sample);
A multi-channel buffer containing floating point audio samples.
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.
Type *const * getArrayOfWritePointers() noexcept
Returns an array of pointers to the channels in the buffer.
Represents a set of audio channel types.
static AudioChannelSet JUCE_CALLTYPE canonicalChannelSet(int numChannels)
Create a canonical channel set for a given number of channels.
Represents a local file or directory.
Very simple container class to hold a pointer to some data on the heap.
ElementType * get() const noexcept
Returns a raw pointer to the allocated data.
Maps a file into virtual memory for easy reading and/or writing.
@ readOnly
Indicates that the memory can only be read.
A general-purpose range object, that simply represents any linear range with a start and end point.
constexpr ValueType getStart() const noexcept
Returns the start of the range.
constexpr ValueType getEnd() const noexcept
Returns the end of the range.
constexpr Range getUnionWith(Range other) const noexcept
Returns the smallest range that contains both this one and the other one.
static Range findMinAndMax(const ValueType *values, Integral numValues) noexcept
Scans an array of values for its min and max, and returns these as a Range.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
Constrains a value to keep it within a given range.
int roundToInt(const FloatType value) noexcept
Fast floating-point-to-integer conversion.
long long int64
A platform-independent 64-bit integer type.
void zeromem(void *memory, size_t numBytes) noexcept
Fills a block of memory with zeros.