Loading...
Searching...
No Matches
juce::MemoryMappedAudioFormatReader Class Referenceabstract

## Detailed Description

A specialised type of AudioFormatReader that uses a MemoryMappedFile to read directly from an audio file.

This allows for incredibly fast random-access to sample data in the mapped region of the file, but not all audio formats support it - see AudioFormat::createMemoryMappedReader().

Note that before reading samples from a MemoryMappedAudioFormatReader, you must first call mapEntireFile() or mapSectionOfFile() to ensure that the region you want to read has been mapped.

See also
  AudioFormat::createMemoryMappedReader, AudioFormatReader

The documentation for this class was generated from the following file:

- juce_audio_formats/format/juce_MemoryMappedAudioFormatReader.h

Inheritance diagram for juce::MemoryMappedAudioFormatReader:

## Public Member Functions

const File & | getFile () const noexcept
| Returns the file that is being mapped.
bool | mapEntireFile ()
| Attempts to map the entire file into memory.
virtual bool | mapSectionOfFile (Range< int64 > samplesToMap)
| Attempts to map a section of the file into memory.
Range< int64 > | getMappedSection () const noexcept
| Returns the sample range that's currently memory-mapped and available for reading.
void | touchSample (int64 sample) const noexcept
| Touches the memory for the given sample, to force it to be loaded into active memory.
virtual void | getSample (int64 sampleIndex, float *result) const noexcept=0
| Returns the samples for all channels at a given sample position.
size_t | getNumBytesUsed () const
| Returns the number of bytes currently being mapped.
Public Member Functions inherited from juce::AudioFormatReader
virtual | ~AudioFormatReader ()
| Destructor.
const String & | getFormatName () const noexcept
| Returns a description of what type of format this is.
bool | read (float *const *destChannels, int numDestChannels, int64 startSampleInSource, int numSamplesToRead)
| Reads samples from the stream.
bool | read (int *const *destChannels, int numDestChannels, int64 startSampleInSource, int numSamplesToRead, bool fillLeftoverChannelsWithCopies)
| Reads samples from the stream.
bool | read (AudioBuffer< float > *buffer, int startSampleInDestBuffer, int numSamples, int64 readerStartSample, bool useReaderLeftChan, bool useReaderRightChan)
| Fills a section of an AudioBuffer from this reader.
virtual void | readMaxLevels (int64 startSample, int64 numSamples, Range< float > *results, int numChannelsToRead)
| Finds the highest and lowest sample levels from a section of the audio stream.
virtual void | readMaxLevels (int64 startSample, int64 numSamples, float &lowestLeft, float &highestLeft, float &lowestRight, float &highestRight)
| Finds the highest and lowest sample levels from a section of the audio stream.
int64 | searchForLevel (int64 startSample, int64 numSamplesToSearch, double magnitudeRangeMinimum, double magnitudeRangeMaximum, int minimumConsecutiveSamples)
| Scans the source looking for a sample whose magnitude is in a specified range.
virtual AudioChannelSet | getChannelLayout ()
| Get the channel layout of the audio stream.
virtual bool | readSamples (int *const *destChannels, int numDestChannels, int startOffsetInDestBuffer, int64 startSampleInFile, int numSamples)=0
| Subclasses must implement this method to perform the low-level read operation.

## Protected Member Functions

| MemoryMappedAudioFormatReader (const File &file, const AudioFormatReader &details, int64 dataChunkStart, int64 dataChunkLength, int bytesPerFrame)
| Creates an MemoryMappedAudioFormatReader object.
int64 | sampleToFilePos (int64 sample) const noexcept
| Converts a sample index to a byte position in the file.
int64 | filePosToSample (int64 filePos) const noexcept
| Converts a byte position in the file to a sample index.
const void * | sampleToPointer (int64 sample) const noexcept
| Converts a sample index to a pointer to the mapped file memory.
template<typename SampleType, typename Endianness>
Range< float > | scanMinAndMaxInterleaved (int channel, int64 startSampleInFile, int64 numSamples) const noexcept
| Used by AudioFormatReader subclasses to scan for min/max ranges in interleaved data.
Protected Member Functions inherited from juce::AudioFormatReader
| AudioFormatReader (InputStream *sourceStream, const String &formatName)
| Creates an AudioFormatReader object.

## Protected Attributes

File | file
Range< int64 > | mappedSection
std::unique_ptr< MemoryMappedFile > | map
int64 | dataChunkStart
int64 | dataLength
int | bytesPerFrame

## Additional Inherited Members

Public Attributes inherited from juce::AudioFormatReader
double | sampleRate = 0
| The sample-rate of the stream.
unsigned int | bitsPerSample = 0
| The number of bits per sample, e.g.
int64 | lengthInSamples = 0
| The total number of samples in the audio stream.
unsigned int | numChannels = 0
| The total number of channels in the audio stream.
bool | usesFloatingPointData = false
| Indicates whether the data is floating-point or fixed.
StringPairArray | metadataValues
| A set of metadata values that the reader has pulled out of the stream.
InputStream * | input
| The input stream, for use by subclasses.
Static Protected Member Functions inherited from juce::AudioFormatReader
static void | clearSamplesBeyondAvailableLength (int *const *destChannels, int numDestChannels, int startOffsetInDestBuffer, int64 startSampleInFile, int &numSamples, int64 fileLengthInSamples)
| Used by AudioFormatReader subclasses to clear any parts of the data blocks that lie beyond the end of their available length.

