SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
Public Member Functions | List of all members
SDL::AudioStreamRef Struct Reference

Handle to a non owned audioStream. More...

Inheritance diagram for SDL::AudioStreamRef:
Inheritance graph
[legend]

Public Member Functions

constexpr AudioStreamRef (const AudioStreamRef &other)
 Copy constructor.
 
constexpr AudioStreamRef (AudioStreamRef &&other)
 Move constructor.
 
constexpr ~AudioStreamRef ()=default
 Default constructor.
 
AudioStreamRefoperator= (AudioStreamRef other)
 Assignment operator.
 
void reset (SDL_AudioStream *newResource={})
 Free an audio stream.
 
 AudioStreamBase (OptionalRef< const AudioSpec > src_spec, OptionalRef< const AudioSpec > dst_spec)
 Create a new audio stream.
 
 AudioStreamBase (const AudioDeviceBase &devid, OptionalRef< const AudioSpec > spec=std::nullopt, AudioStreamCallback callback=nullptr, void *userdata=nullptr)
 Convenience function for straightforward audio init for the common case.
 
 AudioStreamBase (const AudioDeviceBase &devid, OptionalRef< const AudioSpec > spec, AudioStreamCB callback)
 Convenience function for straightforward audio init for the common case.
 
- Public Member Functions inherited from SDL::AudioStreamBase
 AudioStreamBase (OptionalRef< const AudioSpec > src_spec, OptionalRef< const AudioSpec > dst_spec)
 Create a new audio stream.
 
 AudioStreamBase (const AudioDeviceBase &devid, OptionalRef< const AudioSpec > spec=std::nullopt, AudioStreamCallback callback=nullptr, void *userdata=nullptr)
 Convenience function for straightforward audio init for the common case.
 
 AudioStreamBase (const AudioDeviceBase &devid, OptionalRef< const AudioSpec > spec, AudioStreamCB callback)
 Convenience function for straightforward audio init for the common case.
 
PropertiesRef GetProperties () const
 Get the properties associated with an audio stream.
 
AudioSpec GetInputFormat () const
 Query the current input format of an audio stream.
 
AudioSpec GetOutputFormat () const
 Query the current output format of an audio stream.
 
void GetFormat (AudioSpec *src_spec, AudioSpec *dst_spec) const
 Query the current format of an audio stream.
 
void SetInputFormat (const AudioSpec &spec)
 Change the input format of an audio stream.
 
void SetOutputFormat (const AudioSpec &spec)
 Change the output format of an audio stream.
 
void SetFormat (OptionalRef< const AudioSpec > src_spec, OptionalRef< const AudioSpec > dst_spec)
 Change the input and output formats of an audio stream.
 
float GetFrequencyRatio () const
 Get the frequency ratio of an audio stream.
 
void SetFrequencyRatio (float ratio)
 Change the frequency ratio of an audio stream.
 
float GetGain () const
 Get the gain of an audio stream.
 
void SetGain (float gain)
 Change the gain of an audio stream.
 
OwnArray< int > GetInputChannelMap () const
 Get the current input channel map of an audio stream.
 
OwnArray< int > GetOutputChannelMap () const
 Get the current output channel map of an audio stream.
 
void SetInputChannelMap (std::span< int > chmap)
 Set the current input channel map of an audio stream.
 
void SetOutputChannelMap (std::span< int > chmap)
 Set the current output channel map of an audio stream.
 
void PutData (SourceBytes buf)
 Add data to the stream.
 
int GetData (TargetBytes buf)
 Get converted/resampled data from the stream.
 
int GetAvailable () const
 Get the number of converted/resampled bytes available.
 
int GetQueued () const
 Get the number of bytes currently queued.
 
void Flush ()
 Tell the stream that you're done sending data, and anything being buffered should be converted/resampled and made available immediately.
 
void Clear ()
 Clear any pending data in the stream.
 
void PauseDevice ()
 Use this function to pause audio playback on the audio device associated with an audio stream.
 
void ResumeDevice ()
 Use this function to unpause audio playback on the audio device associated with an audio stream.
 
