LMMS
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 //==============================================================================
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
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:
87 std::unique_ptr<MemoryMappedFile> map;
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
#define noexcept
Definition DistrhoDefines.h:72
AudioFormatReader(InputStream *sourceStream, const String &formatName)
Definition juce_AudioFormatReader.cpp:29
unsigned int bitsPerSample
Definition juce_AudioFormatReader.h:228
unsigned int numChannels
Definition juce_AudioFormatReader.h:234
Definition juce_File.h:45
Definition juce_MemoryMappedAudioFormatReader.h:47
MemoryMappedAudioFormatReader(const File &file, const AudioFormatReader &details, int64 dataChunkStart, int64 dataChunkLength, int bytesPerFrame)
Definition juce_AudioFormatReader.cpp:404
int64 dataLength
Definition juce_MemoryMappedAudioFormatReader.h:88
Range< int64 > mappedSection
Definition juce_MemoryMappedAudioFormatReader.h:86
const File & getFile() const noexcept
Definition juce_MemoryMappedAudioFormatReader.h:61
std::unique_ptr< MemoryMappedFile > map
Definition juce_MemoryMappedAudioFormatReader.h:87
int64 dataChunkStart
Definition juce_MemoryMappedAudioFormatReader.h:88
virtual void getSample(int64 sampleIndex, float *result) const noexcept=0
Range< int64 > getMappedSection() const noexcept
Definition juce_MemoryMappedAudioFormatReader.h:70
File file
Definition juce_MemoryMappedAudioFormatReader.h:85
int bytesPerFrame
Definition juce_MemoryMappedAudioFormatReader.h:89
const void * sampleToPointer(int64 sample) const noexcept
Definition juce_MemoryMappedAudioFormatReader.h:98
size_t getNumBytesUsed() const
Definition juce_MemoryMappedAudioFormatReader.h:82
int64 sampleToFilePos(int64 sample) const noexcept
Definition juce_MemoryMappedAudioFormatReader.h:92
Range< float > scanMinAndMaxInterleaved(int channel, int64 startSampleInFile, int64 numSamples) const noexcept
Definition juce_MemoryMappedAudioFormatReader.h:102
int64 filePosToSample(int64 filePos) const noexcept
Definition juce_MemoryMappedAudioFormatReader.h:95
Definition juce_Range.h:40
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
#define JUCE_API
Definition juce_StandardHeader.h:152
Definition carla_juce.cpp:31
long long int64
Definition juce_MathsFunctions.h:54
Type * addBytesToPointer(Type *basePointer, IntegerType bytes) noexcept
Definition juce_Memory.h:111
signed int sample
Definition tap_dynamics_m.c:41
int result
Definition process.c:1455
#define const
Definition zconf.h:137