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

`#include <juce_AudioFormatReader.h>`

Inheritance diagram for juce::AudioFormatReader:

## Classes

struct | ReadHelper

## Public Member Functions

virtual | ~AudioFormatReader ()
const String & | getFormatName () const noexcept
bool | read (float *const *destChannels, int numDestChannels, int64 startSampleInSource, int numSamplesToRead)
bool | read (int *const *destChannels, int numDestChannels, int64 startSampleInSource, int numSamplesToRead, bool fillLeftoverChannelsWithCopies)
bool | read (AudioBuffer< float > *buffer, int startSampleInDestBuffer, int numSamples, int64 readerStartSample, bool useReaderLeftChan, bool useReaderRightChan)
virtual void | readMaxLevels (int64 startSample, int64 numSamples, Range< float > *results, int numChannelsToRead)
virtual void | readMaxLevels (int64 startSample, int64 numSamples, float &lowestLeft, float &highestLeft, float &lowestRight, float &highestRight)
int64 | searchForLevel (int64 startSample, int64 numSamplesToSearch, double magnitudeRangeMinimum, double magnitudeRangeMaximum, int minimumConsecutiveSamples)
virtual AudioChannelSet | getChannelLayout ()
virtual bool | readSamples (int *const *destChannels, int numDestChannels, int startOffsetInDestBuffer, int64 startSampleInFile, int numSamples)=0

## Public Attributes

double | sampleRate = 0
unsigned int | bitsPerSample = 0
int64 | lengthInSamples = 0
unsigned int | numChannels = 0
bool | usesFloatingPointData = false
StringPairArray | metadataValues
InputStream * | input

## Protected Member Functions

| AudioFormatReader (InputStream *sourceStream, const String &formatName)

## Static Protected Member Functions

static void | clearSamplesBeyondAvailableLength (int *const *destChannels, int numDestChannels, int startOffsetInDestBuffer, int64 startSampleInFile, int &numSamples, int64 fileLengthInSamples)

## Detailed Description

Reads samples from an audio file stream.

A subclass that reads a specific type of audio format will be created by an AudioFormat object.

See also
  AudioFormat, AudioFormatWriter

Definition at line 43 of file juce_AudioFormatReader.h.

## Constructor & Destructor Documentation

## AudioFormatReader()

juce::AudioFormatReader::AudioFormatReader | ( | InputStream * | sourceStream,
|  | const String & | formatName )

protected

Creates an AudioFormatReader object.

Parameters

  sourceStream | the stream to read from - this will be deleted by this object when it is no longer needed. (Some specialised readers might not use this parameter and can leave it as nullptr).
  formatName | the description that will be returned by the getFormatName() method

Definition at line 29 of file juce_AudioFormatReader.cpp.

Referenced by juce::ARAAudioSourceReader::ARAAudioSourceReader(), juce::ARAPlaybackRegionReader::ARAPlaybackRegionReader(), juce::AudioSubsectionReader::AudioSubsectionReader(), juce::BufferingAudioReader::BufferingAudioReader(), and juce::MemoryMappedAudioFormatReader::MemoryMappedAudioFormatReader().

## ~AudioFormatReader()

juce::AudioFormatReader::~AudioFormatReader | ( |  | ) |

virtual

Destructor.

Definition at line 34 of file juce_AudioFormatReader.cpp.

## Member Function Documentation

## clearSamplesBeyondAvailableLength()

void juce::AudioFormatReader::clearSamplesBeyondAvailableLength | ( | int *const * | destChannels,
|  | int | numDestChannels,
|  | int | startOffsetInDestBuffer,
|  | int64 | startSampleInFile,
|  | int & | numSamples,
|  | int64 | fileLengthInSamples )

inline static protected

Used by AudioFormatReader subclasses to clear any parts of the data blocks that lie beyond the end of their available length.

Definition at line 309 of file juce_AudioFormatReader.h.

Referenced by juce::AudioSubsectionReader::readSamples(), and juce::BufferingAudioReader::readSamples().

## getChannelLayout()

AudioChannelSet juce::AudioFormatReader::getChannelLayout | ( |  | ) |

virtual

Get the channel layout of the audio stream.

Definition at line 398 of file juce_AudioFormatReader.cpp.

## getFormatName()

const String & juce::AudioFormatReader::getFormatName | ( |  | ) | const

