libSDL2pp
C++ bindings/wrapper for SDL2
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | List of all members
SDL2pp::AudioDevice Class Reference

Audio device. More...

#include <SDL2pp/AudioDevice.hh>

Classes

class  LockHandle
 SDL2pp::AudioDevice lock. More...
 

Public Types

typedef std::function< void(Uint8 *stream, int len)> AudioCallback
 Function type for audio callback.
 

Public Member Functions

 AudioDevice (const Optional< std::string > &device, bool iscapture, const AudioSpec &spec, AudioCallback &&callback=AudioCallback())
 Open audio device with specified output format.
 
 AudioDevice (const Optional< std::string > &device, bool iscapture, AudioSpec &spec, int allowed_changes, AudioCallback &&callback=AudioCallback())
 Open audio device with desired output format.
 
virtual ~AudioDevice ()
 Destructor.
 
 AudioDevice (AudioDevice &&other) noexcept
 Move constructor.
 
AudioDeviceoperator= (AudioDevice &&other) noexcept
 Move constructor.
 
 AudioDevice (const AudioDevice &)=delete
 Deleted copy constructor.
 
AudioDeviceoperator= (const AudioDevice &)=delete
 Deleted assignment operator.
 
SDL_AudioDeviceID Get () const
 Get managed audio device ID.
 
AudioDevicePause (bool pause_on)
 Pause or unpause audio playback.
 
SDL_AudioStatus GetStatus () const
 Get playback status.
 
AudioDeviceChangeCallback (AudioCallback &&callback)
 Replace audio callback.
 
LockHandle Lock ()
 Lock audio device to prevent it from calling audio callback.
 
AudioDeviceQueueAudio (const void *data, Uint32 len)
 Queue more audio for a non-callback device.
 
AudioDeviceClearQueuedAudio ()
 Drop queued audio.
 
Uint32 GetQueuedAudioSize () const
 Get number of bytes of still-queued audio.
 

Detailed Description

Audio device.

This class provides access to basic SDL (not SDL_mixer!) audio functionality.

Constructor & Destructor Documentation

◆ AudioDevice() [1/4]

SDL2pp::AudioDevice::AudioDevice ( const Optional< std::string > &  device,
bool  iscapture,
const AudioSpec spec,
AudioDevice::AudioCallback &&  callback = AudioCallback() 
)

Open audio device with specified output format.

Parameters
[in]deviceName of the device to open
[in]iscaptureNon-zero to open device for recording (SDL2 doesn't support this yet)
[in]specAudio output format
[in]callbackCallback which will feed audio to the device
Exceptions
SDL2pp::Exception
See also
http://wiki.libsdl.org/SDL_OpenAudioDevice

◆ AudioDevice() [2/4]

SDL2pp::AudioDevice::AudioDevice ( const Optional< std::string > &  device,
bool  iscapture,
AudioSpec spec,
int  allowed_changes,
AudioDevice::AudioCallback &&  callback = AudioCallback() 
)

Open audio device with desired output format.

Parameters
[in]deviceName of the device to open
[in]iscaptureNon-zero to open device for recording (SDL2 doesn't support this yet)
[in]allowed_changesFlag mask specifying which audio format properties may change
[in,out]specDesired audio output format (may be changed)
[in]callbackCallback which will feed audio to the device
Exceptions
SDL2pp::Exception
See also
http://wiki.libsdl.org/SDL_OpenAudioDevice

◆ ~AudioDevice()

SDL2pp::AudioDevice::~AudioDevice ( )
virtual

Destructor.

◆ AudioDevice() [3/4]

SDL2pp::AudioDevice::AudioDevice ( AudioDevice &&  other)
noexcept

Move constructor.

Parameters
[in]otherSDL2pp::AudioDevice to move data from

◆ AudioDevice() [4/4]

SDL2pp::AudioDevice::AudioDevice ( const AudioDevice )
delete

Deleted copy constructor.

This class is not copyable

Member Function Documentation

◆ ChangeCallback()

AudioDevice & SDL2pp::AudioDevice::ChangeCallback ( AudioDevice::AudioCallback &&  callback)

Replace audio callback.

Parameters
[in]callbackNew audio callback
Returns
Reference to self

◆ ClearQueuedAudio()

AudioDevice & SDL2pp::AudioDevice::ClearQueuedAudio ( )

Drop queued audio.

Returns
Reference to self
See also
http://wiki.libsdl.org/SDL_ClearQueuedAudio

◆ Get()

SDL_AudioDeviceID SDL2pp::AudioDevice::Get ( ) const

Get managed audio device ID.

Returns
Managed audio device ID

◆ GetQueuedAudioSize()

Uint32 SDL2pp::AudioDevice::GetQueuedAudioSize ( ) const

Get number of bytes of still-queued audio.

Returns
Number of bytes (not samples!) of still-queued audio
See also
http://wiki.libsdl.org/SDL_GetQueuedAudioSize

◆ GetStatus()

SDL_AudioStatus SDL2pp::AudioDevice::GetStatus ( ) const

Get playback status.

Returns
Playback status (SDL_AUDIO_STOPPED, SDL_AUDIO_PLAYING, SDL_AUDIO_PAUSED)
See also
http://wiki.libsdl.org/SDL_GetAudioDeviceStatus

◆ Lock()

AudioDevice::LockHandle SDL2pp::AudioDevice::Lock ( )

Lock audio device to prevent it from calling audio callback.

Returns
Lock handle used to control lock lifetime

The device remains locked for the lifetime of returned LockHandle

Recursive locking is allowed

See also
http://wiki.libsdl.org/SDL_LockAudioDevice

◆ operator=() [1/2]

AudioDevice & SDL2pp::AudioDevice::operator= ( AudioDevice &&  other)
noexcept

Move constructor.

Parameters
[in]otherSDL2pp::AudioDevice to move data from
Returns
Reference to self

◆ operator=() [2/2]

AudioDevice & SDL2pp::AudioDevice::operator= ( const AudioDevice )
delete

Deleted assignment operator.

This class is not copyable

◆ Pause()

AudioDevice & SDL2pp::AudioDevice::Pause ( bool  pause_on)

Pause or unpause audio playback.

Parameters
[in]pause_onWhether audio should be paused
Returns
Reference to self
See also
http://wiki.libsdl.org/SDL_PauseAudioDevice

◆ QueueAudio()

AudioDevice & SDL2pp::AudioDevice::QueueAudio ( const void *  data,
Uint32  len 
)

Queue more audio for a non-callback device.

Parameters
[in]dataData to queue for later playback
[in]lenData length in bytes (not samples!)
Returns
Reference to self
Exceptions
SDL2pp::Exception
See also
http://wiki.libsdl.org/SDL_QueueAudio

The documentation for this class was generated from the following files: