JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_MemoryMappedAudioFormatReader.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
29//==============================================================================
47{
48protected:
49 //==============================================================================
56 MemoryMappedAudioFormatReader (const File& file, const AudioFormatReader& details,
57 int64 dataChunkStart, int64 dataChunkLength, int bytesPerFrame);
58
59public:
61 const File& getFile() const noexcept { return file; }
62
64 bool mapEntireFile();
65
67 virtual bool mapSectionOfFile (Range<int64> samplesToMap);
68
70 Range<int64> getMappedSection() const noexcept { return mappedSection; }
71
73 void touchSample (int64 sample) const noexcept;
74
79 virtual void getSample (int64 sampleIndex, float* result) const noexcept = 0;
80
82 size_t getNumBytesUsed() const { return map != nullptr ? map->getSize() : 0; }
83
84protected:
85 File file;
86 Range<int64> mappedSection;
88 int64 dataChunkStart, dataLength;
89 int bytesPerFrame;
90
92 inline int64 sampleToFilePos (int64 sample) const noexcept { return dataChunkStart + sample * bytesPerFrame; }
93
95 inline int64 filePosToSample (int64 filePos) const noexcept { return (filePos - dataChunkStart) / bytesPerFrame; }
96
98 inline const void* sampleToPointer (int64 sample) const noexcept { return addBytesToPointer (map->getData(), sampleToFilePos (sample) - map->getRange().getStart()); }
99
101 template <typename SampleType, typename Endianness>
102 Range<float> scanMinAndMaxInterleaved (int channel, int64 startSampleInFile, int64 numSamples) const noexcept
103 {
104 using SourceType = AudioData::Pointer <SampleType, Endianness, AudioData::Interleaved, AudioData::Const>;
105
106 return SourceType (addBytesToPointer (sampleToPointer (startSampleInFile), ((int) bitsPerSample / 8) * channel), (int) numChannels)
107 .findMinAndMax ((size_t) numSamples);
108 }
109
111};
112
113} // namespace juce
Reads samples from an audio file stream.
Represents a local file or directory.
Definition juce_File.h:45
A specialised type of AudioFormatReader that uses a MemoryMappedFile to read directly from an audio f...
const File & getFile() const noexcept
Returns the file that is being mapped.
virtual void getSample(int64 sampleIndex, float *result) const noexcept=0
Returns the samples for all channels at a given sample position.
Range< int64 > getMappedSection() const noexcept
Returns the sample range that's currently memory-mapped and available for reading.
const void * sampleToPointer(int64 sample) const noexcept
Converts a sample index to a pointer to the mapped file memory.
size_t getNumBytesUsed() const
Returns the number of bytes currently being mapped.
int64 sampleToFilePos(int64 sample) const noexcept
Converts a sample index to a byte position in the file.
Range< float > scanMinAndMaxInterleaved(int channel, int64 startSampleInFile, int64 numSamples) const noexcept
Used by AudioFormatReader subclasses to scan for min/max ranges in interleaved data.
int64 filePosToSample(int64 filePos) const noexcept
Converts a byte position in the file to a sample index.
A general-purpose range object, that simply represents any linear range with a start and end point.
Definition juce_Range.h:40
static Range findMinAndMax(const ValueType *values, Integral numValues) noexcept
Scans an array of values for its min and max, and returns these as a Range.
Definition juce_Range.h:279
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
This is a shorthand way of writing both a JUCE_DECLARE_NON_COPYABLE and JUCE_LEAK_DETECTOR macro for ...
JUCE Namespace.
Type * addBytesToPointer(Type *basePointer, IntegerType bytes) noexcept
A handy function which adds a number of bytes to any type of pointer and returns the result.
long long int64
A platform-independent 64-bit integer type.