inline noexcept

Returns a description of what type of format this is.

E.g. "AIFF"

Definition at line 68 of file juce_AudioFormatReader.h.

Referenced by juce::AudioSubsectionReader::AudioSubsectionReader(), juce::BufferingAudioReader::BufferingAudioReader(), and juce::MemoryMappedAudioFormatReader::MemoryMappedAudioFormatReader().

## read() [1/3]

bool juce::AudioFormatReader::read | ( | AudioBuffer< float > * | buffer,
|  | int | startSampleInDestBuffer,
|  | int | numSamples,
|  | int64 | readerStartSample,
|  | bool | useReaderLeftChan,
|  | bool | useReaderRightChan )

Fills a section of an AudioBuffer from this reader.

This will convert the reader's fixed- or floating-point data to the buffer's floating-point format, and will try to intelligently cope with mismatches between the number of channels in the reader and the buffer.

Returns
  true if the operation succeeded, false if there was an error. Note that reading sections of data beyond the extent of the stream isn't an error - the reader should just return zeros for these regions

Definition at line 142 of file juce_AudioFormatReader.cpp.

## read() [2/3]

bool juce::AudioFormatReader::read | ( | float *const * | destChannels,
|  | int | numDestChannels,
|  | int64 | startSampleInSource,
|  | int | numSamplesToRead )

Reads samples from the stream.

Parameters

  destChannels | an array of float buffers into which the sample data for each channel will be written. Channels that aren't needed can be null
  numDestChannels | the number of array elements in the destChannels array
  startSampleInSource | the position in the audio file or stream at which the samples should be read, as a number of samples from the start of the stream. It's ok for this to be beyond the start or end of the available data - any samples that are out-of-range will be returned as zeros.
  numSamplesToRead | the number of samples to read. If this is greater than the number of samples that the file or stream contains. the result will be padded with zeros

Returns
  true if the operation succeeded, false if there was an error. Note that reading sections of data beyond the extent of the stream isn't an error - the reader should just return zeros for these regions

See also
  readMaxLevels

Definition at line 48 of file juce_AudioFormatReader.cpp.

Referenced by read(), read(), readMaxLevels(), searchForLevel(), and juce::AudioFormatWriter::writeFromAudioReader().

## read() [3/3]

bool juce::AudioFormatReader::read | ( | int *const * | destChannels,
|  | int | numDestChannels,
|  | int64 | startSampleInSource,
|  | int | numSamplesToRead,
|  | bool | fillLeftoverChannelsWithCopies )

Reads samples from the stream.

Parameters

  destChannels

  an array of buffers into which the sample data for each channel will be written. If the format is fixed-point, each channel will be written as an array of 32-bit signed integers using the full range -0x80000000 to 0x7fffffff, regardless of the source's bit-depth. If it is a floating-point format, you should cast the resulting array to a (float**) to get the values (in the range -1.0 to 1.0 or beyond) If the format is stereo, then destChannels[0] is the left channel data, and destChannels[1] is the right channel. The numDestChannels parameter indicates how many pointers this array contains, but some of these pointers can be null if you don't want to read data for some of the channels

  numDestChannels | the number of array elements in the destChannels array
  startSampleInSource | the position in the audio file or stream at which the samples should be read, as a number of samples from the start of the stream. It's ok for this to be beyond the start or end of the available data - any samples that are out-of-range will be returned as zeros.
  numSamplesToRead | the number of samples to read. If this is greater than the number of samples that the file or stream contains. the result will be padded with zeros

  fillLeftoverChannelsWithCopies

  if true, this indicates that if there's no source data available for some of the channels that you pass in, then they should be filled with copies of valid source channels. E.g. if you're reading a mono file and you pass 2 channels to this method, then if fillLeftoverChannelsWithCopies is true, both destination channels will be filled with the same data from the file's single channel. If fillLeftoverChannelsWithCopies was false, then only the first channel would be filled with the file's contents, and the second would be cleared. If there are many channels, e.g. you try to read 4 channels from a stereo file, then the last 3 would all end up with copies of the same data.

Returns
  true if the operation succeeded, false if there was an error. Note that reading sections of data beyond the extent of the stream isn't an error - the reader should just return zeros for these regions

See also
  readMaxLevels

Definition at line 62 of file juce_AudioFormatReader.cpp.

