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
Audio.h
Go to the documentation of this file.
1#pragma once
2#include "HephAudioShared.h"
6
9namespace HephAudio
10{
16 {
17 Default,
18#if defined(_WIN32)
19 WASAPI,
20 DirectSound,
21 MMEAPI,
22#elif defined(__APPLE__)
23 CoreAudio,
24#elif defined(__ANDROID__)
25#if __ANDROID_API__ >= HEPHAUDIO_ANDROID_AAUDIO_MIN_API_LEVEL
26 AAudio,
27#endif
28 OpenSLES,
29#elif defined(__linux__)
30 ALSA,
31#endif
32 };
33
38 class HEPH_API Audio final
39 {
40 private:
41 Native::NativeAudio* pNativeAudio;
42
43 public:
44 void SetOnAudioDeviceAddedHandler(Heph::EventHandler handler);
45 void AddOnAudioDeviceAddedHandler(Heph::EventHandler handler);
46 void SetOnAudioDeviceRemovedHandler(Heph::EventHandler handler);
47 void AddOnAudioDeviceRemovedHandler(Heph::EventHandler handler);
48 void SetOnCaptureHandler(Heph::EventHandler handler);
49 void AddOnCaptureHandler(Heph::EventHandler handler);
50
51 public:
54
61
62 Audio(const Audio&) = delete;
63 Audio& operator=(const Audio&) = delete;
64
67
73
75 std::shared_ptr<IAudioDecoder> GetAudioDecoder() const;
76
78 void SetAudioDecoder(std::shared_ptr<IAudioDecoder> pNewDecoder);
79
81 std::shared_ptr<IAudioEncoder> GetAudioEncoder() const;
82
84 void SetAudioEncoder(std::shared_ptr<IAudioEncoder> pNewEncoder);
85
87 AudioObject* Play(const std::filesystem::path& filePath);
88
90 AudioObject* Play(const std::filesystem::path& filePath, uint32_t playCount);
91
93 AudioObject* Play(const std::filesystem::path& filePath, uint32_t playCount, bool isPaused);
94
96 AudioObject* Load(const std::filesystem::path& filePath);
97
99 AudioObject* Load(const std::filesystem::path& filePath, uint32_t playCount);
100
102 AudioObject* Load(const std::filesystem::path& filePath, uint32_t playCount, bool isPaused);
103
105 AudioObject* CreateAudioObject(const std::string& name, size_t bufferFrameCount, AudioChannelLayout channelLayout, uint16_t sampleRate);
106
108 bool DestroyAudioObject(AudioObject* pAudioObject);
109
111 bool DestroyAudioObject(const Heph::Guid& audioObjectId);
112
114 bool AudioObjectExists(AudioObject* pAudioObject) const;
115
117 bool AudioObjectExists(const Heph::Guid& audioObjectId) const;
118
120 AudioObject* GetAudioObject(size_t index) const;
121
123 AudioObject* GetAudioObject(const Heph::Guid& audioObjectId);
124
126 AudioObject* GetAudioObject(const std::string& audioObjectName) const;
127
129 size_t GetAudioObjectCount() const;
130
133
136
138 bool IsCapturePaused() const;
139
142
144 void SetDeviceEnumerationPeriod(uint32_t deviceEnumerationPeriod_ms);
145
147 void SetMasterVolume(double volume);
148
150 double GetMasterVolume() const;
151
154
157
160
162 void InitializeRender(AudioChannelLayout channelLayout, uint32_t sampleRate);
163
166
169
172
175
177 void InitializeCapture(AudioChannelLayout channelLayout, uint32_t sampleRate);
178
181
184
187
190
193
195 AudioDevice GetAudioDeviceById(const std::string& deviceId) const;
196
199
202
205
207 std::vector<AudioDevice> GetAudioDevices(AudioDeviceType deviceType) const;
208 };
209}
AudioDeviceType
Definition AudioDevice.h:11
AudioAPI
available native audio APIs.
Definition Audio.h:16
#define HEPH_API
Definition HephShared.h:132
manages the native audio classes.
Definition Audio.h:39
AudioDevice GetDefaultAudioDevice(AudioDeviceType deviceType) const
const AudioFormatInfo & GetCaptureFormat() const
void SetNativeParams(const Native::NativeAudioParams &nativeParams)
bool DestroyAudioObject(AudioObject *pAudioObject)
void SetAudioEncoder(std::shared_ptr< IAudioEncoder > pNewEncoder)
bool IsCapturePaused() const
void InitializeRender()
std::shared_ptr< IAudioEncoder > GetAudioEncoder() const
AudioObject * Load(const std::filesystem::path &filePath, uint32_t playCount)
AudioObject * GetAudioObject(const Heph::Guid &audioObjectId)
AudioObject * CreateAudioObject(const std::string &name, size_t bufferFrameCount, AudioChannelLayout channelLayout, uint16_t sampleRate)
AudioObject * Play(const std::filesystem::path &filePath)
void InitializeRender(AudioDevice *device, AudioFormatInfo format)
bool AudioObjectExists(const Heph::Guid &audioObjectId) const
bool DestroyAudioObject(const Heph::Guid &audioObjectId)
std::shared_ptr< IAudioDecoder > GetAudioDecoder() const
void InitializeCapture(AudioChannelLayout channelLayout, uint32_t sampleRate)
void SetAudioDecoder(std::shared_ptr< IAudioDecoder > pNewDecoder)
AudioObject * Play(const std::filesystem::path &filePath, uint32_t playCount, bool isPaused)
AudioObject * Load(const std::filesystem::path &filePath)
size_t GetAudioObjectCount() const
AudioObject * GetAudioObject(const std::string &audioObjectName) const
Audio(AudioAPI api)
Native::NativeAudio * GetNativeAudio() const
AudioDevice GetAudioDeviceById(const std::string &deviceId) const
void GetNativeParams(Native::NativeAudioParams &nativeParams) const
double GetMasterVolume() const
const AudioFormatInfo & GetRenderFormat() const
void SetMasterVolume(double volume)
void InitializeCapture(AudioDevice *device, AudioFormatInfo format)
void InitializeRender(AudioFormatInfo format)
AudioDevice GetCaptureDevice() const
AudioDevice GetRenderDevice() const
void InitializeCapture(AudioFormatInfo format)
AudioObject * Load(const std::filesystem::path &filePath, uint32_t playCount, bool isPaused)
uint32_t GetDeviceEnumerationPeriod() const
bool AudioObjectExists(AudioObject *pAudioObject) const
AudioObject * GetAudioObject(size_t index) const
std::vector< AudioDevice > GetAudioDevices(AudioDeviceType deviceType) const
AudioObject * Play(const std::filesystem::path &filePath, uint32_t playCount)
void InitializeCapture()
void InitializeRender(AudioChannelLayout channelLayout, uint32_t sampleRate)
void SetDeviceEnumerationPeriod(uint32_t deviceEnumerationPeriod_ms)
base class for the classes that interact with the native audio APIs.
Definition NativeAudio.h:28
stores information about the channel layout.
Definition AudioChannelLayout.h:136
stores information about an audio device.
Definition AudioDevice.h:76
stores the properties of the audio signals
Definition AudioFormatInfo.h:20
stores information that's necessary to play audio.
Definition AudioObject.h:36
base class for storing the native audio API specific parameters.
Definition NativeAudioParams.h:15
struct for storing globally unique identifiers.
Definition Guid.h:14