Eric Oulashin's C++ Audio Mixer 1.0
EOUtils::SndFileBackedMetadataAudioFile Class Referenceabstract

Shared libsndfile-backed implementation used by MP3, Ogg Vorbis, and AIFF codecs. More...

#include <SndFileBackedMetadataAudioFile.h>

Inheritance diagram for EOUtils::SndFileBackedMetadataAudioFile:
Inheritance graph
Collaboration diagram for EOUtils::SndFileBackedMetadataAudioFile:
Collaboration graph

Public Member Functions

void setAudioFileInfo (const AudioFileInfo &pAudioFileInfo) override
AudioFileResultType open (AudioFileModes pOpenMode) override
void close () override
 Closes the audio file.
bool isOpen () const override
 Returns whether or not the audio file is open.
AudioFileResultType getNextSample_int64 (std::int64_t &pAudioSample) override
AudioFileResultType writeSample_int64 (std::int64_t pAudioSample) override
AudioFileResultType getHighestSampleValue_int64 (std::int64_t &pHighestAudioSample) override
AudioFileResultType goToAudioDataPos () override
 Goes to the audio data position in the audio file.
std::size_t numSamples () const override
 Returns the number of audio samples in the audio file.
std::int64_t maxValueForSampleSize () const override
 Returns the maximum possible positive value of the audio file's sample size.
void seekOutputToSampleNum (std::size_t pSampleNum) override
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 (std::uint32_t pTrackNumber, std::uint32_t pTotalTracks=0) override
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 (std::uint32_t &pTrackNumber, std::uint32_t &pTotalTracks) const override
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.
 ~SndFileBackedMetadataAudioFile () override
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 ()
virtual AudioFileResultType setTrackNumber (uint32_t pTrackNumber, uint32_t pTotalTracks=0)=0
 Sets the track number metadata tag.
virtual AudioFileResultType getTrackNumber (uint32_t &pTrackNumber, uint32_t &pTotalTracks) const =0
 Gets the track number metadata tag.
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.
virtual AudioFileResultType getNextSample_int64 (int64_t &pAudioSample)=0
 Gets the next sample from the file, cast to a 64-bit integer.
virtual AudioFileResultType writeSample_int64 (int64_t pAudioSample)=0
 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.
virtual AudioFileResultType getHighestSampleValue_int64 (int64_t &pHighestAudioSample)=0
 Gets the highest audio sample value from the file, cast to a 64-bit integer.
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.
virtual void seekOutputToSampleNum (size_t pSampleNum)=0

Protected Member Functions

 SndFileBackedMetadataAudioFile (const std::string &pFilename)
 SndFileBackedMetadataAudioFile (const std::string &pFilename, AudioFileModes pFileMode)
 SndFileBackedMetadataAudioFile (const SndFileBackedMetadataAudioFile &pOther)
 SndFileBackedMetadataAudioFile (SndFileBackedMetadataAudioFile &&pOther) noexcept
 SndFileBackedMetadataAudioFile (const std::string &pFilename, const AudioFileInfo &pLayoutHint)
virtual bool readFormatMatches (int pSfFullFormat) const =0
virtual int newFileSfFormatMask () const =0
virtual const char * formatLabel () const =0
virtual void configureSndfileEncoderForWrite (SNDFILE *)
Protected Member Functions inherited from EOUtils::AudioFile
virtual std::streampos fileSizeAccordingToStream ()
virtual void setFileMode (AudioFileModes pFileMode)

Protected Attributes

AudioFileInfo mFileLayout
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

Detailed Description

Shared libsndfile-backed implementation used by MP3, Ogg Vorbis, and AIFF codecs.

Constructor & Destructor Documentation

◆ ~SndFileBackedMetadataAudioFile()

EOUtils::SndFileBackedMetadataAudioFile::~SndFileBackedMetadataAudioFile ( )
override

References close().

◆ SndFileBackedMetadataAudioFile() [1/5]

◆ SndFileBackedMetadataAudioFile() [2/5]

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

◆ SndFileBackedMetadataAudioFile() [3/5]

EOUtils::SndFileBackedMetadataAudioFile::SndFileBackedMetadataAudioFile ( const SndFileBackedMetadataAudioFile & pOther)
protected

◆ SndFileBackedMetadataAudioFile() [4/5]

EOUtils::SndFileBackedMetadataAudioFile::SndFileBackedMetadataAudioFile ( SndFileBackedMetadataAudioFile && pOther)
protectednoexcept

◆ SndFileBackedMetadataAudioFile() [5/5]

EOUtils::SndFileBackedMetadataAudioFile::SndFileBackedMetadataAudioFile ( const std::string & pFilename,
const AudioFileInfo & pLayoutHint )
explicitprotected

Member Function Documentation

◆ close()

