OpenShot Audio Library | OpenShotAudio: juce_MemoryMappedAudioFormatReader.h Source File

OpenShot Audio Library | OpenShotAudio 0.3.2

Loading...
Searching...
No Matches
juce_MemoryMappedAudioFormatReader.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
30//==============================================================================
47 class JUCE_API MemoryMappedAudioFormatReader : public AudioFormatReader
48{
49protected:
50 //==============================================================================
57 MemoryMappedAudioFormatReader (const File& file, const AudioFormatReader& details,
58 int64 dataChunkStart, int64 dataChunkLength, int bytesPerFrame);
59
60public:
62 const File& getFile() const noexcept { return file; }
63
65 bool mapEntireFile();
66
68 virtual bool mapSectionOfFile (Range<int64> samplesToMap);
69
71 Range<int64> getMappedSection() const noexcept { return mappedSection; }
72
74 void touchSample (int64 sample) const noexcept;
75
80 virtual void getSample (int64 sampleIndex, float* result) const noexcept = 0;
81
83 size_t getNumBytesUsed() const { return map != nullptr ? map->getSize() : 0; }
84
85protected:
86 File file;
87 Range<int64> mappedSection;
88 std::unique_ptr<MemoryMappedFile> map;
89 int64 dataChunkStart, dataLength;
90 int bytesPerFrame;
91
93 inline int64 sampleToFilePos (int64 sample) const noexcept { return dataChunkStart + sample * bytesPerFrame; }
94
96 inline int64 filePosToSample (int64 filePos) const noexcept { return (filePos - dataChunkStart) / bytesPerFrame; }
97
99 inline const void* sampleToPointer (int64 sample) const noexcept { return addBytesToPointer (map->getData(), sampleToFilePos (sample) - map->getRange().getStart()); }
100
102 template <typename SampleType, typename Endianness>
103 Range<float> scanMinAndMaxInterleaved (int channel, int64 startSampleInFile, int64 numSamples) const noexcept
104 {
105 using SourceType = AudioData::Pointer <SampleType, Endianness, AudioData::Interleaved, AudioData::Const>;
106
107 return SourceType (addBytesToPointer (sampleToPointer (startSampleInFile), ((int) bitsPerSample / 8) * channel), (int) numChannels)
108 .findMinAndMax ((size_t) numSamples);
109 }
110
111 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MemoryMappedAudioFormatReader)
112};
113
114} // namespace juce
juce::AudioFormatReader
Definition: juce_AudioFormatReader.h:45
juce::File
Definition: juce_File.h:41
juce::MemoryMappedAudioFormatReader
Definition: juce_MemoryMappedAudioFormatReader.h:48
juce::MemoryMappedAudioFormatReader::getFile
const File & getFile() const noexcept
Definition: juce_MemoryMappedAudioFormatReader.h:62
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:71
juce::MemoryMappedAudioFormatReader::sampleToPointer
const void * sampleToPointer(int64 sample) const noexcept
Definition: juce_MemoryMappedAudioFormatReader.h:99
juce::MemoryMappedAudioFormatReader::getNumBytesUsed
size_t getNumBytesUsed() const
Definition: juce_MemoryMappedAudioFormatReader.h:83
juce::MemoryMappedAudioFormatReader::sampleToFilePos
int64 sampleToFilePos(int64 sample) const noexcept
Definition: juce_MemoryMappedAudioFormatReader.h:93
juce::MemoryMappedAudioFormatReader::scanMinAndMaxInterleaved
Range< float > scanMinAndMaxInterleaved(int channel, int64 startSampleInFile, int64 numSamples) const noexcept
Definition: juce_MemoryMappedAudioFormatReader.h:103
juce::MemoryMappedAudioFormatReader::filePosToSample
int64 filePosToSample(int64 filePos) const noexcept
Definition: juce_MemoryMappedAudioFormatReader.h:96
juce::Range
Definition: juce_Range.h:40