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
27namespace juce
28{
29
30class AudioFormat;
31
32
33//==============================================================================
44class JUCE_API AudioFormatReader
45{
46protected:
47 //==============================================================================
57 AudioFormatReader (InputStream* sourceStream,
58 const String& formatName);
59
60public:
62 virtual ~AudioFormatReader();
63
64 //==============================================================================
69 const String& getFormatName() const noexcept { return formatName; }
70
71 //==============================================================================
90 bool read (float* const* destChannels, int numDestChannels,
92
131 bool read (int* const* destChannels,
132 int numDestChannels,
136
144 void read (AudioBuffer<float>* buffer,
146 int numSamples,
147 int64 readerStartSample,
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,
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
243
246
247 //==============================================================================
249 virtual AudioChannelSet getChannelLayout();
250
251 //==============================================================================
267 virtual bool readSamples (int** destChannels,
268 int numDestChannels,
270 int64 startSampleInFile,
271 int numSamples) = 0;
272
273
274protected:
275 //==============================================================================
277 template <class DestSampleType, class SourceSampleType, class SourceEndianness>
279 {
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,
308 int& numSamples, int64 fileLengthInSamples)
309 {
310 jassert (destChannels != nullptr);
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
323private:
324 String formatName;
325
326 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioFormatReader)
327};
328
329} // namespace juce
void clearSamples(int numSamples) const noexcept
void convertSamples(Pointer source, int numSamples) const noexcept
const String & getFormatName() const noexcept
static void clearSamplesBeyondAvailableLength(int **destChannels, int numDestChannels, int startOffsetInDestBuffer, int64 startSampleInFile, int &numSamples, int64 fileLengthInSamples)
virtual bool readSamples(int **destChannels, int numDestChannels, int startOffsetInDestBuffer, int64 startSampleInFile, int numSamples)=0