## readMaxLevels() [1/2]

void juce::AudioFormatReader::readMaxLevels | ( | int64 | startSample,
|  | int64 | numSamples,
|  | float & | lowestLeft,
|  | float & | highestLeft,
|  | float & | lowestRight,
|  | float & | highestRight )

virtual

Finds the highest and lowest sample levels from a section of the audio stream.

This will read a block of samples from the stream, and measure the highest and lowest sample levels from the channels in that section, returning these as normalised floating-point levels.

Parameters

  startSample | the offset into the audio stream to start reading from. It's ok for this to be beyond the start or end of the stream.
  numSamples | how many samples to read
  lowestLeft | on return, this is the lowest absolute sample from the left channel
  highestLeft | on return, this is the highest absolute sample from the left channel
  lowestRight | on return, this is the lowest absolute sample from the right channel (if there is one)
  highestRight | on return, this is the highest absolute sample from the right channel (if there is one)

See also
  read

Reimplemented in juce::AudioSubsectionReader.

Definition at line 261 of file juce_AudioFormatReader.cpp.

## readMaxLevels() [2/2]

void juce::AudioFormatReader::readMaxLevels | ( | int64 | startSample,
|  | int64 | numSamples,
|  | Range< float > * | results,
|  | int | numChannelsToRead )

virtual

Finds the highest and lowest sample levels from a section of the audio stream.

This will read a block of samples from the stream, and measure the highest and lowest sample levels from the channels in that section, returning these as normalised floating-point levels.

Parameters

  startSample | the offset into the audio stream to start reading from. It's ok for this to be beyond the start or end of the stream.
  numSamples | how many samples to read
  results | this array will be filled with Range values for each channel. The array must contain numChannels elements.
  numChannelsToRead | the number of channels of data to scan. This must be more than zero, but not more than the total number of channels that the reader contains

See also
  read

Reimplemented in juce::AudioSubsectionReader.

Definition at line 209 of file juce_AudioFormatReader.cpp.

Referenced by readMaxLevels().

## readSamples()

virtual bool juce::AudioFormatReader::readSamples | ( | int *const * | destChannels,
|  | int | numDestChannels,
|  | int | startOffsetInDestBuffer,
|  | int64 | startSampleInFile,
|  | int | numSamples )

pure virtual

Subclasses must implement this method to perform the low-level read operation.

Callers should use read() instead of calling this directly.

Parameters

  destChannels | the array of destination buffers to fill. Some of these pointers may be null
  numDestChannels | the number of items in the destChannels array. This value is guaranteed not to be greater than the number of channels that this reader object contains
  startOffsetInDestBuffer | the number of samples from the start of the dest data at which to begin writing
  startSampleInFile | the number of samples into the source data at which to begin reading. This value is guaranteed to be >= 0.
  numSamples | the number of samples to read

Implemented in juce::ARAAudioSourceReader, juce::ARAPlaybackRegionReader, juce::AudioSubsectionReader, and juce::BufferingAudioReader.

Referenced by read().

## searchForLevel()

int64 juce::AudioFormatReader::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.

This will read from the source, either forwards or backwards between two sample positions, until it finds a sample whose magnitude lies between two specified levels.

If it finds a suitable sample, it returns its position; if not, it will return -1.

There's also a minimumConsecutiveSamples setting to help avoid spikes or zero-crossing points when you're searching for a continuous range of samples

Parameters

  startSample | the first sample to look at
  numSamplesToSearch | the number of samples to scan. If this value is negative, the search will go backwards
  magnitudeRangeMinimum | the lowest magnitude (inclusive) that is considered a hit, from 0 to 1.0
  magnitudeRangeMaximum | the highest magnitude (inclusive) that is considered a hit, from 0 to 1.0
  minimumConsecutiveSamples | if this is > 0, the method will only look for a sequence of this many consecutive samples, all of which lie within the target range. When it finds such a sequence, it returns the position of the first in-range sample it found (i.e. the earliest one if scanning forwards, the latest one if scanning backwards)

Definition at line 283 of file juce_AudioFormatReader.cpp.

## Member Data Documentation

## bitsPerSample

unsigned int juce::AudioFormatReader::bitsPerSample = 0

The number of bits per sample, e.g. 16, 24, 32.

Definition at line 228 of file juce_AudioFormatReader.h.

