Audio - Horizon-NTH/HorizonGUI GitHub Wiki

Audio

The Audio class in the hgui::kernel namespace is designed for handling audio data. It encapsulates audio information in the form of a structure (AudioData) and provides functions for retrieving audio data and information from a file. The class is defined in the header file Audio.h and utilizes the libsndfile library to handle audio files.

AudioData Structure

The AudioData structure represents essential information about audio, including the number of frames, sample rate, number of channels, audio format, and other properties.

  • sf_count_t frames: Number of frames in the audio.
  • int samplerate: Sample rate of the audio.
  • int channels: Number of channels in the audio.
  • int format: Format of the audio.
  • int sections: Number of sections in the audio.
  • int seekable: Indicates whether seeking is supported.

Constructors

  • AudioData(): Default constructor for the AudioData structure.

  • explicit AudioData(const SF_INFO& info): Constructs an AudioData object using information from an SF_INFO structure.

Audio Class

Constructors

  • explicit Audio(const std::string& filePath): Constructs an Audio object by specifying the path to the audio file.

Member Functions

  • const float* data() const: Retrieves a pointer to the audio data stored in the Audio object.

  • const AudioData& get_audio_data() const: Retrieves the audio data stored in the Audio object.

Example Usage

#include <hgui/header/Audio.h>

// Example Usage of Audio class
std::string audioPath = "path_to_audio.wav";
hgui::kernel::Audio audio(audioPath);

// Get the audio data
const AudioData& audioData = audio.get_audio_data();

// Access the audio data
const float* audioSamples = audio.data();

// Process or play the audio data

Note: In the "Example Usage" section, replace "path_to_audio.wav" with the actual path to the audio file you want to use.