LMMS
Loading...
Searching...
No Matches
juce_AudioFormatReader.h
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
29class AudioFormat;
30
31
32//==============================================================================
44{
45protected:
46 //==============================================================================
56 AudioFormatReader (InputStream* sourceStream,
57 const String& formatName);
58
59public:
61 virtual ~AudioFormatReader();
62
63 //==============================================================================
69
70 //==============================================================================
89 bool read (float* const* destChannels, int numDestChannels,
90 int64 startSampleInSource, int numSamplesToRead);
91
130 bool read (int* const* destChannels,
131 int numDestChannels,
132 int64 startSampleInSource,
133 int numSamplesToRead,
134 bool fillLeftoverChannelsWithCopies);
135
147 bool read (AudioBuffer<float>* buffer,
148 int startSampleInDestBuffer,
149 int numSamples,
150 int64 readerStartSample,
151 bool useReaderLeftChan,
152 bool useReaderRightChan);
153
170 virtual void readMaxLevels (int64 startSample, int64 numSamples,
171 Range<float>* results, int numChannelsToRead);
172
190 virtual void readMaxLevels (int64 startSample, int64 numSamples,
191 float& lowestLeft, float& highestLeft,
192 float& lowestRight, float& highestRight);
193
216 int64 searchForLevel (int64 startSample,
217 int64 numSamplesToSearch,
218 double magnitudeRangeMinimum,
219 double magnitudeRangeMaximum,
220 int minimumConsecutiveSamples);
221
222
223 //==============================================================================
225 double sampleRate = 0;
226
228 unsigned int bitsPerSample = 0;
229
232
234 unsigned int numChannels = 0;
235
238
246
249
250 //==============================================================================
253
254 //==============================================================================
270 virtual bool readSamples (int** destChannels,
271 int numDestChannels,
272 int startOffsetInDestBuffer,
273 int64 startSampleInFile,
274 int numSamples) = 0;
275
276
277protected:
278 //==============================================================================
280 template <class DestSampleType, class SourceSampleType, class SourceEndianness>
282 {
285
286 template <typename TargetType>
287 static void read (TargetType* const* destData, int destOffset, int numDestChannels,
288 const void* sourceData, int numSourceChannels, int numSamples) noexcept
289 {
290 for (int i = 0; i < numDestChannels; ++i)
291 {
292 if (void* targetChan = destData[i])
293 {
294 DestType dest (targetChan);
295 dest += destOffset;
296
297 if (i < numSourceChannels)
298 dest.convertSamples (SourceType (addBytesToPointer (sourceData, i * SourceType::getBytesPerSample()), numSourceChannels), numSamples);
299 else
300 dest.clearSamples (numSamples);
301 }
302 }
303 }
304 };
305
309 static void clearSamplesBeyondAvailableLength (int** destChannels, int numDestChannels,
310 int startOffsetInDestBuffer, int64 startSampleInFile,
311 int& numSamples, int64 fileLengthInSamples)
312 {
313 if (destChannels == nullptr)
314 {
316 return;
317 }
318
319 const int64 samplesAvailable = fileLengthInSamples - startSampleInFile;
320
321 if (samplesAvailable < numSamples)
322 {
323 for (int i = numDestChannels; --i >= 0;)
324 if (destChannels[i] != nullptr)
325 zeromem (destChannels[i] + startOffsetInDestBuffer, (size_t) numSamples * sizeof (int));
326
327 numSamples = (int) samplesAvailable;
328 }
329 }
330
331private:
333
335};
336
337} // namespace juce
#define noexcept
Definition DistrhoDefines.h:72
Definition juce_AudioSampleBuffer.h:34
Definition juce_AudioChannelSet.h:47
Definition juce_AudioDataConverters.h:355
void clearSamples(int numSamples) const noexcept
Definition juce_AudioDataConverters.h:486
void convertSamples(Pointer source, int numSamples) const noexcept
Definition juce_AudioDataConverters.h:442
InputStream * input
Definition juce_AudioFormatReader.h:248
bool usesFloatingPointData
Definition juce_AudioFormatReader.h:237
StringPairArray metadataValues
Definition juce_AudioFormatReader.h:245
const String & getFormatName() const noexcept
Definition juce_AudioFormatReader.h:68
String formatName
Definition juce_AudioFormatReader.h:332
static void clearSamplesBeyondAvailableLength(int **destChannels, int numDestChannels, int startOffsetInDestBuffer, int64 startSampleInFile, int &numSamples, int64 fileLengthInSamples)
Definition juce_AudioFormatReader.h:309
int64 lengthInSamples
Definition juce_AudioFormatReader.h:231
double sampleRate
Definition juce_AudioFormatReader.h:225
virtual AudioChannelSet getChannelLayout()
Definition juce_AudioFormatReader.cpp:398
AudioFormatReader(InputStream *sourceStream, const String &formatName)
Definition juce_AudioFormatReader.cpp:29
unsigned int bitsPerSample
Definition juce_AudioFormatReader.h:228
virtual bool readSamples(int **destChannels, int numDestChannels, int startOffsetInDestBuffer, int64 startSampleInFile, int numSamples)=0
unsigned int numChannels
Definition juce_AudioFormatReader.h:234
Definition juce_InputStream.h:37
Definition juce_Range.h:40
Definition juce_String.h:53
Definition juce_StringPairArray.h:35
register unsigned i
Definition inflate.c:1575
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
#define jassertfalse
#define JUCE_API
Definition juce_StandardHeader.h:152
Definition carla_juce.cpp:31
long long int64
Definition juce_MathsFunctions.h:54
Type * addBytesToPointer(Type *basePointer, IntegerType bytes) noexcept
Definition juce_Memory.h:111
void zeromem(void *memory, size_t numBytes) noexcept
Definition juce_Memory.h:28
Definition juce_AudioFormatReader.h:282
AudioData::Pointer< DestSampleType, AudioData::NativeEndian, AudioData::NonInterleaved, AudioData::NonConst > DestType
Definition juce_AudioFormatReader.h:283
static void read(TargetType *const *destData, int destOffset, int numDestChannels, const void *sourceData, int numSourceChannels, int numSamples) noexcept
Definition juce_AudioFormatReader.h:287
AudioData::Pointer< SourceSampleType, SourceEndianness, AudioData::Interleaved, AudioData::Const > SourceType
Definition juce_AudioFormatReader.h:284
read(f, &c, 1)
typedef int(UZ_EXP MsgFn)()
#define const
Definition zconf.h:137