HephAudio v3.0.6
A cross-platform C++ library for recording, playing, and processing audio on Windows, Android, Linux, iOS, and macOS.
Loading...
Searching...
No Matches
HephAudio::Audio Class Referencefinal

manages the native audio classes. More...

#include <Audio.h>

Public Member Functions

void SetOnAudioDeviceAddedHandler (Heph::EventHandler handler)
 
void AddOnAudioDeviceAddedHandler (Heph::EventHandler handler)
 
void SetOnAudioDeviceRemovedHandler (Heph::EventHandler handler)
 
void AddOnAudioDeviceRemovedHandler (Heph::EventHandler handler)
 
void SetOnCaptureHandler (Heph::EventHandler handler)
 
void AddOnCaptureHandler (Heph::EventHandler handler)
 
 Audio ()
 
 Audio (AudioAPI api)
 
 Audio (const Audio &)=delete
 
Audiooperator= (const Audio &)=delete
 
 ~Audio ()
 
Native::NativeAudioGetNativeAudio () const
 
std::shared_ptr< IAudioDecoderGetAudioDecoder () const
 
void SetAudioDecoder (std::shared_ptr< IAudioDecoder > pNewDecoder)
 
std::shared_ptr< IAudioEncoderGetAudioEncoder () const
 
void SetAudioEncoder (std::shared_ptr< IAudioEncoder > pNewEncoder)
 
AudioObjectPlay (const std::filesystem::path &filePath)
 
AudioObjectPlay (const std::filesystem::path &filePath, uint32_t playCount)
 
AudioObjectPlay (const std::filesystem::path &filePath, uint32_t playCount, bool isPaused)
 
AudioObjectLoad (const std::filesystem::path &filePath)
 
AudioObjectLoad (const std::filesystem::path &filePath, uint32_t playCount)
 
AudioObjectLoad (const std::filesystem::path &filePath, uint32_t playCount, bool isPaused)
 
AudioObjectCreateAudioObject (const std::string &name, size_t bufferFrameCount, AudioChannelLayout channelLayout, uint16_t sampleRate)
 
bool DestroyAudioObject (AudioObject *pAudioObject)
 
bool DestroyAudioObject (const Heph::Guid &audioObjectId)
 
bool AudioObjectExists (AudioObject *pAudioObject) const
 
bool AudioObjectExists (const Heph::Guid &audioObjectId) const
 
AudioObjectGetAudioObject (size_t index) const
 
AudioObjectGetAudioObject (const Heph::Guid &audioObjectId)
 
AudioObjectGetAudioObject (const std::string &audioObjectName) const
 
size_t GetAudioObjectCount () const
 
void ResumeCapture ()
 
void PauseCapture ()
 
bool IsCapturePaused () const
 
uint32_t GetDeviceEnumerationPeriod () const
 
void SetDeviceEnumerationPeriod (uint32_t deviceEnumerationPeriod_ms)
 
void SetMasterVolume (double volume)
 
double GetMasterVolume () const
 
const AudioFormatInfoGetRenderFormat () const
 
const AudioFormatInfoGetCaptureFormat () const
 
void InitializeRender ()
 
void InitializeRender (AudioChannelLayout channelLayout, uint32_t sampleRate)
 
void InitializeRender (AudioFormatInfo format)
 
void InitializeRender (AudioDevice *device, AudioFormatInfo format)
 
void StopRendering ()
 
void InitializeCapture ()
 
void InitializeCapture (AudioChannelLayout channelLayout, uint32_t sampleRate)
 
void InitializeCapture (AudioFormatInfo format)
 
void InitializeCapture (AudioDevice *device, AudioFormatInfo format)
 
void StopCapturing ()
 
void GetNativeParams (Native::NativeAudioParams &nativeParams) const
 
void SetNativeParams (const Native::NativeAudioParams &nativeParams)
 
AudioDevice GetAudioDeviceById (const std::string &deviceId) const
 
AudioDevice GetRenderDevice () const
 
AudioDevice GetCaptureDevice () const
 
AudioDevice GetDefaultAudioDevice (AudioDeviceType deviceType) const
 
std::vector< AudioDeviceGetAudioDevices (AudioDeviceType deviceType) const
 

Detailed Description

manages the native audio classes.

Constructor & Destructor Documentation

◆ Audio() [1/2]

HephAudio::Audio::Audio ( )

creates a new instance and initializes it with default values.

◆ Audio() [2/2]

HephAudio::Audio::Audio ( AudioAPI api)

creates a new instance and initializes it with the provided values.

Parameters
apithe native audio API that will be used.

◆ ~Audio()

HephAudio::Audio::~Audio ( )

releases the resources and destroys the instance.

Member Function Documentation

◆ GetNativeAudio()

Native::NativeAudio * HephAudio::Audio::GetNativeAudio ( ) const

gets the pointer to the native audio instance that's internally used.

◆ GetAudioDecoder()

