Eric Oulashin's C++ Audio Mixer 1.0
EOUtils::FLACFile Class Reference

#include <FLACFile.h>

Inheritance diagram for EOUtils::FLACFile:
Inheritance graph
Collaboration diagram for EOUtils::FLACFile:
Collaboration graph

Classes

struct  DecoderClientData
 Used by FLAC decoder callbacks (same layout as FLAC client data). More...

Public Member Functions

 FLACFile (const std::string &pFilename)
 Constructor for opening an existing FLAC file for reading, which just takes the filename.
 FLACFile (const std::string &pFilenam, uint32_t pCompressionLevel)
 Constructor for opening an existing FLAC file for reading, which takes the filename and a compression level.
 FLACFile (const std::string &pFilename, const FLACFileInfo &pFLACFileInfo)
 Constructor for opening an existing FLAC file for reading.
 FLACFile (const std::string &pFilename, AudioFileModes pFileMode)
 Constructor for opening a FLAC file for reading or writing.
 FLACFile (const FLACFile &pFLACFile)
 Copy constructor.
 FLACFile (FLACFile &&pFLACFile) noexcept
 Move constructor.
 ~FLACFile ()
void setAudioFileInfo (const AudioFileInfo &pAudioFileInfo) override
 Sets the audio file info for the FLAC file.
uint32_t CompressionLevel () const
 Returns the compression level currently set for the FLAC file.
void CompressionLevel (uint32_t pCompressionLevel)
 Sets the compression level to use when writing FLAC files.
AudioFileResultType open (AudioFileModes pOpenMode) override
 Opens the audio file in the given mode (read, write, or read/write).
void close () override
 Closes the FLAC file.
bool isOpen () const override
 Returns whether the FLAC file is open (and also has its encoder and/or decoder initialized).
const FLACFileInfogetFileInfo () const
 Returns a FLACFileInfo object with information about the FLAC file.
AudioFileResultType getNextSample_int64 (int64_t &pAudioSample) override
 Gets the next sample from the file, cast to a 64-bit integer.
AudioFileResultType writeSample_int64 (int64_t pAudioSample) override
 Writes an audio sample to the file. The parameter is a 64-bit integer but will be cast to the bitness of the audio samples in the file.
AudioFileResultType getHighestSampleValue_int64 (int64_t &pHighestAudioSample) override
 Gets the highest audio sample value from the file, cast to a 64-bit integer.
AudioFileResultType goToAudioDataPos () override
 Goes to the audio data position in the audio file.
size_t numSamples () const override
 Returns the number of audio samples in the audio file.
int64_t maxValueForSampleSize () const override
 Returns the maximum possible positive value of the audio file's sample size.
void seekOutputToSampleNum (size_t pSampleNum) override
 Returns the maximum possible positive value of the audio file's sample size.
AudioFileInfo getAudioFileInfo () const override
 Returns an AudioFile object with information about the audio file.
AudioFileResultType setTitle (const std::string &pTitle) override
 Sets the title metadata tag.
AudioFileResultType setArtist (const std::string &pArtist) override
 Sets the artist metadata tag.
AudioFileResultType setAlbum (const std::string &pAlbum) override
 Sets the album metadata tag.
AudioFileResultType setGenre (const std::string &pGenre) override
 Sets the genre metadata tag.
AudioFileResultType setTrackNumber (uint32_t pTrackNumber, uint32_t pTotalTracks=0) override
 Sets the track number metadata tag.
AudioFileResultType setYear (const std::string &pYear) override
 Sets the year/date metadata tag.
AudioFileResultType setComment (const std::string &pComment) override
 Sets the comment metadata tag.
AudioFileResultType getTitle (std::string &pTitle) const override
 Gets the title metadata tag.
AudioFileResultType getArtist (std::string &pArtist) const override
 Gets the artist metadata tag.
AudioFileResultType getAlbum (std::string &pAlbum) const override
 Gets the album metadata tag.
AudioFileResultType getGenre (std::string &pGenre) const override
 Gets the genre metadata tag.
AudioFileResultType getTrackNumber (uint32_t &pTrackNumber, uint32_t &pTotalTracks) const override
 Gets the track number metadata tag.
AudioFileResultType getYear (std::string &pYear) const override
 Gets the year/date metadata tag.
AudioFileResultType getComment (std::string &pComment) const override
 Gets the comment metadata tag.
Public Member Functions inherited from EOUtils::MetadataAudioFile
 MetadataAudioFile (const std::string &pFilename)
 MetadataAudioFile (const std::string &pFilename, AudioFileModes pFileMode)
 MetadataAudioFile (const MetadataAudioFile &pOther)
