Loading...
Searching...
No Matches
juce_MemoryMappedAudioFormatReader.h
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 7 End-User License
Agreement and JUCE Privacy Policy.
End User License Agreement: www.juce.com/juce-7-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
class JUCE_API MemoryMappedAudioFormatReader : public AudioFormatReader
{
protected:
//==============================================================================
MemoryMappedAudioFormatReader (const File& file, const AudioFormatReader& details,
int64 dataChunkStart, int64 dataChunkLength, int bytesPerFrame);
public:
const File& getFile() const noexcept { return file; }
bool mapEntireFile();
virtual bool mapSectionOfFile (Range<int64> samplesToMap);
Range<int64> getMappedSection() const noexcept { return mappedSection; }
void touchSample (int64 sample) const noexcept;
virtual void getSample (int64 sampleIndex, float* result) const noexcept = 0;
size_t getNumBytesUsed() const { return map != nullptr ? map->getSize() : 0; }
protected:
File file;
Range<int64> mappedSection;
std::unique_ptr<MemoryMappedFile> map;
int64 dataChunkStart, dataLength;
int bytesPerFrame;
inline int64 sampleToFilePos (int64 sample) const noexcept { return dataChunkStart + sample * bytesPerFrame; }
inline int64 filePosToSample (int64 filePos) const noexcept { return (filePos - dataChunkStart) / bytesPerFrame; }
inline const void* sampleToPointer (int64 sample) const noexcept { return addBytesToPointer (map->getData(), sampleToFilePos (sample) - map->getRange().getStart()); }
template <typename SampleType, typename Endianness>
Range<float> scanMinAndMaxInterleaved (int channel, int64 startSampleInFile, int64 numSamples) const noexcept
{
using SourceType = AudioData::Pointer <SampleType, Endianness, AudioData::Interleaved, AudioData::Const>;
return SourceType (addBytesToPointer (sampleToPointer (startSampleInFile), ((int) bitsPerSample / 8) * channel), (int) numChannels)
.findMinAndMax ((size_t) numSamples);
}
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MemoryMappedAudioFormatReader)
};
} // namespace juce
juce::AudioFormatReader::AudioFormatReader
AudioFormatReader(InputStream *sourceStream, const String &formatName)
Definition juce_AudioFormatReader.cpp:29
juce::AudioFormatReader::bitsPerSample
unsigned int bitsPerSample
Definition juce_AudioFormatReader.h:228
juce::AudioFormatReader::numChannels
unsigned int numChannels
Definition juce_AudioFormatReader.h:234
juce::File
Definition juce_File.h:45
juce::MemoryMappedAudioFormatReader
Definition juce_MemoryMappedAudioFormatReader.h:47
juce::MemoryMappedAudioFormatReader::MemoryMappedAudioFormatReader
MemoryMappedAudioFormatReader(const File &file, const AudioFormatReader &details, int64 dataChunkStart, int64 dataChunkLength, int bytesPerFrame)
Definition juce_AudioFormatReader.cpp:404
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