41 constexpr auto scaleFactor = 1.0f /
static_cast<float> (0x7fffffff);
43 for (
int i = 0;
i < numChannels; ++
i)
44 if (
auto d = channels[
i])
49 int64 startSampleInSource,
int numSamplesToRead)
51 auto channelsAsInt =
reinterpret_cast<int*
const*
> (destChannels);
53 if (!
read (channelsAsInt, numDestChannels, startSampleInSource, numSamplesToRead,
false))
64 int64 startSampleInSource,
66 bool fillLeftoverChannelsWithCopies)
70 auto originalNumSamplesToRead = (size_t) numSamplesToRead;
71 int startOffsetInDestBuffer = 0;
73 if (startSampleInSource < 0)
77 for (
int i = numDestChannels; --
i >= 0;)
78 if (
auto d = destChannels[
i])
81 startOffsetInDestBuffer +=
silence;
83 startSampleInSource = 0;
86 if (numSamplesToRead <= 0)
89 if (!
readSamples (
const_cast<int**
> (destChannels),
91 startSampleInSource, numSamplesToRead))
96 if (fillLeftoverChannelsWithCopies)
98 auto lastFullChannel = destChannels[0];
102 if (destChannels[
i] !=
nullptr)
104 lastFullChannel = destChannels[
i];
109 if (lastFullChannel !=
nullptr)
111 if (
auto d = destChannels[
i])
112 memcpy (
d, lastFullChannel,
sizeof (
int) * originalNumSamplesToRead);
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);
145 int64 readerStartSample,
146 bool useReaderLeftChan,
147 bool useReaderRightChan)
150 jassert (startSample >= 0 && startSample + numSamples <= buffer->getNumSamples());
155 auto numTargetChannels = buffer->getNumChannels();
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));
196 if (numTargetChannels <= 64)
199 return readChannels (*
this, chans, buffer, startSample, numSamples,
200 readerStartSample, numTargetChannels, ! usesFloatingPointData);
203 HeapBlock<int*> chans (numTargetChannels + 1);
205 return readChannels (*
this, chans, buffer, startSample, numSamples,
206 readerStartSample, numTargetChannels, ! usesFloatingPointData);
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);
248 r =
Range<float> ((
float) intRange.getStart() / (
float) std::numeric_limits<int>::max(),
249 (
float) intRange.getEnd() / (
float) std::numeric_limits<int>::max());
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);
304 auto doubleMin =
jlimit (0.0, (
double) std::numeric_limits<int>::max(), magnitudeRangeMinimum * std::numeric_limits<int>::max());
305 auto doubleMax =
jlimit (doubleMin, (
double) std::numeric_limits<int>::max(), magnitudeRangeMaximum * std::numeric_limits<int>::max());
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;
433 if (
map->getData() ==
nullptr)
440 return map !=
nullptr;
#define nullptr
Definition DistrhoDefines.h:75
Definition juce_AudioSampleBuffer.h:34
Type ** getArrayOfWritePointers() noexcept
Definition juce_AudioSampleBuffer.h:342
Definition juce_AudioChannelSet.h:47
static AudioChannelSet JUCE_CALLTYPE canonicalChannelSet(int numChannels)
Definition juce_AudioChannelSet.cpp:511
Definition juce_File.h:45
static void JUCE_CALLTYPE convertFixedToFloat(float *dest, const int *src, float multiplier, int num) noexcept
Definition juce_FloatVectorOperations.cpp:1425
Definition juce_HeapBlock.h:87
ElementType * get() const noexcept
Definition juce_HeapBlock.h:188
Definition juce_MemoryMappedFile.h:33
@ readOnly
Definition juce_MemoryMappedFile.h:38
Definition juce_Range.h:40
constexpr ValueType getStart() const noexcept
Definition juce_Range.h:80
constexpr ValueType getEnd() const noexcept
Definition juce_Range.h:86
JUCE_NODISCARD constexpr Range getUnionWith(Range other) const noexcept
Definition juce_Range.h:241
static Range findMinAndMax(const ValueType *values, Integral numValues) noexcept
Definition juce_Range.h:274
Definition juce_String.h:53
register unsigned j
Definition inflate.c:1576
unsigned d
Definition inflate.c:940
register unsigned i
Definition inflate.c:1575
unsigned f
Definition inflate.c:1572
static const char * name
Definition pugl.h:1582
virtual ASIOError start()=0
float in
Definition lilv_test.c:1460
float silence[4097]
Definition monosynth.cpp:28
Definition carla_juce.cpp:31
static void convertFixedToFloat(int *const *channels, int numChannels, int numSamples)
Definition juce_AudioFormatReader.cpp:39
constexpr Type jmin(Type a, Type b)
Definition juce_MathsFunctions.h:106
constexpr Type jmax(Type a, Type b)
Definition juce_MathsFunctions.h:94
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
Definition juce_MathsFunctions.h:262
long long int64
Definition juce_MathsFunctions.h:54
static int memoryReadDummyVariable
Definition juce_AudioFormatReader.cpp:443
static bool readChannels(AudioFormatReader &reader, int **chans, AudioBuffer< float > *buffer, int startSample, int numSamples, int64 readerStartSample, int numTargetChannels, bool convertToFloat)
Definition juce_AudioFormatReader.cpp:125
int roundToInt(const FloatType value) noexcept
Definition juce_MathsFunctions.h:465
void zeromem(void *memory, size_t numBytes) noexcept
Definition juce_Memory.h:28
png_uint_32 length
Definition png.c:2247
signed int sample
Definition tap_dynamics_m.c:41
memcpy(hh, h, RAND_HEAD_LEN)
int r
Definition crypt.c:458
typedef int(UZ_EXP MsgFn)()
#define const
Definition zconf.h:137