virtual ~MetadataAudioFile ()
Public Member Functions inherited from EOUtils::AudioFile
 AudioFile (const std::string &pFilename)
 Constructor.
 AudioFile (const std::string &pFilename, AudioFileModes pFileMode)
 AudioFile (const AudioFile &pAudioFile)
virtual ~AudioFile ()
virtual bool BitrateIsAdjustable () const =0
 Returns whether or not the audio file bitrate is adjustable.
virtual bool hasReadMode () const
 Returns whether or not read mode is enabled for the file.
virtual bool hasWriteMode () const
 Returns whether or not write mode is enabled for the file.
const std::string & Filename () const
 Gets the filename of the audio file.
void Filename (const std::string &pFilename)
 Setter for the filename of the audio file.
void setMetadata (const std::string &pName, const std::string &pValue)
 Adds a piece of metadata for the audio file.
template<typename T>
void setMetadataFromVal (const std::string &pName, const T &pValue)
 Adds a piece of metadata for the audio file. Templatized for any value type. The value will be converted to a string to store in the metadata.
AudioFileResultType getMetadata (const std::string &pName, std::string &pValue) const
 Gets a metadata value as a string.
template<typename T>
AudioFileResultType getMetadataAs (const std::string &pName, T &pValue) const
 Gets a metadata value. Templatized to capture the value as any type.
std::string getMetadata (const std::string &pName) const
 Gets a metadata value.
template<typename T>
getMetadataAs (const std::string &pName) const
template<typename T>
getMetadataAs (const std::string &pName, const T &pDefaultVal) const
 Gets a metadata value. Templatized to return it as any type.
bool hasMetadata (const std::string &pName) const
 Returns whether or not a metadata item exists.

Additional Inherited Members

Protected Member Functions inherited from EOUtils::AudioFile
virtual std::streampos fileSizeAccordingToStream ()
virtual void setFileMode (AudioFileModes pFileMode)
Protected Attributes inherited from EOUtils::AudioFile
std::string mFilename
std::fstream mFileStream
std::ios_base::openmode mFileOpenMode
size_t mDataSizeBytes
std::map< std::string, std::string > mMetadata

Constructor & Destructor Documentation

◆ FLACFile() [1/6]

EOUtils::FLACFile::FLACFile ( const std::string & pFilename)

Constructor for opening an existing FLAC file for reading, which just takes the filename.

Parameters
[in]pFilenameThe name of the FLAC file

Referenced by FLACFile(), FLACFile(), and FLACFile().

◆ FLACFile() [2/6]

EOUtils::FLACFile::FLACFile ( const std::string & pFilenam,
uint32_t pCompressionLevel )

Constructor for opening an existing FLAC file for reading, which takes the filename and a compression level.

Parameters
[in]pFilenameThe name of the FLAC file
[in]pCompressionLevelThe compression level to use when writing FLAC files (0-8, where 0 is fastest and 8 is maximum compression)

◆ FLACFile() [3/6]

EOUtils::FLACFile::FLACFile ( const std::string & pFilename,
const FLACFileInfo & pFLACFileInfo )

Constructor for opening an existing FLAC file for reading.

Parameters
[in]pFilenameThe name of the FLAC file
[in]pFLACFileInfoAn object containing information about the new FLAC file

◆ FLACFile() [4/6]

EOUtils::FLACFile::FLACFile ( const std::string & pFilename,
AudioFileModes pFileMode )

Constructor for opening a FLAC file for reading or writing.

Parameters
[in]pFilenameThe name of the FLAC file
[in]pFileModeThe mode to open the file in (read, write, or read/write)

References FLACFile().

◆ FLACFile() [5/6]

EOUtils::FLACFile::FLACFile ( const FLACFile & pFLACFile)

Copy constructor.

References FLACFile(), and EOUtils::MetadataAudioFile::MetadataAudioFile().

◆ FLACFile() [6/6]

EOUtils::FLACFile::FLACFile ( FLACFile && pFLACFile)
noexcept

Move constructor.

References FLACFile(), and EOUtils::MetadataAudioFile::MetadataAudioFile().

◆ ~FLACFile()

EOUtils::FLACFile::~FLACFile ( )

References close().

Member Function Documentation

◆ close()

void EOUtils::FLACFile::close ( )
overridevirtual

Closes the FLAC file.

Reimplemented from EOUtils::AudioFile.

References EOUtils::AudioFile::mFileStream.

Referenced by ~FLACFile().

◆ CompressionLevel() [1/2]

uint32_t EOUtils::FLACFile::CompressionLevel ( ) const