std::shared_ptr< IAudioDecoder > HephAudio::Audio::GetAudioDecoder ( ) const

gets the shared pointer to the audio decoder instance.

◆ SetAudioDecoder()

void HephAudio::Audio::SetAudioDecoder ( std::shared_ptr< IAudioDecoder > pNewDecoder)

sets the decoder.

Parameters
pNewDecodershared pointer to the new decoder.

◆ GetAudioEncoder()

std::shared_ptr< IAudioEncoder > HephAudio::Audio::GetAudioEncoder ( ) const

gets the shared pointer to the audio encoder instance.

◆ SetAudioEncoder()

void HephAudio::Audio::SetAudioEncoder ( std::shared_ptr< IAudioEncoder > pNewEncoder)

sets the encoder.

Parameters
pNewEncodershared pointer to the new encoder.

◆ Play() [1/3]

AudioObject * HephAudio::Audio::Play ( const std::filesystem::path & filePath)

reads the file, then starts playing it.

Parameters
filePathpath of the file which will be played.
Returns
pointer to the audio object instance.

◆ Play() [2/3]

AudioObject * HephAudio::Audio::Play ( const std::filesystem::path & filePath,
uint32_t playCount )

reads the file, then starts playing it.

Parameters
filePathpath of the file which will be played.
playCountnumber of times the file will be played.
Returns
pointer to the audio object instance.

◆ Play() [3/3]

AudioObject * HephAudio::Audio::Play ( const std::filesystem::path & filePath,
uint32_t playCount,
bool isPaused )

reads the file, then starts playing it.

Parameters
filePathpath of the file which will be played.
playCountnumber of times the file will be played.
isPausedindicates whether to start playing the audio data after reading it to memory.
Returns
pointer to the audio object instance.

◆ Load() [1/3]

AudioObject * HephAudio::Audio::Load ( const std::filesystem::path & filePath)

reads the file and converts the audio data to the render format but does not start playing it.

Parameters
filePathpath of the file which will be loaded.
Returns
pointer to the audio object instance.

◆ Load() [2/3]

AudioObject * HephAudio::Audio::Load ( const std::filesystem::path & filePath,
uint32_t playCount )

reads the file and converts the audio data to the render format but does not start playing it.

Parameters
filePathpath of the file which will be loaded.
playCountnumber of times the file will be played.
Returns
pointer to the audio object instance.

◆ Load() [3/3]

AudioObject * HephAudio::Audio::Load ( const std::filesystem::path & filePath,
uint32_t playCount,
bool isPaused )

reads the file and converts the audio data to the render format but does not start playing it.

Parameters
filePathpath of the file which will be loaded.
playCountnumber of times the file will be played.
isPausedindicates whether to start playing the audio data after loading it.
Returns
pointer to the audio object instance.

◆ CreateAudioObject()

AudioObject * HephAudio::Audio::CreateAudioObject ( const std::string & name,
size_t bufferFrameCount,
AudioChannelLayout channelLayout,
uint16_t sampleRate )

creates an audio object with the provided buffer info.

Parameters
namename for the audio object.
bufferFrameCountnumber of frames the buffer will have.
channelLayoutchannel layout of the buffer.
sampleRatesample rate of the buffer.
Returns
pointer to the audio object instance.

◆ DestroyAudioObject() [1/2]

bool HephAudio::Audio::DestroyAudioObject ( AudioObject * pAudioObject)

destroys the audio object.

Parameters
pAudioObjectpointer to the object which will be destroyed.
Returns
true if the object is found and destroyed, otherwise false.

◆ DestroyAudioObject() [2/2]

bool HephAudio::Audio::DestroyAudioObject ( const Heph::Guid & audioObjectId)

destroys the audio object.

Parameters
audioObjectIdunique identifier of the object which will be destroyed.
Returns
true if the object is found and destroyed, otherwise false.

◆ AudioObjectExists() [1/2]

bool HephAudio::Audio::AudioObjectExists ( AudioObject * pAudioObject) const

◆ AudioObjectExists() [2/2]

bool HephAudio::Audio::AudioObjectExists ( const Heph::Guid & audioObjectId) const

◆ GetAudioObject() [1/3]

AudioObject * HephAudio::Audio::GetAudioObject ( size_t index) const

gets the audio object.

Parameters
indexindex of the audio object.
Returns
pointer to the audio object if found, otherwise nullptr.

◆ GetAudioObject() [2/3]

AudioObject * HephAudio::Audio::GetAudioObject ( const Heph::Guid & audioObjectId)

gets the audio object.

Parameters
audioObjectIdunique identifier of the audio object.
Returns
pointer to the audio object if found, otherwise nullptr.

◆ GetAudioObject() [3/3]

AudioObject * HephAudio::Audio::GetAudioObject ( const std::string & audioObjectName) const

gets the first audio object with the provided name.

Parameters
audioObjectNamename of the audio object.
Returns
pointer to the audio object if found, otherwise nullptr.

