SDL3pp
A slim C++ wrapper for SDL3
|
Handle to an owned audioDevice. More...
Public Member Functions | |
void | Close () |
Close a previously-opened audio device. | |
AudioDeviceShared | share () |
Move this audioDevice into a AudioDeviceShared. | |
constexpr | ResourceUnique (std::nullptr_t=nullptr) |
Default constructor. | |
constexpr | ResourceUnique (base::value_type value, DELETER deleter={}) |
Constructs from raw type. | |
constexpr | ResourceUnique (ResourceUnique &&other) |
Move constructor. | |
ResourceUnique (const ResourceUnique &other)=delete | |
![]() | |
constexpr | ResourceUnique (std::nullptr_t=nullptr) |
Default constructor. | |
constexpr | ResourceUnique (base::value_type value, DefaultDeleter< AudioDeviceRef > deleter={}) |
Constructs from raw type. | |
constexpr | ResourceUnique (ResourceUnique &&other) |
Move constructor. | |
ResourceUnique (const ResourceUnique &other)=delete | |
~ResourceUnique () | |
Destructor. | |
constexpr ResourceUnique & | operator= (ResourceUnique other) |
Assignment operator. | |
void | reset () |
Resets the value, destroying the resource if not nullptr. | |
![]() | |
RESOURCE | release () |
Returns reference and reset this. | |
![]() | |
constexpr | operator bool () const |
Check if not null. | |
constexpr bool | operator== (const ResourcePtrBase &other) const |
Comparison. | |
constexpr bool | operator== (std::nullptr_t) const |
Comparison. | |
constexpr bool | operator== (std::nullopt_t) const |
Comparison. | |
constexpr reference | operator* () const |
Gets reference. | |
constexpr const reference * | operator-> () const |
Gets addressable reference. | |
constexpr reference * | operator-> () |
Gets addressable reference. | |
reference | get () const |
Get reference. | |
Static Public Member Functions | |
static AudioDevice | Open (AudioDeviceRef devid, OptionalRef< const SDL_AudioSpec > spec) |
Open a specific audio device. | |
Additional Inherited Members | |
![]() | |
using | deleter = DELETER |
The deleter type. | |
![]() | |
using | reference = RESOURCE |
The reference resource type. | |
using | value_type = typename reference::value_type |
The raw resource type. | |
![]() | |
constexpr | ResourceOwnerBase (base::value_type value={}, DELETER deleter={}) |
Constructs from raw type. | |
void | free () |
Frees resource. | |
![]() | |
constexpr | ResourcePtrBase (value_type value={}) |
Constructs from raw type. | |
reference & | get () |
Get reference. | |
|
inline |
The application should close open audio devices once they are no longer needed.
This function may block briefly while pending audio data is played by the hardware, so that applications don't drop the last buffer of data they supplied if terminating immediately afterwards.
|
inlinestatic |
You can open both playback and recording devices through this function. Playback devices will take data from bound audio streams, mix it, and send it to the hardware. Recording devices will feed any bound audio streams with a copy of any incoming data.
An opened audio device starts out with no audio streams bound. To start audio playing, bind a stream and supply audio data to it. Unlike SDL2, there is no audio callback; you only bind audio streams and make sure they have data flowing into them (however, you can simulate SDL2's semantics fairly closely by using AudioStream.OpenAudioDeviceStream instead of this function).
If you don't care about opening a specific device, pass a devid
of either AUDIO_DEVICE_DEFAULT_PLAYBACK
or AUDIO_DEVICE_DEFAULT_RECORDING
. In this case, SDL will try to pick the most reasonable default, and may also switch between physical devices seamlessly later, if the most reasonable default changes during the lifetime of this opened device (user changed the default in the OS's system preferences, the default got unplugged so the system jumped to a new default, the user plugged in headphones on a mobile device, etc). Unless you have a good reason to choose a specific device, this is probably what you want.
You may request a specific format for the audio device, but there is no promise the device will honor that request for several reasons. As such, it's only meant to be a hint as to what data your app will provide. Audio streams will accept data in whatever format you specify and manage conversion for you as appropriate. AudioDeviceRef.GetFormat can tell you the preferred format for the device before opening and the actual format the device is using after opening.
It's legal to open the same device ID more than once; each successful open will generate a new logical AudioDevice that is managed separately from others on the same physical device. This allows libraries to open a device separately from the main app and bind its own streams without conflicting.
It is also legal to open a device ID returned by a previous call to this function; doing so just creates another logical device on the same physical device. This may be useful for making logical groupings of audio streams.
This function returns the opened device ID on success. This is a new, unique AudioDevice that represents a logical device.
Some backends might offer arbitrary devices (for example, a networked audio protocol that can connect to an arbitrary server). For these, as a change from SDL2, you should open a default device ID and use an SDL hint to specify the target if you care, or otherwise let the backend figure out a reasonable default. Most backends don't offer anything like this, and often this would be an end user setting an environment variable for their custom need, and not something an application should specifically manage.
When done with an audio device, possibly at the end of the app's life, one should call AudioDevice.Close() on the returned device id.
devid | the device instance id to open, or AUDIO_DEVICE_DEFAULT_PLAYBACK or AUDIO_DEVICE_DEFAULT_RECORDING for the most reasonable default device. |
spec | the requested device configuration. Can be nullptr to use reasonable defaults. |
Error | on failure. |