bool DevicePaused () const
 Use this function to query if an audio device associated with a stream is paused.
 
AudioStreamLock Lock ()
 Lock an audio stream for serialized access.
 
void SetGetCallback (AudioStreamCB callback)
 Set a callback that runs when data is requested from an audio stream.
 
void SetGetCallback (AudioStreamCallback callback, void *userdata)
 Set a callback that runs when data is requested from an audio stream.
 
void SetPutCallback (AudioStreamCB callback)
 Set a callback that runs when data is added to an audio stream.
 
void SetPutCallback (AudioStreamCallback callback, void *userdata)
 Set a callback that runs when data is added to an audio stream.
 
void Bind (AudioDeviceBase &devid)
 Bind a single audio stream to an audio device.
 
void Unbind ()
 Unbind a single audio stream from its audio device.
 
AudioDeviceRef GetDevice () const
 Query an audio stream for its currently-bound device.
 
constexpr Resource (T resource={})
 Constructs the underlying resource.
 
constexpr Resource (std::nullptr_t)
 Equivalent to default ctor.
 
constexpr Resource (std::nullopt_t)
 Equivalent to default ctor.
 
 Resource (const Resource &other)=delete
 
 Resource (Resource &&other)=delete
 
- Public Member Functions inherited from SDL::Resource< SDL_AudioStream * >
constexpr Resource (SDL_AudioStream * resource={})
 Constructs the underlying resource.
 
constexpr Resource (std::nullptr_t)
 Equivalent to default ctor.
 
constexpr Resource (std::nullopt_t)
 Equivalent to default ctor.
 
 Resource (const Resource &other)=delete
 
 Resource (Resource &&other)=delete
 
Resourceoperator= (const Resource &other)=delete
 
Resourceoperator= (Resource &&other)=delete
 
constexpr operator bool () const
 True if contains a valid resource.
 
constexpr bool operator== (const Resource &other) const=default
 Comparison.
 
constexpr bool operator== (std::nullopt_t) const
 Comparison.
 
constexpr bool operator== (std::nullptr_t) const
 Comparison.
 
constexpr SDL_AudioStream * get () const
 Return contained resource;.
 
constexpr SDL_AudioStream * release (SDL_AudioStream * newResource={})
 Return contained resource and empties or replace value.
 
constexpr const SDL_AudioStream * operator-> () const
 Access to fields.
 
constexpr SDL_AudioStream * operator-> ()
 Access to fields.
 

Detailed Description

Category:
Resource
See also
AudioStreamBase
AudioStream

Member Function Documentation

◆ AudioStreamBase() [1/3]

SDL::AudioStreamBase::AudioStreamBase ( const AudioDeviceBase devid,
OptionalRef< const AudioSpec spec,
AudioStreamCB  callback 
)
inline

If all your app intends to do is provide a single source of PCM audio, this function allows you to do all your audio setup in a single call.

This is also intended to be a clean means to migrate apps from SDL2.

This function will open an audio device, create a stream and bind it. Unlike other methods of setup, the audio device will be closed when this stream is destroyed, so the app can treat the returned AudioStreamBase as the only object needed to manage audio playback.

Also unlike other functions, the audio device begins paused. This is to map more closely to SDL2-style behavior, since there is no extra step here to bind a stream to begin audio flowing. The audio device should be resumed with AudioStreamBase.ResumeDevice(stream);

This function works with both playback and recording devices.

The spec parameter represents the app's side of the audio stream. That is, for recording audio, this will be the output format, and for playing audio, this will be the input format. If spec is nullptr, the system will choose the format, and the app can use AudioStreamBase.GetFormat() to obtain this information later.

If you don't care about opening a specific audio device, you can (and probably should), use AUDIO_DEVICE_DEFAULT_PLAYBACK for playback and AUDIO_DEVICE_DEFAULT_RECORDING for recording.

One can optionally provide a callback function; if nullptr, the app is expected to queue audio data for playback (or unqueue audio data if capturing). Otherwise, the callback will begin to fire once the device is unpaused.