◆ GetAudioObjectCount()

size_t HephAudio::Audio::GetAudioObjectCount ( ) const

gets the number of audio objects currently present.

◆ ResumeCapture()

void HephAudio::Audio::ResumeCapture ( )

resumes capturing.

◆ PauseCapture()

void HephAudio::Audio::PauseCapture ( )

pauses capturing.

◆ IsCapturePaused()

bool HephAudio::Audio::IsCapturePaused ( ) const

checks whether the capturing is paused.

Returns
true if paused capturing, otherwise false.

◆ GetDeviceEnumerationPeriod()

uint32_t HephAudio::Audio::GetDeviceEnumerationPeriod ( ) const

◆ SetDeviceEnumerationPeriod()

void HephAudio::Audio::SetDeviceEnumerationPeriod ( uint32_t deviceEnumerationPeriod_ms)

◆ SetMasterVolume()

void HephAudio::Audio::SetMasterVolume ( double volume)

sets the master volume.

Parameters
volumenew master volume.
Important
values above 1 may cause distortion.

◆ GetMasterVolume()

double HephAudio::Audio::GetMasterVolume ( ) const

gets the master volume.

◆ GetRenderFormat()

const AudioFormatInfo & HephAudio::Audio::GetRenderFormat ( ) const

gets the audio format used for rendering.

◆ GetCaptureFormat()

const AudioFormatInfo & HephAudio::Audio::GetCaptureFormat ( ) const

gets the audio format used for capturing.

◆ InitializeRender() [1/4]

void HephAudio::Audio::InitializeRender ( )

initializes rendering with the default device and default format.

◆ InitializeRender() [2/4]

void HephAudio::Audio::InitializeRender ( AudioChannelLayout channelLayout,
uint32_t sampleRate )

initializes rendering with the default device and the provided format.

Parameters
channelLayoutchannel layout of the render format.
sampleRatesample rate of the render format.

◆ InitializeRender() [3/4]

void HephAudio::Audio::InitializeRender ( AudioFormatInfo format)

initializes rendering with the default device and the provided format.

Parameters
formatrender format.

◆ InitializeRender() [4/4]

void HephAudio::Audio::InitializeRender ( AudioDevice * device,
AudioFormatInfo format )

initializes rendering with the provided device and the provided format.

Parameters
devicepointer to the audio render device.
formatrender format.

◆ StopRendering()

void HephAudio::Audio::StopRendering ( )

stops rendering and releases the resources allocated for it.

◆ InitializeCapture() [1/4]

void HephAudio::Audio::InitializeCapture ( )

initializes capturing with the default device and default format.

◆ InitializeCapture() [2/4]

void HephAudio::Audio::InitializeCapture ( AudioChannelLayout channelLayout,
uint32_t sampleRate )

initializes capturing with the default device and the provided format.

Parameters
channelLayoutchannel layout of the capture format.
sampleRatesample rate of the capture format.

◆ InitializeCapture() [3/4]

void HephAudio::Audio::InitializeCapture ( AudioFormatInfo format)

initializes capturing with the default device and the provided format.

Parameters
formatcapture format.

◆ InitializeCapture() [4/4]

void HephAudio::Audio::InitializeCapture ( AudioDevice * device,
AudioFormatInfo format )

initializes capturing with the provided device and the provided format.

Parameters
devicepointer to the audio capture device.
formatcapture format.

◆ StopCapturing()

void HephAudio::Audio::StopCapturing ( )

stops capturing and releases the resources allocated for it.

◆ GetNativeParams()

void HephAudio::Audio::GetNativeParams ( Native::NativeAudioParams & nativeParams) const

gets the native API specific parameters.

◆ SetNativeParams()

void HephAudio::Audio::SetNativeParams ( const Native::NativeAudioParams & nativeParams)

sets the native API specific parameters.

◆ GetAudioDeviceById()

AudioDevice HephAudio::Audio::GetAudioDeviceById ( const std::string & deviceId) const

gets audio device by id.

◆ GetRenderDevice()

AudioDevice HephAudio::Audio::GetRenderDevice ( ) const

gets the audio device that's currently being used for rendering.

◆ GetCaptureDevice()

AudioDevice HephAudio::Audio::GetCaptureDevice ( ) const

gets the audio device that's currently being used for capturing.

◆ GetDefaultAudioDevice()

AudioDevice HephAudio::Audio::GetDefaultAudioDevice ( AudioDeviceType deviceType) const

gets the system default render/capture device.

Parameters
deviceTypetype of the device. Must be either AudioDeviceType::Render or AudioDeviceType::Capture .
Returns
AudioDevice

◆ GetAudioDevices()

std::vector< AudioDevice > HephAudio::Audio::GetAudioDevices ( AudioDeviceType deviceType) const

gets the available audio devices of the requested type.

Parameters
deviceTypetype of the audio devices.