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)
68 jassert (numDestChannels > 0);
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)
90 jmin ((
int)
numChannels, numDestChannels), startOffsetInDestBuffer,
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)
149 jassert (buffer !=
nullptr);
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,
212 jassert (channelsToRead > 0 && channelsToRead <= (
int)
numChannels);
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());
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);
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;
405 int64 start, int64 length,
int frameSize)
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);
Type * getWritePointer(int channelNumber) noexcept
int getNumChannels() const noexcept
Type *const * getArrayOfWritePointers() noexcept
static AudioChannelSet JUCE_CALLTYPE canonicalChannelSet(int numChannels)
ElementType * get() const noexcept
constexpr ValueType getStart() const noexcept
constexpr ValueType getEnd() const noexcept
constexpr Range getUnionWith(Range other) const noexcept
static Range findMinAndMax(const ValueType *values, Integral numValues) noexcept