OpenShot Audio Library | OpenShotAudio 0.4.0

Loading...
Searching...
No Matches
juce_MemoryMappedAudioFormatReader.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//==============================================================================
46 class JUCE_API MemoryMappedAudioFormatReader : public AudioFormatReader
47{
48 protected:
49 //==============================================================================
56 MemoryMappedAudioFormatReader (const File& file, const AudioFormatReader& details,
57 int64 dataChunkStart, int64 dataChunkLength, int bytesPerFrame);
58
59 public:
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
84 protected:
85 File file;
86 Range<int64> mappedSection;
87 std::unique_ptr<MemoryMappedFile> map;
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
110 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MemoryMappedAudioFormatReader)
111};
112
113} // namespace juce
juce::AudioFormatReader
Definition juce_AudioFormatReader.h:44
juce::File
Definition juce_File.h:45
juce::MemoryMappedAudioFormatReader
Definition juce_MemoryMappedAudioFormatReader.h:47
juce::MemoryMappedAudioFormatReader::getFile
const File & getFile() const noexcept
Definition juce_MemoryMappedAudioFormatReader.h:61
juce::MemoryMappedAudioFormatReader::getSample
virtual void getSample(int64 sampleIndex, float *result) const noexcept=0
juce::MemoryMappedAudioFormatReader::getMappedSection
Range< int64 > getMappedSection() const noexcept
Definition juce_MemoryMappedAudioFormatReader.h:70
juce::MemoryMappedAudioFormatReader::sampleToPointer
const void * sampleToPointer(int64 sample) const noexcept
Definition juce_MemoryMappedAudioFormatReader.h:98
juce::MemoryMappedAudioFormatReader::getNumBytesUsed
size_t getNumBytesUsed() const
Definition juce_MemoryMappedAudioFormatReader.h:82
juce::MemoryMappedAudioFormatReader::sampleToFilePos
int64 sampleToFilePos(int64 sample) const noexcept
Definition juce_MemoryMappedAudioFormatReader.h:92
juce::MemoryMappedAudioFormatReader::scanMinAndMaxInterleaved
Range< float > scanMinAndMaxInterleaved(int channel, int64 startSampleInFile, int64 numSamples) const noexcept
Definition juce_MemoryMappedAudioFormatReader.h:102
juce::MemoryMappedAudioFormatReader::filePosToSample
int64 filePosToSample(int64 filePos) const noexcept
Definition juce_MemoryMappedAudioFormatReader.h:95
juce::Range
Definition juce_Range.h:40