Returns the compression level currently set for the FLAC file.

◆ CompressionLevel() [2/2]

void EOUtils::FLACFile::CompressionLevel ( uint32_t pCompressionLevel)

Sets the compression level to use when writing FLAC files.

Parameters
[in]pCompressionLevelThe compression level to use when writing FLAC files (0-8, where 0 is fastest and 8 is maximum compression)

◆ getAlbum()

AudioFileResultType EOUtils::FLACFile::getAlbum ( std::string & pAlbum) const
overridevirtual

Gets the album metadata tag.

Parameters
[out]pAlbumWill receive the album string
Returns
An AudioFileResultType with errors on failure

Implements EOUtils::MetadataAudioFile.

◆ getArtist()

AudioFileResultType EOUtils::FLACFile::getArtist ( std::string & pArtist) const
overridevirtual

Gets the artist metadata tag.

Parameters
[out]pArtistWill receive the artist string
Returns
An AudioFileResultType with errors on failure

Implements EOUtils::MetadataAudioFile.

◆ getAudioFileInfo()

AudioFileInfo EOUtils::FLACFile::getAudioFileInfo ( ) const
overridevirtual

Returns an AudioFile object with information about the audio file.

Implements EOUtils::AudioFile.

◆ getComment()

AudioFileResultType EOUtils::FLACFile::getComment ( std::string & pComment) const
overridevirtual

Gets the comment metadata tag.

Parameters
[out]pCommentWill receive the comment string
Returns
An AudioFileResultType with errors on failure

Implements EOUtils::MetadataAudioFile.

◆ getFileInfo()

const FLACFileInfo & EOUtils::FLACFile::getFileInfo ( ) const

Returns a FLACFileInfo object with information about the FLAC file.

◆ getGenre()

AudioFileResultType EOUtils::FLACFile::getGenre ( std::string & pGenre) const
overridevirtual

Gets the genre metadata tag.

Parameters
[out]pGenreWill receive the genre string
Returns
An AudioFileResultType with errors on failure

Implements EOUtils::MetadataAudioFile.

◆ getHighestSampleValue_int64()

AudioFileResultType EOUtils::FLACFile::getHighestSampleValue_int64 ( int64_t & pHighestAudioSample)
overridevirtual

Gets the highest audio sample value from the file, cast to a 64-bit integer.

Parameters
[out]pHighestAudioSampleThe highest audio sample from the file, cast to a 64-bit integer
Returns
An AudioFileResultType object containing error messages on failure, or no errors on success. This can also be cast to a bool.

Implements EOUtils::AudioFile.

References EOUtils::AudioFileResultType::addError(), getNextSample_int64(), goToAudioDataPos(), and numSamples().

◆ getNextSample_int64()

AudioFileResultType EOUtils::FLACFile::getNextSample_int64 ( int64_t & pAudioSample)
overridevirtual

Gets the next sample from the file, cast to a 64-bit integer.

Parameters
[out]pAudioSampleThe next audio sample from the file, cast to a 64-bit integer
Returns
An AudioFileResultType object containing error messages on failure, or no errors on success. This can also be cast to a bool.

Implements EOUtils::AudioFile.

References EOUtils::AudioFileResultType::addError(), EOUtils::AudioFile::hasReadMode(), and EOUtils::AudioFileResultType::numErrors().

Referenced by getHighestSampleValue_int64().

◆ getTitle()

AudioFileResultType EOUtils::FLACFile::getTitle ( std::string & pTitle) const
overridevirtual

Gets the title metadata tag.

Parameters
[out]pTitleWill receive the title string
Returns
An AudioFileResultType with errors on failure

Implements EOUtils::MetadataAudioFile.

◆ getTrackNumber()

AudioFileResultType EOUtils::FLACFile::getTrackNumber ( uint32_t & pTrackNumber,
uint32_t & pTotalTracks ) const
overridevirtual

Gets the track number metadata tag.

Parameters
[out]pTrackNumberWill receive the track number
[out]pTotalTracksWill receive the total number of tracks (0 if not specified in the metadata)
Returns
An AudioFileResultType with errors on failure

Implements EOUtils::MetadataAudioFile.

References EOUtils::AudioFileResultType::addError().

◆ getYear()

AudioFileResultType EOUtils::FLACFile::getYear ( std::string & pYear) const
overridevirtual

Gets the year/date metadata tag.

Parameters
[out]pYearWill receive the year string
Returns
An AudioFileResultType with errors on failure

Implements EOUtils::MetadataAudioFile.

◆ goToAudioDataPos()

AudioFileResultType EOUtils::FLACFile::goToAudioDataPos ( )
overridevirtual