## Constructors and Destructors

## MemoryMappedAudioFormatReader()

juce::MemoryMappedAudioFormatReader::MemoryMappedAudioFormatReader | ( | const File & | file,
|  | const AudioFormatReader & | details,
|  | int64 | dataChunkStart,
|  | int64 | dataChunkLength,
|  | int | bytesPerFrame )

protected

Creates an MemoryMappedAudioFormatReader object.

Note that before attempting to read any data, you must call mapEntireFile() or mapSectionOfFile() to ensure that the region you want to read has been mapped.

References juce::AudioFormatReader::AudioFormatReader(), bytesPerFrame, dataChunkStart, and file.

## Member Functions

## getFile()

const File & juce::MemoryMappedAudioFormatReader::getFile | ( |  | ) | const

inline noexcept

Returns the file that is being mapped.

References file.

## mapEntireFile()

bool juce::MemoryMappedAudioFormatReader::mapEntireFile | ( |  | ) |

Attempts to map the entire file into memory.

## mapSectionOfFile()

virtual bool juce::MemoryMappedAudioFormatReader::mapSectionOfFile | ( | Range< int64 > | samplesToMap | ) |

virtual

Attempts to map a section of the file into memory.

## getMappedSection()

Range< int64 > juce::MemoryMappedAudioFormatReader::getMappedSection | ( |  | ) | const

inline noexcept

Returns the sample range that's currently memory-mapped and available for reading.

References mappedSection.

## touchSample()

void juce::MemoryMappedAudioFormatReader::touchSample | ( | int64 | sample | ) | const

noexcept

Touches the memory for the given sample, to force it to be loaded into active memory.

## getSample()

virtual void juce::MemoryMappedAudioFormatReader::getSample | ( | int64 | sampleIndex,
|  | float * | result ) const

pure virtual noexcept

Returns the samples for all channels at a given sample position.

The result array must be large enough to hold a value for each channel that this reader contains.

## getNumBytesUsed()

size_t juce::MemoryMappedAudioFormatReader::getNumBytesUsed | ( |  | ) | const

inline

Returns the number of bytes currently being mapped.

References map.

## sampleToFilePos()

int64 juce::MemoryMappedAudioFormatReader::sampleToFilePos | ( | int64 | sample | ) | const

inline protected noexcept

Converts a sample index to a byte position in the file.

References bytesPerFrame, and dataChunkStart.

Referenced by sampleToPointer().

## filePosToSample()

int64 juce::MemoryMappedAudioFormatReader::filePosToSample | ( | int64 | filePos | ) | const

inline protected noexcept

Converts a byte position in the file to a sample index.

References bytesPerFrame, and dataChunkStart.

## sampleToPointer()

const void * juce::MemoryMappedAudioFormatReader::sampleToPointer | ( | int64 | sample | ) | const

inline protected noexcept

Converts a sample index to a pointer to the mapped file memory.

References juce::addBytesToPointer(), map, and sampleToFilePos().

Referenced by scanMinAndMaxInterleaved().

## scanMinAndMaxInterleaved()

template<typename SampleType, typename Endianness>

Range< float > juce::MemoryMappedAudioFormatReader::scanMinAndMaxInterleaved | ( | int | channel,
|  | int64 | startSampleInFile,
|  | int64 | numSamples ) const

inline protected noexcept

Used by AudioFormatReader subclasses to scan for min/max ranges in interleaved data.

References juce::addBytesToPointer(), juce::AudioFormatReader::bitsPerSample, juce::AudioFormatReader::numChannels, and sampleToPointer().

## Member Data Documentation

## file

File juce::MemoryMappedAudioFormatReader::file

protected

Referenced by getFile(), and MemoryMappedAudioFormatReader().

## mappedSection

Range<int64> juce::MemoryMappedAudioFormatReader::mappedSection

protected

Referenced by getMappedSection().

## map

std::unique_ptr<MemoryMappedFile> juce::MemoryMappedAudioFormatReader::map

protected

Referenced by getNumBytesUsed(), and sampleToPointer().

## dataChunkStart

int64 juce::MemoryMappedAudioFormatReader::dataChunkStart

protected

Referenced by filePosToSample(), MemoryMappedAudioFormatReader(), and sampleToFilePos().

## dataLength

int64 juce::MemoryMappedAudioFormatReader::dataLength

protected

## bytesPerFrame

int juce::MemoryMappedAudioFormatReader::bytesPerFrame

protected

Referenced by filePosToSample(), MemoryMappedAudioFormatReader(), and sampleToFilePos().

### Purchase

Get JUCE

### Discover

What's New in JUCE Features

### Learn

Documentaion Tutorials Made with JUCE Resources

### Support

JUCE Forum Newsletter Archive

### About

Contact Us JUCE Legal JUCE Licensing FAQ

### Events

Audio Developer Conference
© Raw Material Software Limited