Referenced by juce::ARAAudioSourceReader::ARAAudioSourceReader(), juce::ARAPlaybackRegionReader::ARAPlaybackRegionReader(), juce::AudioSubsectionReader::AudioSubsectionReader(), juce::BufferingAudioReader::BufferingAudioReader(), juce::MemoryMappedAudioFormatReader::MemoryMappedAudioFormatReader(), juce::ARAAudioSourceReader::readSamples(), and juce::MemoryMappedAudioFormatReader::scanMinAndMaxInterleaved().

## input

InputStream* juce::AudioFormatReader::input

The input stream, for use by subclasses.

Definition at line 248 of file juce_AudioFormatReader.h.

Referenced by AudioFormatReader(), and ~AudioFormatReader().

## lengthInSamples

int64 juce::AudioFormatReader::lengthInSamples = 0

The total number of samples in the audio stream.

Definition at line 231 of file juce_AudioFormatReader.h.

Referenced by juce::ARAAudioSourceReader::ARAAudioSourceReader(), juce::ARAPlaybackRegionReader::ARAPlaybackRegionReader(), juce::AudioSubsectionReader::AudioSubsectionReader(), juce::BufferingAudioReader::BufferingAudioReader(), juce::MemoryMappedAudioFormatReader::mapEntireFile(), juce::MemoryMappedAudioFormatReader::mapSectionOfFile(), juce::MemoryMappedAudioFormatReader::MemoryMappedAudioFormatReader(), juce::BufferingAudioReader::readSamples(), juce::SamplerSound::SamplerSound(), searchForLevel(), and juce::AudioFormatWriter::writeFromAudioReader().

## metadataValues

StringPairArray juce::AudioFormatReader::metadataValues

A set of metadata values that the reader has pulled out of the stream.

Exactly what these values are depends on the format, so you can check out the format implementation code to see what kind of stuff they understand.

Definition at line 245 of file juce_AudioFormatReader.h.

Referenced by juce::BufferingAudioReader::BufferingAudioReader(), and juce::MemoryMappedAudioFormatReader::MemoryMappedAudioFormatReader().

## numChannels

unsigned int juce::AudioFormatReader::numChannels = 0

The total number of channels in the audio stream.

Definition at line 234 of file juce_AudioFormatReader.h.

Referenced by juce::ARAAudioSourceReader::ARAAudioSourceReader(), juce::ARAPlaybackRegionReader::ARAPlaybackRegionReader(), juce::AudioSubsectionReader::AudioSubsectionReader(), juce::BufferingAudioReader::BufferingAudioReader(), getChannelLayout(), juce::MemoryMappedAudioFormatReader::MemoryMappedAudioFormatReader(), read(), read(), readMaxLevels(), readMaxLevels(), juce::BufferingAudioReader::readSamples(), juce::MemoryMappedAudioFormatReader::scanMinAndMaxInterleaved(), and searchForLevel().

## sampleRate

double juce::AudioFormatReader::sampleRate = 0

The sample-rate of the stream.

Definition at line 225 of file juce_AudioFormatReader.h.

Referenced by juce::ARAAudioSourceReader::ARAAudioSourceReader(), juce::ARAPlaybackRegionReader::ARAPlaybackRegionReader(), juce::AudioSubsectionReader::AudioSubsectionReader(), juce::BufferingAudioReader::BufferingAudioReader(), juce::MemoryMappedAudioFormatReader::MemoryMappedAudioFormatReader(), and juce::ARAPlaybackRegionReader::readSamples().

## usesFloatingPointData

bool juce::AudioFormatReader::usesFloatingPointData = false

Indicates whether the data is floating-point or fixed.

Definition at line 237 of file juce_AudioFormatReader.h.

Referenced by juce::ARAAudioSourceReader::ARAAudioSourceReader(), juce::ARAPlaybackRegionReader::ARAPlaybackRegionReader(), juce::AudioSubsectionReader::AudioSubsectionReader(), juce::BufferingAudioReader::BufferingAudioReader(), juce::MemoryMappedAudioFormatReader::MemoryMappedAudioFormatReader(), read(), readMaxLevels(), juce::AudioSubsectionReader::readMaxLevels(), searchForLevel(), and juce::AudioFormatWriter::writeFromAudioReader().

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

- juce_AudioFormatReader.h
- juce_AudioFormatReader.cpp