DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
Loading...
Searching...
No Matches
dspark::Mp3File Class Reference

#include <Mp3File.h>

Inheritance diagram for dspark::Mp3File:
Collaboration diagram for dspark::Mp3File:

Public Member Functions

 ~Mp3File () override
 
bool openRead (const std::filesystem::path &path) override
 Opens a file for reading.
 
bool openWrite (const std::filesystem::path &path, const AudioFileInfo &info) override
 Opens a file for writing, creating it or overwriting if it exists.
 
AudioFileInfo getInfo () const override
 Retrieves metadata of the currently opened file.
 
bool readSamples (AudioBufferView< float > dest) override
 Reads samples from the start of the file into the destination view.
 
bool readSamples (AudioBufferView< float > dest, int64_t startFrame, int64_t numFrames) override
 Reads a specific range of sample frames. Useful for chunked streaming.
 
bool writeSamples (AudioBufferView< const float > src) override
 Writes samples from the view to the file.
 
void close () override
 Finalizes file headers and releases system handles.
 
bool isOpen () const noexcept override
 Checks if a valid file handle is currently open.
 
- Public Member Functions inherited from dspark::AudioFile
virtual ~AudioFile ()=default
 

Detailed Description

Definition at line 56 of file Mp3File.h.

Constructor & Destructor Documentation

◆ ~Mp3File()

dspark::Mp3File::~Mp3File ( )
inlineoverride

Definition at line 59 of file Mp3File.h.

Member Function Documentation

◆ close()

void dspark::Mp3File::close ( )
inlineoverridevirtual

Finalizes file headers and releases system handles.

Safe to call multiple times. Implementations invoke this from their destructor, so an open file is always finalized; call it explicitly when you need the write error-checked (a destructor cannot report failure) or the file released before the object dies.

Implements dspark::AudioFile.

Definition at line 194 of file Mp3File.h.

◆ getInfo()

AudioFileInfo dspark::Mp3File::getInfo ( ) const
inlineoverridevirtual

Retrieves metadata of the currently opened file.

Returns
AudioFileInfo struct. Returns default values if no file is open.

Implements dspark::AudioFile.

Definition at line 141 of file Mp3File.h.

◆ isOpen()

bool dspark::Mp3File::isOpen ( ) const
inlineoverridevirtualnoexcept

Checks if a valid file handle is currently open.

Implements dspark::AudioFile.

Definition at line 217 of file Mp3File.h.

◆ openRead()

bool dspark::Mp3File::openRead ( const std::filesystem::path &  path)
inlineoverridevirtual

Opens a file for reading.

Any previously open file is closed first.

Parameters
pathFile path using C++20 std::filesystem (handles UTF-8/cross-platform safely).
Returns
True if opened and header parsed successfully. False otherwise.

Implements dspark::AudioFile.

Definition at line 63 of file Mp3File.h.

◆ openWrite()

bool dspark::Mp3File::openWrite ( const std::filesystem::path &  path,
const AudioFileInfo info 
)
inlineoverridevirtual

Opens a file for writing, creating it or overwriting if it exists.

Any previously open file is closed first.

Parameters
pathFile path.
infoDesired output format metadata.
Returns
True if created and header written successfully. False otherwise.

Implements dspark::AudioFile.

Definition at line 107 of file Mp3File.h.

◆ readSamples() [1/2]

bool dspark::Mp3File::readSamples ( AudioBufferView< float >  dest)
inlineoverridevirtual

Reads samples from the start of the file into the destination view.

Reads up to min(view length, file length) frames into up to min(view channels, file channels) channels. Excess buffer space and channels beyond those present in the file are left untouched.

Parameters
destBuffer view to receive the audio data.
Returns
True if read successfully. False if an I/O error occurred or no file is open for reading.

Implements dspark::AudioFile.

Definition at line 143 of file Mp3File.h.

◆ readSamples() [2/2]

bool dspark::Mp3File::readSamples ( AudioBufferView< float >  dest,
int64_t  startFrame,
int64_t  numFrames 
)
inlineoverridevirtual

Reads a specific range of sample frames. Useful for chunked streaming.

The requested range must lie entirely within the file (startFrame >= 0, numFrames > 0, startFrame + numFrames <= numSamples); out-of-range requests return false without reading. As with the full-file overload, the transfer is clamped to the view's capacity.

Parameters
destBuffer view to receive the audio data.
startFrameThe absolute frame index in the file to start reading from.
numFramesThe number of frames to read.
Returns
True if the range was read successfully.

Implements dspark::AudioFile.

Definition at line 148 of file Mp3File.h.

◆ writeSamples()

bool dspark::Mp3File::writeSamples ( AudioBufferView< const float >  src)
inlineoverridevirtual

Writes samples from the view to the file.

Converts float [-1.0, 1.0] back to the native bit-depth defined in openWrite(). May be called repeatedly to append blocks (streaming writes).

Parameters
srcBuffer view containing the data to write.
Returns
True on success, False if disk is full or an I/O error occurred.

Implements dspark::AudioFile.

Definition at line 169 of file Mp3File.h.


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