31 : input (in), formatName (name)
40 static void convertFixedToFloat (
int*
const* channels,
int numChannels,
int numSamples)
42 for (
int i = 0; i < numChannels; ++i)
43 if (
auto d = channels[i])
48 int64 startSampleInSource,
int numSamplesToRead)
50 auto channelsAsInt =
reinterpret_cast<int* const*
> (destChannels);
52 if (!
read (channelsAsInt, numDestChannels, startSampleInSource, numSamplesToRead,
false))
56 convertFixedToFloat (channelsAsInt, numDestChannels, numSamplesToRead);
63 int64 startSampleInSource,
65 bool fillLeftoverChannelsWithCopies)
67 jassert (numDestChannels > 0);
69 auto originalNumSamplesToRead = (size_t) numSamplesToRead;
70 int startOffsetInDestBuffer = 0;
72 if (startSampleInSource < 0)
74 auto silence = (int) jmin (-startSampleInSource, (int64) numSamplesToRead);
76 for (
int i = numDestChannels; --i >= 0;)
77 if (
auto d = destChannels[i])
78 zeromem (d, (
size_t) silence *
sizeof (
int));
80 startOffsetInDestBuffer += silence;
81 numSamplesToRead -= silence;
82 startSampleInSource = 0;
85 if (numSamplesToRead <= 0)
88 if (!
readSamples (
const_cast<int**
> (destChannels),
89 jmin ((
int)
numChannels, numDestChannels), startOffsetInDestBuffer,
90 startSampleInSource, numSamplesToRead))
95 if (fillLeftoverChannelsWithCopies)
97 auto lastFullChannel = destChannels[0];
101 if (destChannels[i] !=
nullptr)
103 lastFullChannel = destChannels[i];
108 if (lastFullChannel !=
nullptr)
109 for (
int i = (
int)
numChannels; i < numDestChannels; ++i)
110 if (
auto d = destChannels[i])
111 memcpy (d, lastFullChannel,
sizeof (
int) * originalNumSamplesToRead);
115 for (
int i = (
int)
numChannels; i < numDestChannels; ++i)
116 if (
auto d = destChannels[i])
117 zeromem (d,
sizeof (
int) * originalNumSamplesToRead);
125 int startSample,
int numSamples, int64 readerStartSample,
int numTargetChannels,
128 for (
int j = 0; j < numTargetChannels; ++j)
129 chans[j] =
reinterpret_cast<int*
> (buffer->
getWritePointer (j, startSample));
131 chans[numTargetChannels] =
nullptr;
132 reader.
read (chans, numTargetChannels, readerStartSample, numSamples,
true);
135 convertFixedToFloat (chans, numTargetChannels, numSamples);
141 int64 readerStartSample,
142 bool useReaderLeftChan,
143 bool useReaderRightChan)
145 jassert (buffer !=
nullptr);
146 jassert (startSample >= 0 && startSample + numSamples <= buffer->getNumSamples());
152 if (numTargetChannels <= 2)
154 int* dests[2] = {
reinterpret_cast<int*
> (buffer->
getWritePointer (0, startSample)),
155 reinterpret_cast<int*
> (numTargetChannels > 1 ? buffer->
getWritePointer (1, startSample) :
nullptr) };
158 if (useReaderLeftChan == useReaderRightChan)
169 else if (useReaderRightChan)
174 read (chans, 2, readerStartSample, numSamples,
true);
177 if (numTargetChannels > 1 && (chans[0] ==
nullptr || chans[1] ==
nullptr))
178 memcpy (dests[1], dests[0], (
size_t) numSamples *
sizeof (
float));
181 convertFixedToFloat (dests, 2, numSamples);
183 else if (numTargetChannels <= 64)
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;
394 int64 start, int64 length,
int frameSize)
396 dataChunkStart (start), dataLength (length), bytesPerFrame (frameSize)
413 if (map ==
nullptr || samplesToMap != mappedSection)
422 if (map->getData() ==
nullptr)
429 return map !=
nullptr;
432 static int memoryReadDummyVariable;
436 if (map !=
nullptr && mappedSection.contains (sample))
437 memoryReadDummyVariable += *(
char*) sampleToPointer (sample);
Type * getWritePointer(int channelNumber) noexcept
Returns a writeable pointer to one of the buffer's channels.
Type ** getArrayOfWritePointers() noexcept
Returns an array of pointers to the channels in the buffer.
int getNumChannels() const noexcept
Returns the number of channels of audio data that this buffer contains.
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.
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.
static Range< float > JUCE_CALLTYPE findMinAndMax(const float *src, int numValues) noexcept
Finds the minimum and maximum values in the given array.
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.
JUCE_CONSTEXPR ValueType getStart() const noexcept
Returns the start of the range.
static Range findMinAndMax(const ValueType *values, int numValues) noexcept
Scans an array of values for its min and max, and returns these as a Range.
JUCE_CONSTEXPR Range getUnionWith(Range other) const noexcept
Returns the smallest range that contains both this one and the other one.
JUCE_CONSTEXPR ValueType getEnd() const noexcept
Returns the end of the range.