libSDL2pp
C++ bindings/wrapper for SDL2
Loading...
Searching...
No Matches
AudioDevice.hh
1/*
2 libSDL2pp - C++ bindings/wrapper for SDL2
3 Copyright (C) 2014-2016 Dmitry Marakasov <amdmi3@amdmi3.ru>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22#ifndef SDL2PP_AUDIODEVICE_HH
23#define SDL2PP_AUDIODEVICE_HH
24
25#include <functional>
26#include <string>
27
28#include <SDL_audio.h>
29#include <SDL_version.h>
30
31#include <SDL2pp/Optional.hh>
32#include <SDL2pp/Config.hh>
33#include <SDL2pp/Export.hh>
34
35namespace SDL2pp {
36
37class AudioSpec;
38
50class SDL2PP_EXPORT AudioDevice {
51public:
86 class SDL2PP_EXPORT LockHandle {
87 friend class AudioDevice;
88 private:
89 AudioDevice* device_;
90
91 private:
105 explicit LockHandle(AudioDevice* device);
106
107 public:
115 LockHandle();
116
125 ~LockHandle();
126
133 LockHandle(LockHandle&& other) noexcept;
134
143 LockHandle& operator=(LockHandle&& other) noexcept;
144
151 LockHandle(const LockHandle& other);
152
161 LockHandle& operator=(const LockHandle& other);
162 };
163
164 typedef std::function<void(Uint8* stream, int len)> AudioCallback;
165
166private:
167 SDL_AudioDeviceID device_id_;
168 AudioCallback callback_;
169
170private:
178 static void SDLCallback(void *userdata, Uint8* stream, int len);
179
180public:
195 AudioDevice(const Optional<std::string>& device, bool iscapture, const AudioSpec& spec, AudioCallback&& callback = AudioCallback());
196
213 AudioDevice(const Optional<std::string>& device, bool iscapture, AudioSpec& spec, int allowed_changes, AudioCallback&& callback = AudioCallback());
214
219 virtual ~AudioDevice();
220
227 AudioDevice(AudioDevice&& other) noexcept;
228
237 AudioDevice& operator=(AudioDevice&& other) noexcept;
238
245 AudioDevice(const AudioDevice&) = delete;
246
254
261 SDL_AudioDeviceID Get() const;
262
273 AudioDevice& Pause(bool pause_on);
274
283 SDL_AudioStatus GetStatus() const;
284
293 AudioDevice& ChangeCallback(AudioCallback&& callback);
294
307 LockHandle Lock();
308
309#if SDL_VERSION_ATLEAST(2, 0, 4)
323 AudioDevice& QueueAudio(const void* data, Uint32 len);
324
333 AudioDevice& ClearQueuedAudio();
334
343 Uint32 GetQueuedAudioSize() const;
344#endif
345};
346
347}
348
349#endif
SDL2pp::AudioDevice lock.
Definition: AudioDevice.hh:86
Audio device.
Definition: AudioDevice.hh:50
AudioDevice(const AudioDevice &)=delete
Deleted copy constructor.
std::function< void(Uint8 *stream, int len)> AudioCallback
Function type for audio callback.
Definition: AudioDevice.hh:164
AudioDevice & operator=(const AudioDevice &)=delete
Deleted assignment operator.
Audio format specification.
Definition: AudioSpec.hh:46