174 read (chans, 2, readerStartSample, numSamples,
true);
186 readChannels (*
this, chans, buffer, startSample, numSamples,
192 readChannels (*
this, chans, buffer, startSample, numSamples,
201 jassert (channelsToRead > 0 && channelsToRead <= (
int)
numChannels);
205 for (
int i = 0; i < channelsToRead; ++i)
211 auto bufferSize = (int) jmin (numSamples, (int64) 4096);
215 auto intBuffer =
reinterpret_cast<int* const*
> (floatBuffer);
216 bool isFirstBlock =
true;
218 while (numSamples > 0)
220 auto numToDo = (int) jmin (numSamples, (int64) bufferSize);
222 if (!
read (intBuffer, channelsToRead, startSampleInFile, numToDo,
false))
225 for (
int i = 0; i < channelsToRead; ++i)
237 r =
Range<float> (intRange.getStart() / (
float) std::numeric_limits<int>::max(),
238 intRange.getEnd() / (
float) std::numeric_limits<int>::max());
241 results[i] = isFirstBlock ? r : results[i].
getUnionWith (r);
244 isFirstBlock =
false;
245 numSamples -= numToDo;
246 startSampleInFile += numToDo;
251 float& lowestLeft,
float& highestLeft,
252 float& lowestRight,
float& highestRight)
259 levels[1] = levels[0];
267 highestLeft = levels[0].
getEnd();
269 highestRight = levels[1].
getEnd();
273 int64 numSamplesToSearch,
274 double magnitudeRangeMinimum,
275 double magnitudeRangeMaximum,
276 int minimumConsecutiveSamples)
278 if (numSamplesToSearch == 0)
281 const int bufferSize = 4096;
284 int* tempBuffer[3] = { tempSpace.
get(),
285 tempSpace.
get() + bufferSize,
289 int64 firstMatchPos = -1;
291 jassert (magnitudeRangeMaximum > magnitudeRangeMinimum);
293 auto doubleMin = jlimit (0.0, (
double) std::numeric_limits<int>::max(), magnitudeRangeMinimum * std::numeric_limits<int>::max());
294 auto doubleMax = jlimit (doubleMin, (
double) std::numeric_limits<int>::max(), magnitudeRangeMaximum * std::numeric_limits<int>::max());
295 auto intMagnitudeRangeMinimum = roundToInt (doubleMin);
296 auto intMagnitudeRangeMaximum = roundToInt (doubleMax);
298 while (numSamplesToSearch != 0)
300 auto numThisTime = (int) jmin (std::abs (numSamplesToSearch), (int64) bufferSize);
301 int64 bufferStart = startSample;
303 if (numSamplesToSearch < 0)
304 bufferStart -= numThisTime;
309 read (tempBuffer, 2, bufferStart, numThisTime,
false);
310 auto num = numThisTime;
314 if (numSamplesToSearch < 0)
317 bool matches =
false;
318 auto index = (int) (startSample - bufferStart);
322 const float sample1 = std::abs (((
float*) tempBuffer[0]) [index]);
324 if (sample1 >= magnitudeRangeMinimum
325 && sample1 <= magnitudeRangeMaximum)
331 const float sample2 = std::abs (((
float*) tempBuffer[1]) [index]);
333 matches = (sample2 >= magnitudeRangeMinimum
334 && sample2 <= magnitudeRangeMaximum);
339 const int sample1 = std::abs (tempBuffer[0] [index]);
341 if (sample1 >= intMagnitudeRangeMinimum
342 && sample1 <= intMagnitudeRangeMaximum)
348 const int sample2 = std::abs (tempBuffer[1][index]);
350 matches = (sample2 >= intMagnitudeRangeMinimum
351 && sample2 <= intMagnitudeRangeMaximum);
357 if (firstMatchPos < 0)
358 firstMatchPos = startSample;
360 if (++consecutive >= minimumConsecutiveSamples)
365 return firstMatchPos;
374 if (numSamplesToSearch > 0)
378 if (numSamplesToSearch > 0)
379 numSamplesToSearch -= numThisTime;
381 numSamplesToSearch += numThisTime;