audio_file
Overview
audio_file
is a set of small and lightweight classes for reading and writing WAV (Waveform Audio File Format) files. It offers a straightforward and intuitive interface for working with WAV audio data. This includes:
wav_reader
-
For reading WAV files.
wav_writer
-
For writing WAV files.
wav_base
wav_base
is the base class with common functionalities for wav_reader
and wav_writer
.
Declaration
class wav_base
{
public:
wav_base();
wav_base(wav_base const&) = delete;
~wav_base();
wav_base& operator=(wav_base const&) = delete;
explicit operator bool() const;
std::size_t sps() const;
std::size_t num_channels() const;
};
wav_reader
wav_reader
is a class for reading WAV files with the typical read-only input mechanisms, such as incrementally reading a chunk of audio data from a position starting at the beginning of the file, and being able to move a certain position in the file.
Declaration
class wav_reader : public wav_base
{
public:
wav_reader(std::string filepath);
wav_reader(char const* filepath);
std::uint64_t length() const;
std::uint64_t position();
bool restart();
bool seek(std::uint64_t target);
std::size_t read(float* data, std::uint32_t len);
std::size_t read(concepts::IndexableContainer auto& buffer);
};
The IndexableContainer
concept is declared in Basic Concepts.
Expressions
wav_reader
is derived from wav_base
. In addition to valid expressions for wav_base
, wav_reader
allows these expressions.
Notation
r
-
Object of type
wav_reader
. f
-
Object of type convertible to
std::string
orchar const*
representing a file path. d
-
Pointer to a buffer of
float
elements with sizelen
. s
-
Size buffer of
d
. b
-
Object of type that conforms to the
IndexableContainer
concept. p
-
Position in the wav file (
std::uint64_t
).
Constructors and Assignment
Expression | Semantics |
---|---|
|
Construct a |
C++ brace initialization may also be used. |
Mutators
Expression | Semantics | Return Type |
---|---|---|
|
Reset the read position to the start.
Returns |
|
|
Set the read position to the |
|
|
Read a chunk of data given a raw
buffer, |
|
|
Read a chunk of data given a
buffer, |
|
wav_writer
wav_writer
is a class for writing WAV files with the typical write-only output mechanisms, such as incrementally writing a chunk of audio data from a position starting at the beginning of the file. wav_writer
writes WAV files with one or more channels and 32-bit floating point samples.
Declaration
class wav_writer : public wav_base
{
public:
wav_writer(
std::string filename
, std::uint32_t num_channels, float sps);
wav_writer(
char const* filename
, std::uint32_t num_channels, float sps);
std::size_t write(float const* data, std::uint32_t len);
std::size_t write(concepts::IndexableContainer auto const& buffer);
};
The IndexableContainer
concept is declared in Basic Concepts.
Expressions
wav_writer
is derived from wav_base
. In addition to valid expressions for wav_base
, wav_writer
allows these expressions.
Notation
w
-
Object of type
wav_writer
. f
-
Object of type convertible to
std::string
orchar const*
representing a file path. d
-
Pointer to a buffer of
float
elements with sizelen
. s
-
Size buffer of
d
. b
-
Object of type that conforms to the
IndexableContainer
concept. ch
-
Integer value representing number of channels.
sps
-
Floating point value representing samples per second.