Goes to the audio data position in the audio file.

Implements EOUtils::AudioFile.

References EOUtils::AudioFileResultType::addError().

Referenced by getHighestSampleValue_int64().

◆ isOpen()

bool EOUtils::FLACFile::isOpen ( ) const
overridevirtual

Returns whether the FLAC file is open (and also has its encoder and/or decoder initialized).

Reimplemented from EOUtils::AudioFile.

References EOUtils::AudioFile::mFileStream.

◆ maxValueForSampleSize()

int64_t EOUtils::FLACFile::maxValueForSampleSize ( ) const
overridevirtual

Returns the maximum possible positive value of the audio file's sample size.

Implements EOUtils::AudioFile.

References EOUtils::maxValue().

◆ numSamples()

size_t EOUtils::FLACFile::numSamples ( ) const
overridevirtual

Returns the number of audio samples in the audio file.

Implements EOUtils::AudioFile.

References EOUtils::AudioFile::mFilename.

Referenced by getHighestSampleValue_int64().

◆ open()

AudioFileResultType EOUtils::FLACFile::open ( AudioFileModes pOpenMode)
overridevirtual

◆ seekOutputToSampleNum()

void EOUtils::FLACFile::seekOutputToSampleNum ( size_t pSampleNum)
overridevirtual

Returns the maximum possible positive value of the audio file's sample size.

Implements EOUtils::AudioFile.

◆ setAlbum()

AudioFileResultType EOUtils::FLACFile::setAlbum ( const std::string & pAlbum)
overridevirtual

Sets the album metadata tag.

Parameters
[in]pAlbumThe album string
Returns
An AudioFileResultType with errors on failure

Implements EOUtils::MetadataAudioFile.

◆ setArtist()

AudioFileResultType EOUtils::FLACFile::setArtist ( const std::string & pArtist)
overridevirtual

Sets the artist metadata tag.

Parameters
[in]pArtistThe artist string
Returns
An AudioFileResultType with errors on failure

Implements EOUtils::MetadataAudioFile.

◆ setAudioFileInfo()

void EOUtils::FLACFile::setAudioFileInfo ( const AudioFileInfo & pAudioFileInfo)
overridevirtual

Sets the audio file info for the FLAC file.

Implements EOUtils::AudioFile.

◆ setComment()

AudioFileResultType EOUtils::FLACFile::setComment ( const std::string & pComment)
overridevirtual

Sets the comment metadata tag.

Parameters
[in]pCommentThe comment string
Returns
An AudioFileResultType with errors on failure

Implements EOUtils::MetadataAudioFile.

◆ setGenre()

AudioFileResultType EOUtils::FLACFile::setGenre ( const std::string & pGenre)
overridevirtual

Sets the genre metadata tag.

Parameters
[in]pGenreThe genre string
Returns
An AudioFileResultType with errors on failure

Implements EOUtils::MetadataAudioFile.

◆ setTitle()

AudioFileResultType EOUtils::FLACFile::setTitle ( const std::string & pTitle)
overridevirtual

Sets the title metadata tag.

Parameters
[in]pTitleThe title string
Returns
An AudioFileResultType with errors on failure

Implements EOUtils::MetadataAudioFile.

◆ setTrackNumber()

AudioFileResultType EOUtils::FLACFile::setTrackNumber ( uint32_t pTrackNumber,
uint32_t pTotalTracks = 0 )
overridevirtual

Sets the track number metadata tag.

Parameters
[in]pTrackNumberThe track number
[in]pTotalTracksThe total number of tracks (0 means not specified, stores only the track number)
Returns
An AudioFileResultType with errors on failure

Implements EOUtils::MetadataAudioFile.

◆ setYear()

AudioFileResultType EOUtils::FLACFile::setYear ( const std::string & pYear)
overridevirtual

Sets the year/date metadata tag.

Parameters
[in]pYearThe year string (e.g., "2024")
Returns
An AudioFileResultType with errors on failure

Implements EOUtils::MetadataAudioFile.

◆ writeSample_int64()

AudioFileResultType EOUtils::FLACFile::writeSample_int64 ( int64_t pAudioSample)
overridevirtual

Writes an audio sample to the file. The parameter is a 64-bit integer but will be cast to the bitness of the audio samples in the file.

Parameters
[in]pAudioSampleThe audio sample to write to the file
Returns
An AudioFileResultType object containing error messages on failure, or no errors on success. This can also be cast to a bool.

Implements EOUtils::AudioFile.

References EOUtils::AudioFileResultType::addError(), and EOUtils::AudioFile::hasWriteMode().


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