OpenShot Audio Library | OpenShotAudio 0.4.0

Loading...
Searching...
No Matches
juce_AudioFormatReader.h
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
26 namespace juce
27{
28
29 class AudioFormat;
30
31
32//==============================================================================
43 class JUCE_API AudioFormatReader
44{
45 protected:
46 //==============================================================================
56 AudioFormatReader (InputStream* sourceStream,
57 const String& formatName);
58
59 public:
61 virtual ~AudioFormatReader();
62
63 //==============================================================================
68 const String& getFormatName() const noexcept { return formatName; }
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
231 int64 lengthInSamples = 0;
232
234 unsigned int numChannels = 0;
235
237 bool usesFloatingPointData = false;
238
245 StringPairArray metadataValues;
246
248 InputStream* input;
249
250 //==============================================================================
252 virtual AudioChannelSet getChannelLayout();
253
254 //==============================================================================
270 virtual bool readSamples (int* const* destChannels,
271 int numDestChannels,
272 int startOffsetInDestBuffer,
273 int64 startSampleInFile,
274 int numSamples) = 0;
275
276
277 protected:
278 //==============================================================================
280 template <class DestSampleType, class SourceSampleType, class SourceEndianness>
281 struct ReadHelper
282 {
283 using DestType = AudioData::Pointer<DestSampleType, AudioData::NativeEndian, AudioData::NonInterleaved, AudioData::NonConst>;
284 using SourceType = AudioData::Pointer<SourceSampleType, SourceEndianness, AudioData::Interleaved, AudioData::Const>;
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* const* destChannels, int numDestChannels,
310 int startOffsetInDestBuffer, int64 startSampleInFile,
311 int& numSamples, int64 fileLengthInSamples)
312 {
313 if (destChannels == nullptr)
314 {
315 jassertfalse;
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
331 private:
332 String formatName;
333
334 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioFormatReader)
335};
336
337} // namespace juce
juce::AudioBuffer
Definition juce_AudioSampleBuffer.h:34
juce::AudioChannelSet
Definition juce_AudioChannelSet.h:47
juce::AudioData::Pointer
Definition juce_AudioDataConverters.h:355
juce::AudioData::Pointer::clearSamples
void clearSamples(int numSamples) const noexcept
Definition juce_AudioDataConverters.h:489
juce::AudioData::Pointer::convertSamples
void convertSamples(Pointer source, int numSamples) const noexcept
Definition juce_AudioDataConverters.h:445
juce::AudioFormatReader
Definition juce_AudioFormatReader.h:44
juce::AudioFormatReader::input
InputStream * input
Definition juce_AudioFormatReader.h:248
juce::AudioFormatReader::metadataValues
StringPairArray metadataValues
Definition juce_AudioFormatReader.h:245
juce::AudioFormatReader::getFormatName
const String & getFormatName() const noexcept
Definition juce_AudioFormatReader.h:68
juce::AudioFormatReader::clearSamplesBeyondAvailableLength
static void clearSamplesBeyondAvailableLength(int *const *destChannels, int numDestChannels, int startOffsetInDestBuffer, int64 startSampleInFile, int &numSamples, int64 fileLengthInSamples)
Definition juce_AudioFormatReader.h:309
juce::AudioFormatReader::readSamples
virtual bool readSamples(int *const *destChannels, int numDestChannels, int startOffsetInDestBuffer, int64 startSampleInFile, int numSamples)=0
juce::InputStream
Definition juce_InputStream.h:37
juce::Range
Definition juce_Range.h:40
juce::StringPairArray
Definition juce_StringPairArray.h:35
juce::String
Definition juce_String.h:53
juce::AudioFormatReader::ReadHelper
Definition juce_AudioFormatReader.h:282