JUCE  v6.1.6 (6.0.8-1114)
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::AudioCDReader Class Reference

A type of AudioFormatReader that reads from an audio CD. More...

#include <juce_AudioCDReader.h>

Inheritance diagram for juce::AudioCDReader:
Collaboration diagram for juce::AudioCDReader:

Public Types

enum  {
  framesPerSecond = 75,
  samplesPerFrame = 44100 / framesPerSecond
}
 

Public Member Functions

 ~AudioCDReader () override
 Destructor. More...
 
void ejectDisk ()
 Tries to eject the disk. More...
 
void enableIndexScanning (bool enabled)
 Enables scanning for indexes within tracks. More...
 
Array< intfindIndexesInTrack (const int trackNumber)
 Scans a track to find the position of any indexes within it. More...
 
int getCDDBId ()
 Returns the CDDB id number for the CD. More...
 
virtual AudioChannelSet getChannelLayout ()
 Get the channel layout of the audio stream. More...
 
const StringgetFormatName () const noexcept
 Returns a description of what type of format this is. More...
 
int getLastIndex () const
 Returns the index number found during the last read() call. More...
 
int getNumTracks () const
 Returns the total number of tracks (audio + data). More...
 
int getPositionOfTrackStart (int trackNum) const
 Finds the sample offset of the start of a track. More...
 
const Array< int > & getTrackOffsets () const
 Returns an array of sample offsets for the start of each track, followed by the sample position of the end of the CD. More...
 
bool isCDStillPresent () const
 Checks whether the CD has been removed from the drive. More...
 
bool isTrackAudio (int trackNum) const
 Returns true if a given track is an audio track. More...
 
void read (AudioBuffer< float > *buffer, int startSampleInDestBuffer, int numSamples, int64 readerStartSample, bool useReaderLeftChan, bool useReaderRightChan)
 Fills a section of an AudioBuffer from this reader. More...
 
bool read (float *const *destChannels, int numDestChannels, int64 startSampleInSource, int numSamplesToRead)
 Reads samples from the stream. More...
 
bool read (int *const *destChannels, int numDestChannels, int64 startSampleInSource, int numSamplesToRead, bool fillLeftoverChannelsWithCopies)
 Reads samples from the stream. More...
 
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. More...
 
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. More...
 
bool readSamples (int **destSamples, int numDestChannels, int startOffsetInDestBuffer, int64 startSampleInFile, int numSamples) override
 Implementation of the AudioFormatReader method. More...
 
void refreshTrackLengths ()
 Refreshes the object's table of contents. More...
 
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. More...
 

Static Public Member Functions

static AudioCDReadercreateReaderForCD (const int index)
 Tries to create an AudioFormatReader that can read from an Audio CD. More...
 
static StringArray getAvailableCDNames ()
 Returns a list of names of Audio CDs currently available for reading. More...
 

Public Attributes

unsigned int bitsPerSample = 0
 The number of bits per sample, e.g. More...
 
InputStreaminput
 The input stream, for use by subclasses. More...
 
int64 lengthInSamples = 0
 The total number of samples in the audio stream. More...
 
StringPairArray metadataValues
 A set of metadata values that the reader has pulled out of the stream. More...
 
unsigned int numChannels = 0
 The total number of channels in the audio stream. More...
 
double sampleRate = 0
 The sample-rate of the stream. More...
 
bool usesFloatingPointData = false
 Indicates whether the data is floating-point or fixed. More...
 

Static Protected Member Functions

