NSUNI/NSLAR Library a250670
Loading...
Searching...
No Matches
Simple Audio

Provides data structures for representing essential components of audio data. More...

Classes

struct  nnl::SAudio
 Represents a simple audio asset. More...

Detailed Description

Provides data structures for representing essential components of audio data.

This file defines the essential components of audio data. These structures facilitate the conversion of audio data between various common formats (such as WAV or MP3) and in-game formats.

See also
nnl::SAudio

Class Documentation

◆ nnl::SAudio

struct nnl::SAudio

Represents a simple audio asset.

This structure serves as intermediary representation of audio data. It facilitate the conversion of audio data between various common formats (such as WAV or MP3) and in-game formats.

See also
nnl::adpcm::Encode
nnl::adpcm::Decode
nnl::SAudio::Import
nnl::SAudio::ExportWAV

Public Member Functions

void ExportWAV (const std::filesystem::path &path) const
 Exports the audio data to a WAV file.
Buffer ExportWAV () const
 Exports the audio data to a WAV file.
void ToMono ()
 Converts stereo audio to mono.

Static Public Member Functions

static SAudio Import (const std::filesystem::path &path)
 Constructs an audio asset from a WAV file located at the specified file path.
static SAudio Import (BufferView buffer)
 Constructs an audio asset from a WAV file in the buffer.

Public Attributes

std::string name
 An optional name of the audio asset.
u32 sample_rate = 0
 The sample rate of the audio (per second)
u16 num_channels = 1
 The number of audio channels (1 for mono, 2 for stereo).
std::vector< i16pcm
 The PCM audio data stored as 16-bit samples.

Member Function Documentation

◆ ExportWAV() [1/2]

Buffer nnl::SAudio::ExportWAV ( ) const
nodiscard

Exports the audio data to a WAV file.

This method saves the audio asset in the WAV format to a buffer.

◆ ExportWAV() [2/2]

void nnl::SAudio::ExportWAV ( const std::filesystem::path & path) const

Exports the audio data to a WAV file.

This method saves the audio asset to the given file path in the WAV format.

Parameters
pathThe file path where the audio asset will be exported.

◆ Import() [1/2]

SAudio nnl::SAudio::Import ( BufferView buffer)
staticnodiscard

Constructs an audio asset from a WAV file in the buffer.

This method loads audio data from a WAV file in the buffer.

Parameters
bufferThe buffer containing a WAV file.

◆ Import() [2/2]

SAudio nnl::SAudio::Import ( const std::filesystem::path & path)
staticnodiscard

Constructs an audio asset from a WAV file located at the specified file path.

This method loads audio data from a WAV file located at the given path.

Parameters
pathThe file path to the WAV file.

◆ ToMono()

void nnl::SAudio::ToMono ( )

Converts stereo audio to mono.

This method combines 2 channels into 1.

Member Data Documentation

◆ name

std::string nnl::SAudio::name

An optional name of the audio asset.

◆ num_channels

u16 nnl::SAudio::num_channels = 1

The number of audio channels (1 for mono, 2 for stereo).

◆ pcm

std::vector<i16> nnl::SAudio::pcm

The PCM audio data stored as 16-bit samples.

◆ sample_rate

u32 nnl::SAudio::sample_rate = 0

The sample rate of the audio (per second)