OpenShot Audio Library | OpenShotAudio 0.3.2

Loading...
Searching...
No Matches
juce_AudioFormatReader.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2017 - ROLI Ltd.
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 5 End-User License
11 Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
12 27th April 2017).
13
14 End User License Agreement: www.juce.com/juce-5-licence
15 Privacy Policy: www.juce.com/juce-5-privacy-policy
16
17 Or: You may also use this code under the terms of the GPL v3 (see
18 www.gnu.org/licenses).
19
20 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22 DISCLAIMED.
23
24 ==============================================================================
25*/
26
27 namespace juce
28{
29
30 class AudioFormat;
31
32
33//==============================================================================
44 class JUCE_API AudioFormatReader
45{
46 protected:
47 //==============================================================================
57 AudioFormatReader (InputStream* sourceStream,
58 const String& formatName);
59
60 public:
62 virtual ~AudioFormatReader();
63
64 //==============================================================================
69 const String& getFormatName() const noexcept { return formatName; }
70
71 //==============================================================================
90 bool read (float* const* destChannels, int numDestChannels,
91 int64 startSampleInSource, int numSamplesToRead);
92
131 bool read (int* const* destChannels,
132 int numDestChannels,
133 int64 startSampleInSource,
134 int numSamplesToRead,
135 bool fillLeftoverChannelsWithCopies);
136
144 void read (AudioBuffer<float>* buffer,
145 int startSampleInDestBuffer,
146 int numSamples,
147 int64 readerStartSample,
148 bool useReaderLeftChan,
149 bool useReaderRightChan);
150
167 virtual void readMaxLevels (int64 startSample, int64 numSamples,
168 Range<float>* results, int numChannelsToRead);
169
187 virtual void readMaxLevels (int64 startSample, int64 numSamples,
188 float& lowestLeft, float& highestLeft,
189 float& lowestRight, float& highestRight);
190
213 int64 searchForLevel (int64 startSample,
214 int64 numSamplesToSearch,
215 double magnitudeRangeMinimum,
216 double magnitudeRangeMaximum,
217 int minimumConsecutiveSamples);
218
219
220 //==============================================================================
222 double sampleRate = 0;
223
225 unsigned int bitsPerSample = 0;
226
228 int64 lengthInSamples = 0;
229
231 unsigned int numChannels = 0;
232
234 bool usesFloatingPointData = false;
235
242 StringPairArray metadataValues;
243
245 InputStream* input;
246
247 //==============================================================================
249 virtual AudioChannelSet getChannelLayout();
250
251 //==============================================================================
267 virtual bool readSamples (int** destChannels,
268 int numDestChannels,
269 int startOffsetInDestBuffer,
270 int64 startSampleInFile,
271 int numSamples) = 0;
272
273
274 protected:
275 //==============================================================================
277 template <class DestSampleType, class SourceSampleType, class SourceEndianness>
278 struct ReadHelper
279 {
280 using DestType = AudioData::Pointer<DestSampleType, AudioData::NativeEndian, AudioData::NonInterleaved, AudioData::NonConst>;
281 using SourceType = AudioData::Pointer<SourceSampleType, SourceEndianness, AudioData::Interleaved, AudioData::Const>;
282
283 template <typename TargetType>
284 static void read (TargetType* const* destData, int destOffset, int numDestChannels,
285 const void* sourceData, int numSourceChannels, int numSamples) noexcept
286 {
287 for (int i = 0; i < numDestChannels; ++i)
288 {
289 if (void* targetChan = destData[i])
290 {
291 DestType dest (targetChan);
292 dest += destOffset;
293
294 if (i < numSourceChannels)
295 dest.convertSamples (SourceType (addBytesToPointer (sourceData, i * SourceType::getBytesPerSample()), numSourceChannels), numSamples);
296 else
297 dest.clearSamples (numSamples);
298 }
299 }
300 }
301 };
302
306 static void clearSamplesBeyondAvailableLength (int** destChannels, int numDestChannels,
307 int startOffsetInDestBuffer, int64 startSampleInFile,
308 int& numSamples, int64 fileLengthInSamples)
309 {
310 jassert (destChannels != nullptr);
311 const int64 samplesAvailable = fileLengthInSamples - startSampleInFile;
312
313 if (samplesAvailable < numSamples)
314 {
315 for (int i = numDestChannels; --i >= 0;)
316 if (destChannels[i] != nullptr)
317 zeromem (destChannels[i] + startOffsetInDestBuffer, (size_t) numSamples * sizeof (int));
318
319 numSamples = (int) samplesAvailable;
320 }
321 }
322
323 private:
324 String formatName;
325
326 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioFormatReader)
327};
328
329} // 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:486
juce::AudioData::Pointer::convertSamples
void convertSamples(Pointer source, int numSamples) const noexcept
Definition: juce_AudioDataConverters.h:442
juce::AudioFormatReader
Definition: juce_AudioFormatReader.h:45
juce::AudioFormatReader::input
InputStream * input
Definition: juce_AudioFormatReader.h:245
juce::AudioFormatReader::metadataValues
StringPairArray metadataValues
Definition: juce_AudioFormatReader.h:242
juce::AudioFormatReader::getFormatName
const String & getFormatName() const noexcept
Definition: juce_AudioFormatReader.h:69
juce::AudioFormatReader::clearSamplesBeyondAvailableLength
static void clearSamplesBeyondAvailableLength(int **destChannels, int numDestChannels, int startOffsetInDestBuffer, int64 startSampleInFile, int &numSamples, int64 fileLengthInSamples)
Definition: juce_AudioFormatReader.h:306
juce::AudioFormatReader::readSamples
virtual bool readSamples(int **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:39
juce::AudioFormatReader::ReadHelper
Definition: juce_AudioFormatReader.h:279