Destroying the returned stream with AudioStreamRef.reset will also close the audio device associated with this stream.

Parameters
devidan audio device to open, or AUDIO_DEVICE_DEFAULT_PLAYBACK or AUDIO_DEVICE_DEFAULT_RECORDING.
specthe audio stream's data format. Can be std::nullopt.
callbacka callback where the app will provide new data for playback, or receive new data for recording. Can not be nullptr.
Postcondition
an audio stream on success.
Exceptions
Erroron failure.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.
See also
AudioStreamBase.GetDevice
AudioStreamBase.ResumeDevice

◆ AudioStreamBase() [2/3]

SDL::AudioStreamBase::AudioStreamBase ( const AudioDeviceBase devid,
OptionalRef< const AudioSpec spec = std::nullopt,
AudioStreamCallback  callback = nullptr,
void *  userdata = nullptr 
)
inline

If all your app intends to do is provide a single source of PCM audio, this function allows you to do all your audio setup in a single call.

This is also intended to be a clean means to migrate apps from SDL2.

This function will open an audio device, create a stream and bind it. Unlike other methods of setup, the audio device will be closed when this stream is destroyed, so the app can treat the returned AudioStreamBase as the only object needed to manage audio playback.

Also unlike other functions, the audio device begins paused. This is to map more closely to SDL2-style behavior, since there is no extra step here to bind a stream to begin audio flowing. The audio device should be resumed with AudioStreamBase.ResumeDevice(stream);

This function works with both playback and recording devices.

The spec parameter represents the app's side of the audio stream. That is, for recording audio, this will be the output format, and for playing audio, this will be the input format. If spec is nullptr, the system will choose the format, and the app can use AudioStreamBase.GetFormat() to obtain this information later.

If you don't care about opening a specific audio device, you can (and probably should), use AUDIO_DEVICE_DEFAULT_PLAYBACK for playback and AUDIO_DEVICE_DEFAULT_RECORDING for recording.

One can optionally provide a callback function; if nullptr, the app is expected to queue audio data for playback (or unqueue audio data if capturing). Otherwise, the callback will begin to fire once the device is unpaused.

Destroying the returned stream with AudioStreamRef.reset will also close the audio device associated with this stream.

Parameters
devidan audio device to open, or AUDIO_DEVICE_DEFAULT_PLAYBACK or AUDIO_DEVICE_DEFAULT_RECORDING.
specthe audio stream's data format. Can be std::nullopt.
callbacka callback where the app will provide new data for playback, or receive new data for recording. Can be nullptr, in which case the app will need to call AudioStreamBase.PutData or AudioStreamBase.GetData as necessary.
userdataapp-controlled pointer passed to callback. Can be nullptr. Ignored if callback is nullptr.
Postcondition
an audio stream on success.
Exceptions
Erroron failure.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.
See also
AudioStreamBase.GetDevice
AudioStreamBase.ResumeDevice

◆ AudioStreamBase() [3/3]

SDL::AudioStreamBase::AudioStreamBase ( OptionalRef< const AudioSpec src_spec,
OptionalRef< const AudioSpec dst_spec 
)
inline
Parameters
src_specthe format details of the input audio.
dst_specthe format details of the output audio.
Postcondition
a new audio stream on success.
Exceptions
Erroron failure.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.
See also
AudioStreamBase.PutData
AudioStreamBase.GetData
AudioStreamBase.GetAvailable
AudioStreamBase.Flush
AudioStreamBase.Clear
AudioStreamBase.SetFormat

◆ reset()

void SDL::AudioStreamRef::reset ( SDL_AudioStream *  newResource = {})
inline

This will release all allocated data, including any audio that is still queued. You do not need to manually clear the stream first.

If this stream was bound to an audio device, it is unbound during this call. If this stream was created with AudioStreamBase.AudioStreamBase, the audio device that was opened alongside this stream's creation will be closed, too.

Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.
See also
AudioStreamBase.AudioStreamBase

The documentation for this struct was generated from the following file: