1 module gfm.sdl2.audio; 2 3 import bindbc.sdl; 4 5 import gfm.sdl2.sdl; 6 7 final class SDL2AudioDevice 8 { 9 private 10 { 11 SDL_AudioDeviceID _id; 12 } 13 14 public 15 { 16 /++ 17 See_also: $(LINK https://wiki.libsdl.org/SDL_OpenAudioDevice) 18 +/ 19 this(SDL2 sdl2, const(char)[] name, int iscapture, const(SDL_AudioSpec*) desired, SDL_AudioSpec* obtained, int allowed_changes) 20 { 21 import std..string : toStringz; 22 _id = SDL_OpenAudioDevice(toStringz(name), iscapture, desired, obtained, allowed_changes); 23 24 if (_id == 0) 25 { 26 sdl2.throwSDL2Exception("SDL_OpenAudioDevice"); 27 } 28 } 29 30 ~this() 31 { 32 SDL_CloseAudioDevice(_id); 33 } 34 35 nothrow @nogc 36 { 37 /++ 38 Starts playing sound on this device 39 See_also: $(D pause), $(LINK https://wiki.libsdl.org/SDL_PauseAudioDevice) 40 +/ 41 void play() 42 { 43 SDL_PauseAudioDevice(_id, 0); 44 } 45 46 /++ 47 Stops playing sound on this device 48 See_also: $(D play), $(LINK https://wiki.libsdl.org/SDL_PauseAudioDevice) 49 +/ 50 void pause() 51 { 52 SDL_PauseAudioDevice(_id, 1); 53 } 54 55 /++ 56 Makes SDL not run the callback from $(D desired).callback. 57 See_also: $(D unlock), $(LINK https://wiki.libsdl.org/SDL_LockAudioDevice) 58 +/ 59 void lock() 60 { 61 SDL_LockAudioDevice(_id); 62 } 63 64 /++ 65 Makes SDL run the callback from $(D desired).callback again. 66 See_also: $(D lock), $(LINK https://wiki.libsdl.org/SDL_UnlockAudioDevice) 67 +/ 68 void unlock() 69 { 70 SDL_UnlockAudioDevice(_id); 71 } 72 73 /++ 74 Checks if this audio device is currently playing sound. 75 See_also: $(D status), $(LINK https://wiki.libsdl.org/SDL_AudioStatus) 76 +/ 77 bool playing() 78 { 79 return status == SDL_AUDIO_PLAYING; 80 } 81 82 /++ 83 See_also: $(D playing), $(LINK https://wiki.libsdl.org/SDL_GetAudioDeviceStatus) 84 +/ 85 SDL_AudioStatus status() 86 { 87 return SDL_GetAudioDeviceStatus(_id); 88 } 89 } 90 } 91 }