HephAudio v3.0.6
A cross-platform C++ library for recording, playing, and processing audio on Windows, Android, Linux, iOS, and macOS.
|
base class for the classes that interact with the native audio APIs. More...
#include <NativeAudio.h>
Public Member Functions | |
NativeAudio () | |
NativeAudio (const NativeAudio &)=delete | |
NativeAudio & | operator= (const NativeAudio &)=delete |
virtual | ~NativeAudio ()=default |
std::shared_ptr< IAudioDecoder > | GetAudioDecoder () const |
void | SetAudioDecoder (std::shared_ptr< IAudioDecoder > pNewDecoder) |
std::shared_ptr< IAudioEncoder > | GetAudioEncoder () const |
void | SetAudioEncoder (std::shared_ptr< IAudioEncoder > pNewEncoder) |
AudioObject * | Play (const std::filesystem::path &filePath) |
AudioObject * | Play (const std::filesystem::path &filePath, uint32_t playCount) |
AudioObject * | Play (const std::filesystem::path &filePath, uint32_t playCount, bool isPaused) |
AudioObject * | Load (const std::filesystem::path &filePath) |
AudioObject * | Load (const std::filesystem::path &filePath, uint32_t playCount) |
AudioObject * | Load (const std::filesystem::path &filePath, uint32_t playCount, bool isPaused) |
AudioObject * | CreateAudioObject (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 |
AudioObject * | GetAudioObject (size_t index) |
AudioObject * | GetAudioObject (const Heph::Guid &audioObjectId) |
AudioObject * | GetAudioObject (const std::string &audioObjectName) |
size_t | GetAudioObjectCount () const |
void | ResumeCapture () |
void | PauseCapture () |
bool | IsCapturePaused () const |
uint32_t | GetDeviceEnumerationPeriod () const |
void | SetDeviceEnumerationPeriod (uint32_t deviceEnumerationPeriod_ms) |
virtual void | SetMasterVolume (double volume)=0 |
virtual double | GetMasterVolume () const =0 |
const AudioFormatInfo & | GetRenderFormat () const |
const AudioFormatInfo & | GetCaptureFormat () const |
void | InitializeRender () |
void | InitializeRender (AudioChannelLayout channelLayout, uint32_t sampleRate) |
void | InitializeRender (AudioFormatInfo format) |
virtual void | InitializeRender (AudioDevice *device, AudioFormatInfo format)=0 |
virtual void | StopRendering ()=0 |
void | InitializeCapture () |
void | InitializeCapture (AudioChannelLayout channelLayout, uint32_t sampleRate) |
void | InitializeCapture (AudioFormatInfo format) |
virtual void | InitializeCapture (AudioDevice *device, AudioFormatInfo format)=0 |
virtual void | StopCapturing ()=0 |
virtual void | GetNativeParams (NativeAudioParams &nativeParams) const =0 |
virtual void | SetNativeParams (const NativeAudioParams &nativeParams)=0 |
AudioDevice | GetAudioDeviceById (const std::string &deviceId) const |
AudioDevice | GetRenderDevice () const |
AudioDevice | GetCaptureDevice () const |
AudioDevice | GetDefaultAudioDevice (AudioDeviceType deviceType) const |
std::vector< AudioDevice > | GetAudioDevices (AudioDeviceType deviceType) const |
Public Attributes | |
Heph::Event | OnAudioDeviceAdded |
Heph::Event | OnAudioDeviceRemoved |
Heph::Event | OnCapture |
Protected Member Functions | |
virtual bool | EnumerateAudioDevices ()=0 |
virtual void | CheckAudioDevices () |
void | JoinRenderThread () |
void | JoinCaptureThread () |
void | JoinDeviceThread () |
EncodedAudioBuffer | Mix (uint32_t frameCount) |
size_t | GetAOCountToMix () const |
virtual double | GetFinalAOVolume (AudioObject *pAudioObject) const |
Protected Attributes | |
std::shared_ptr< IAudioDecoder > | pAudioDecoder |
std::shared_ptr< IAudioEncoder > | pAudioEncoder |
std::vector< AudioObject > | audioObjects |
std::vector< AudioDevice > | audioDevices |
std::thread::id | mainThreadId |
std::thread | renderThread |
std::thread | captureThread |
std::thread | deviceThread |
std::string | renderDeviceId |
std::string | captureDeviceId |
AudioFormatInfo | renderFormat |
AudioFormatInfo | captureFormat |
bool | disposing |
bool | isRenderInitialized |
bool | isCaptureInitialized |
bool | isCapturePaused |
uint32_t | deviceEnumerationPeriod_ms |
std::mutex | audioDevicesMutex |
std::recursive_mutex | audioObjectsMutex |
Static Protected Attributes | |
static constexpr bool | DEVICE_ENUMERATION_FAIL = false |
static constexpr bool | DEVICE_ENUMERATION_SUCCESS = true |
base class for the classes that interact with the native audio APIs.
HephAudio::Native::NativeAudio::NativeAudio | ( | ) |
creates a new instance and initializes it with default values.
|
virtualdefault |
releases the resources and destroys the instance.
std::shared_ptr< IAudioDecoder > HephAudio::Native::NativeAudio::GetAudioDecoder | ( | ) | const |
gets the shared pointer to the audio decoder instance.
void HephAudio::Native::NativeAudio::SetAudioDecoder | ( | std::shared_ptr< IAudioDecoder > | pNewDecoder | ) |
sets the decoder.
pNewDecoder | shared pointer to the new decoder. |
std::shared_ptr< IAudioEncoder > HephAudio::Native::NativeAudio::GetAudioEncoder | ( | ) | const |
gets the shared pointer to the audio encoder instance.
void HephAudio::Native::NativeAudio::SetAudioEncoder | ( | std::shared_ptr< IAudioEncoder > | pNewEncoder | ) |
sets the encoder.
pNewEncoder | shared pointer to the new encoder. |
AudioObject * HephAudio::Native::NativeAudio::Play | ( | const std::filesystem::path & | filePath | ) |
reads the file, then starts playing it.
filePath | path of the file which will be played. |
AudioObject * HephAudio::Native::NativeAudio::Play | ( | const std::filesystem::path & | filePath, |
uint32_t | playCount ) |
reads the file, then starts playing it.
filePath | path of the file which will be played. |
playCount | number of times the file will be played. |
AudioObject * HephAudio::Native::NativeAudio::Play | ( | const std::filesystem::path & | filePath, |
uint32_t | playCount, | ||
bool | isPaused ) |
reads the file, then starts playing it.
filePath | path of the file which will be played. |
playCount | number of times the file will be played. |
isPaused | indicates whether to start playing the audio data after reading it to memory. |
AudioObject * HephAudio::Native::NativeAudio::Load | ( | const std::filesystem::path & | filePath | ) |
reads the file and converts the audio data to the render format but does not start playing it.
filePath | path of the file which will be loaded. |
AudioObject * HephAudio::Native::NativeAudio::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.
filePath | path of the file which will be loaded. |
playCount | number of times the file will be played. |
AudioObject * HephAudio::Native::NativeAudio::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.
filePath | path of the file which will be loaded. |
playCount | number of times the file will be played. |
isPaused | indicates whether to start playing the audio data after loading it. |
AudioObject * HephAudio::Native::NativeAudio::CreateAudioObject | ( | const std::string & | name, |
size_t | bufferFrameCount, | ||
AudioChannelLayout | channelLayout, | ||
uint16_t | sampleRate ) |
creates an audio object with the provided buffer info.
name | name for the audio object. |
bufferFrameCount | number of frames the buffer will have. |
channelLayout | channel layout of the buffer. |
sampleRate | sample rate of the buffer. |
bool HephAudio::Native::NativeAudio::DestroyAudioObject | ( | AudioObject * | pAudioObject | ) |
destroys the audio object.
pAudioObject | pointer to the object which will be destroyed. |
bool HephAudio::Native::NativeAudio::DestroyAudioObject | ( | const Heph::Guid & | audioObjectId | ) |
destroys the audio object.
audioObjectId | unique identifier of the object which will be destroyed. |
bool HephAudio::Native::NativeAudio::AudioObjectExists | ( | AudioObject * | pAudioObject | ) | const |
checks whether an audio object exists.
pAudioObject | pointer to the object which will checked. |
bool HephAudio::Native::NativeAudio::AudioObjectExists | ( | const Heph::Guid & | audioObjectId | ) | const |
checks whether an audio object exists.
audioObjectId | unique identifier of the object which will be checked. |
AudioObject * HephAudio::Native::NativeAudio::GetAudioObject | ( | size_t | index | ) |
gets the audio object.
index | index of the audio object. |
AudioObject * HephAudio::Native::NativeAudio::GetAudioObject | ( | const Heph::Guid & | audioObjectId | ) |
gets the audio object.
audioObjectId | unique identifier of the audio object. |
AudioObject * HephAudio::Native::NativeAudio::GetAudioObject | ( | const std::string & | audioObjectName | ) |
gets the first audio object with the provided name.
audioObjectName | name of the audio object. |
size_t HephAudio::Native::NativeAudio::GetAudioObjectCount | ( | ) | const |
gets the number of audio objects currently present.
void HephAudio::Native::NativeAudio::ResumeCapture | ( | ) |
resumes capturing.
void HephAudio::Native::NativeAudio::PauseCapture | ( | ) |
pauses capturing.
bool HephAudio::Native::NativeAudio::IsCapturePaused | ( | ) | const |
checks whether the capturing is paused.
uint32_t HephAudio::Native::NativeAudio::GetDeviceEnumerationPeriod | ( | ) | const |
gets the device enumeration period.
void HephAudio::Native::NativeAudio::SetDeviceEnumerationPeriod | ( | uint32_t | deviceEnumerationPeriod_ms | ) |
sets the device enumeration period.
|
pure virtual |
sets the master volume.
volume | new master volume. |
Implemented in HephAudio::Native::AndroidAudioA, HephAudio::Native::AndroidAudioSLES, HephAudio::Native::AppleAudio, HephAudio::Native::WinAudio, HephAudio::Native::WinAudioDS, and HephAudio::Native::WinAudioMME.
|
pure virtual |
gets the master volume.
Implemented in HephAudio::Native::AndroidAudioA, HephAudio::Native::AndroidAudioSLES, HephAudio::Native::AppleAudio, HephAudio::Native::WinAudio, HephAudio::Native::WinAudioDS, and HephAudio::Native::WinAudioMME.
const AudioFormatInfo & HephAudio::Native::NativeAudio::GetRenderFormat | ( | ) | const |
gets the audio format used for rendering.
const AudioFormatInfo & HephAudio::Native::NativeAudio::GetCaptureFormat | ( | ) | const |
gets the audio format used for capturing.
void HephAudio::Native::NativeAudio::InitializeRender | ( | ) |
initializes rendering with the default device and default format.
void HephAudio::Native::NativeAudio::InitializeRender | ( | AudioChannelLayout | channelLayout, |
uint32_t | sampleRate ) |
initializes rendering with the default device and the provided format.
channelLayout | channel layout of the render format. |
sampleRate | sample rate of the render format. |
void HephAudio::Native::NativeAudio::InitializeRender | ( | AudioFormatInfo | format | ) |
initializes rendering with the default device and the provided format.
format | render format. |
|
pure virtual |
initializes rendering with the provided device and the provided format.
device | pointer to the audio render device. |
format | render format. |
Implemented in HephAudio::Native::AndroidAudioA, HephAudio::Native::AndroidAudioSLES, HephAudio::Native::AppleAudio, HephAudio::Native::WinAudio, HephAudio::Native::WinAudioDS, and HephAudio::Native::WinAudioMME.
|
pure virtual |
stops rendering and releases the resources allocated for it.
Implemented in HephAudio::Native::AndroidAudioA, HephAudio::Native::AndroidAudioSLES, HephAudio::Native::AppleAudio, HephAudio::Native::WinAudio, HephAudio::Native::WinAudioDS, and HephAudio::Native::WinAudioMME.
void HephAudio::Native::NativeAudio::InitializeCapture | ( | ) |
initializes capturing with the default device and default format.
void HephAudio::Native::NativeAudio::InitializeCapture | ( | AudioChannelLayout | channelLayout, |
uint32_t | sampleRate ) |
initializes capturing with the default device and the provided format.
channelLayout | channel layout of the capture format. |
sampleRate | sample rate of the capture format. |
void HephAudio::Native::NativeAudio::InitializeCapture | ( | AudioFormatInfo | format | ) |
initializes capturing with the default device and the provided format.
format | capture format. |
|
pure virtual |
initializes capturing with the provided device and the provided format.
device | pointer to the audio capture device. |
format | capture format. |
Implemented in HephAudio::Native::AndroidAudioA, HephAudio::Native::AndroidAudioSLES, HephAudio::Native::AppleAudio, HephAudio::Native::WinAudio, HephAudio::Native::WinAudioDS, and HephAudio::Native::WinAudioMME.
|
pure virtual |
stops capturing and releases the resources allocated for it.
Implemented in HephAudio::Native::AndroidAudioA, HephAudio::Native::AndroidAudioSLES, HephAudio::Native::AppleAudio, HephAudio::Native::WinAudio, HephAudio::Native::WinAudioDS, and HephAudio::Native::WinAudioMME.
|
pure virtual |
gets the native API specific parameters.
Implemented in HephAudio::Native::AndroidAudioA, HephAudio::Native::AndroidAudioSLES, HephAudio::Native::AppleAudio, HephAudio::Native::WinAudio, HephAudio::Native::WinAudioDS, and HephAudio::Native::WinAudioMME.
|
pure virtual |
sets the native API specific parameters.
Implemented in HephAudio::Native::AndroidAudioA, HephAudio::Native::AndroidAudioSLES, HephAudio::Native::AppleAudio, HephAudio::Native::WinAudio, HephAudio::Native::WinAudioDS, and HephAudio::Native::WinAudioMME.
AudioDevice HephAudio::Native::NativeAudio::GetAudioDeviceById | ( | const std::string & | deviceId | ) | const |
gets audio device by id.
AudioDevice HephAudio::Native::NativeAudio::GetRenderDevice | ( | ) | const |
gets the audio device that's currently being used for rendering.
AudioDevice HephAudio::Native::NativeAudio::GetCaptureDevice | ( | ) | const |
gets the audio device that's currently being used for capturing.
AudioDevice HephAudio::Native::NativeAudio::GetDefaultAudioDevice | ( | AudioDeviceType | deviceType | ) | const |
gets the system default render/capture device.
deviceType | type of the device. Must be either AudioDeviceType::Render or AudioDeviceType::Capture . |
std::vector< AudioDevice > HephAudio::Native::NativeAudio::GetAudioDevices | ( | AudioDeviceType | deviceType | ) | const |
gets the available audio devices of the requested type.
deviceType | type of the audio devices. |
|
protectedpure virtual |
enumerates the audio devices.
Implemented in HephAudio::Native::AndroidAudioBase.
|
protectedvirtual |
enumerates audio devices periodically.
|
protected |
waits for render thread to join.
|
protected |
waits for capture thread to join.
|
protected |
waits for device thread to join.
|
protected |
mixes the audio objects that are currently playing into one buffer.
frameCount | number of frames the output buffer will have. |
|
protected |
gets the number of audio objects that will are currently playing.
|
protectedvirtual |
calculates the volume of the audio object.
|
staticconstexprprotected |
indicates the device enumeration has failed.
|
staticconstexprprotected |
indicates the device enumeration has succeeded.
|
protected |
shared pointer to the decoder instance that's used internally.
|
protected |
shared pointer to the encoder instance that's used internally.
|
protected |
a list of audio objects.
|
protected |
a list of audio devices present in the system.
|
protected |
unique identifier of the thread that created the current isntance.
|
protected |
the thread that's used for rendering audio data.
|
protected |
the thread that's used for capturing audio data.
|
protected |
the thread that's used for enumerating audio devices periodically.
|
protected |
unique identifier of the audio device that's currently being used for rendering.
|
protected |
unique identifier of the audio device that's currently being used for capturing.
|
protected |
render format.
|
protected |
capture format.
|
protected |
indicates whether the current instance is being destroyed.
|
protected |
indicates whether the current instance is ready for rendering.
|
protected |
indicates whether the current instance is ready for capturing.
|
protected |
indicates whether the capture is paused.
|
protected |
time, in milliseconds, between each device enumeration.
|
mutableprotected |
to prevent race condition when accessing/enumerating audio devices.
|
mutableprotected |
to prevent race condition when creating/accessing audio objects.
Heph::Event HephAudio::Native::NativeAudio::OnAudioDeviceAdded |
raised when an audio device is connected to the device or activated.
Heph::Event HephAudio::Native::NativeAudio::OnAudioDeviceRemoved |
raised when an audio device is disconnected from the device or deactivated.
Heph::Event HephAudio::Native::NativeAudio::OnCapture |
raised when sufficient amount (typically 10 ms) audio data is captured.