void EOUtils::SndFileBackedMetadataAudioFile::close ( )
overridevirtual

Closes the audio file.

Reimplemented from EOUtils::AudioFile.

References EOUtils::AudioFile::close().

Referenced by open(), and ~SndFileBackedMetadataAudioFile().

◆ configureSndfileEncoderForWrite()

virtual void EOUtils::SndFileBackedMetadataAudioFile::configureSndfileEncoderForWrite ( SNDFILE * )
inlineprotectedvirtual

After a successful SFM_WRITE open, codecs may tweak the encoder via sf_command. Default: no-op.

Reimplemented in EOUtils::MP3File, and EOUtils::OggFile.

Referenced by open().

◆ formatLabel()

virtual const char * EOUtils::SndFileBackedMetadataAudioFile::formatLabel ( ) const
protectedpure virtual

◆ getAlbum()

AudioFileResultType EOUtils::SndFileBackedMetadataAudioFile::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::SndFileBackedMetadataAudioFile::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::SndFileBackedMetadataAudioFile::getAudioFileInfo ( ) const
overridevirtual

Returns an AudioFile object with information about the audio file.

Implements EOUtils::AudioFile.

References mFileLayout.

◆ getComment()

AudioFileResultType EOUtils::SndFileBackedMetadataAudioFile::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.

◆ getGenre()

AudioFileResultType EOUtils::SndFileBackedMetadataAudioFile::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::SndFileBackedMetadataAudioFile::getHighestSampleValue_int64 ( std::int64_t & pHighestAudioSample)
override

◆ getNextSample_int64()

AudioFileResultType EOUtils::SndFileBackedMetadataAudioFile::getNextSample_int64 ( std::int64_t & pAudioSample)
override

◆ getTitle()

AudioFileResultType EOUtils::SndFileBackedMetadataAudioFile::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::SndFileBackedMetadataAudioFile::getTrackNumber ( std::uint32_t & pTrackNumber,
std::uint32_t & pTotalTracks ) const
override

◆ getYear()

AudioFileResultType EOUtils::SndFileBackedMetadataAudioFile::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::SndFileBackedMetadataAudioFile::goToAudioDataPos ( )
overridevirtual

Goes to the audio data position in the audio file.

Implements EOUtils::AudioFile.

References EOUtils::AudioFileResultType::addError(), formatLabel(), and EOUtils::AudioFile::mFilename.

Referenced by getHighestSampleValue_int64().

◆ isOpen()

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

Returns whether or not the audio file is open.

Reimplemented from EOUtils::AudioFile.

◆ maxValueForSampleSize()

std::int64_t EOUtils::SndFileBackedMetadataAudioFile::maxValueForSampleSize ( ) const
overridevirtual

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

Implements EOUtils::AudioFile.

References EOUtils::sndfile_detail::maxSampleValueForFormat(), and mFileLayout.

◆ newFileSfFormatMask()

virtual int EOUtils::SndFileBackedMetadataAudioFile::newFileSfFormatMask ( ) const
protectedpure virtual

Implemented in EOUtils::AiffFile, EOUtils::MP3File, and EOUtils::OggFile.

Referenced by open().

◆ numSamples()

std::size_t EOUtils::SndFileBackedMetadataAudioFile::numSamples ( ) const
overridevirtual

Returns the number of audio samples in the audio file.

Implements EOUtils::AudioFile.

References EOUtils::AudioFile::mDataSizeBytes, mFileLayout, and EOUtils::AudioFile::mFilename.

◆ open()

◆ readFormatMatches()

virtual bool EOUtils::SndFileBackedMetadataAudioFile::readFormatMatches ( int pSfFullFormat) const
protectedpure virtual

Implemented in EOUtils::AiffFile, EOUtils::MP3File, and EOUtils::OggFile.

Referenced by open().

◆ seekOutputToSampleNum()

void EOUtils::SndFileBackedMetadataAudioFile::seekOutputToSampleNum ( std::size_t pSampleNum)
override

◆ setAlbum()

AudioFileResultType EOUtils::SndFileBackedMetadataAudioFile::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::SndFileBackedMetadataAudioFile::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::SndFileBackedMetadataAudioFile::setAudioFileInfo ( const AudioFileInfo & pAudioFileInfo)
overridevirtual

◆ setComment()

AudioFileResultType EOUtils::SndFileBackedMetadataAudioFile::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::SndFileBackedMetadataAudioFile::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::SndFileBackedMetadataAudioFile::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::SndFileBackedMetadataAudioFile::setTrackNumber ( std::uint32_t pTrackNumber,
std::uint32_t pTotalTracks = 0 )
override

◆ setYear()

AudioFileResultType EOUtils::SndFileBackedMetadataAudioFile::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()

Member Data Documentation

◆ mFileLayout


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