static void clearSamplesBeyondAvailableLength (int **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. More...
 

Private Member Functions

 AudioCDReader (const File &volume)
 

Private Attributes

int currentReaderTrack
 
String formatName
 
std::unique_ptr< AudioFormatReaderreader
 
Array< Filetracks
 
Array< inttrackStartSamples
 
File volumeDir
 

Detailed Description

A type of AudioFormatReader that reads from an audio CD.

One of these can be used to read a CD as if it's one big audio stream. Use the getPositionOfTrackStart() method to find where the individual tracks are within the stream.

See also
AudioFormatReader

@tags{Audio}

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
framesPerSecond 
samplesPerFrame 

Constructor & Destructor Documentation

◆ ~AudioCDReader()

juce::AudioCDReader::~AudioCDReader ( )
override

Destructor.

◆ AudioCDReader()

juce::AudioCDReader::AudioCDReader ( const File volume)
private

Member Function Documentation

◆ clearSamplesBeyondAvailableLength()

static void juce::AudioFormatReader::clearSamplesBeyondAvailableLength ( int **  destChannels,
int  numDestChannels,
int  startOffsetInDestBuffer,
int64  startSampleInFile,
int numSamples,
int64  fileLengthInSamples 
)
inlinestaticprotectedinherited

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

References int(), jassertfalse, and juce::zeromem().

◆ createReaderForCD()

static AudioCDReader* juce::AudioCDReader::createReaderForCD ( const int  index)
static

Tries to create an AudioFormatReader that can read from an Audio CD.

Parameters
indexthe index of one of the available CDs - use getAvailableCDNames() to find out how many there are.
Returns
a new AudioCDReader object, or nullptr if it couldn't be created. The caller will be responsible for deleting the object returned.

◆ ejectDisk()

void juce::AudioCDReader::ejectDisk ( )

Tries to eject the disk.

Ejecting the disk might not actually be possible, e.g. if some other process is using it.

◆ enableIndexScanning()

void juce::AudioCDReader::enableIndexScanning ( bool  enabled)

Enables scanning for indexes within tracks.

See also
getLastIndex

◆ findIndexesInTrack()

Array<int> juce::AudioCDReader::findIndexesInTrack ( const int  trackNumber)

Scans a track to find the position of any indexes within it.

Parameters
trackNumberthe track to look in, where 0 is the first track on the disc
Returns
an array of sample positions of any index points found (not including the index that marks the start of the track)

◆ getAvailableCDNames()

static StringArray juce::AudioCDReader::getAvailableCDNames ( )
static

Returns a list of names of Audio CDs currently available for reading.

If there's a CD drive but no CD in it, this might return an empty list, or possibly a device that can be opened but which has no tracks, depending on the platform.

See also
createReaderForCD

◆ getCDDBId()

int juce::AudioCDReader::getCDDBId ( )

Returns the CDDB id number for the CD.

It's not a great way of identifying a disc, but it's traditional.

◆ getChannelLayout()

virtual AudioChannelSet juce::AudioFormatReader::getChannelLayout ( )
virtualinherited

Get the channel layout of the audio stream.

◆ getFormatName()

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

Returns a description of what type of format this is.

E.g. "AIFF"

◆ getLastIndex()

int juce::AudioCDReader::getLastIndex ( ) const

Returns the index number found during the last read() call.

Index scanning is turned off by default - turn it on with enableIndexScanning().

Then when the read() method is called, if it comes across an index within that block, the index number is stored and returned by this method.

Some devices might not support indexes, of course.

(If you don't know what CD indexes are, it's unlikely you'll ever need them).

See also
enableIndexScanning

◆ getNumTracks()

int juce::AudioCDReader::getNumTracks ( ) const

Returns the total number of tracks (audio + data).

◆ getPositionOfTrackStart()

int juce::AudioCDReader::getPositionOfTrackStart ( int  trackNum) const

Finds the sample offset of the start of a track.

Parameters
trackNumthe track number, where trackNum = 0 is the first track and trackNum = getNumTracks() means the end of the CD.

◆ getTrackOffsets()

const Array<int>& juce::AudioCDReader::getTrackOffsets ( ) const

Returns an array of sample offsets for the start of each track, followed by the sample position of the end of the CD.

◆ isCDStillPresent()

bool juce::AudioCDReader::isCDStillPresent ( ) const

Checks whether the CD has been removed from the drive.

◆ isTrackAudio()

bool juce::AudioCDReader::isTrackAudio ( int  trackNum) const

Returns true if a given track is an audio track.

Parameters
trackNumthe track number, where 0 is the first track.

◆ read() [1/3]

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

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.

◆ read() [2/3]

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

Reads samples from the stream.

Parameters
destChannelsan array of float buffers into which the sample data for each channel will be written. Channels that aren't needed can be null
numDestChannelsthe number of array elements in the destChannels array
startSampleInSourcethe 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.
numSamplesToReadthe 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

◆ read() [3/3]

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

Reads samples from the stream.

Parameters
destChannelsan 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
numDestChannelsthe number of array elements in the destChannels array
startSampleInSourcethe 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.
numSamplesToReadthe 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
fillLeftoverChannelsWithCopiesif 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

◆ readMaxLevels() [1/2]

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

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
startSamplethe offset into the audio stream to start reading from. It's ok for this to be beyond the start or end of the stream.
numSampleshow many samples to read
lowestLefton return, this is the lowest absolute sample from the left channel
highestLefton return, this is the highest absolute sample from the left channel
lowestRighton return, this is the lowest absolute sample from the right channel (if there is one)
highestRighton return, this is the highest absolute sample from the right channel (if there is one)
See also
read

◆ readMaxLevels() [2/2]

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

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
startSamplethe offset into the audio stream to start reading from. It's ok for this to be beyond the start or end of the stream.
numSampleshow many samples to read
resultsthis array will be filled with Range values for each channel. The array must contain numChannels elements.
numChannelsToReadthe 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.

◆ readSamples()

bool juce::AudioCDReader::readSamples ( int **  destSamples,
int  numDestChannels,
int  startOffsetInDestBuffer,
int64  startSampleInFile,
int  numSamples 
)
overridevirtual

Implementation of the AudioFormatReader method.

Implements juce::AudioFormatReader.

◆ refreshTrackLengths()

void juce::AudioCDReader::refreshTrackLengths ( )

Refreshes the object's table of contents.

If the disc has been ejected and a different one put in since this object was created, this will cause it to update its idea of how many tracks there are, etc.

◆ searchForLevel()

int64 juce::AudioFormatReader::searchForLevel ( int64  startSample,
int64  numSamplesToSearch,
double  magnitudeRangeMinimum,
double  magnitudeRangeMaximum,
int  minimumConsecutiveSamples 
)
inherited

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
startSamplethe first sample to look at
numSamplesToSearchthe number of samples to scan. If this value is negative, the search will go backwards
magnitudeRangeMinimumthe lowest magnitude (inclusive) that is considered a hit, from 0 to 1.0
magnitudeRangeMaximumthe highest magnitude (inclusive) that is considered a hit, from 0 to 1.0
minimumConsecutiveSamplesif 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)

Member Data Documentation

◆ bitsPerSample

unsigned int juce::AudioFormatReader::bitsPerSample = 0
inherited

The number of bits per sample, e.g.

16, 24, 32.

◆ currentReaderTrack

int juce::AudioCDReader::currentReaderTrack
private

◆ formatName

String juce::AudioFormatReader::formatName
privateinherited

◆ input

InputStream* juce::AudioFormatReader::input
inherited

The input stream, for use by subclasses.

◆ lengthInSamples

int64 juce::AudioFormatReader::lengthInSamples = 0
inherited

The total number of samples in the audio stream.

◆ metadataValues

StringPairArray juce::AudioFormatReader::metadataValues
inherited

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.

◆ numChannels

unsigned int juce::AudioFormatReader::numChannels = 0
inherited

The total number of channels in the audio stream.

◆ reader

std::unique_ptr<AudioFormatReader> juce::AudioCDReader::reader
private

◆ sampleRate

double juce::AudioFormatReader::sampleRate = 0
inherited

The sample-rate of the stream.

◆ tracks

Array<File> juce::AudioCDReader::tracks
private

◆ trackStartSamples

Array<int> juce::AudioCDReader::trackStartSamples
private

◆ usesFloatingPointData

bool juce::AudioFormatReader::usesFloatingPointData = false
inherited

Indicates whether the data is floating-point or fixed.

◆ volumeDir

File juce::AudioCDReader::volumeDir
private

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