26#include <SDL2/SDL_mixer.h>
35#define _Class _SoundStage
49#pragma mark - SoundStage
60 if (Mix_OpenAudioDevice(48000, AUDIO_S16SYS, 2, 2048, NULL, SDL_AUDIO_ALLOW_ANY_CHANGE) == 0) {
63 MVC_LogError(
"Failed to open audio device: %s\n", SDL_GetError());
76 static unsigned int ch;
80 Mix_PlayChannel(ch++ % MIX_CHANNELS, sound->
chunk, 0);
83#pragma mark - Class lifecycle
93 ((ObjectInterface *) clazz->interface)->dealloc =
dealloc;
95 ((SoundStageInterface *) clazz->interface)->init =
init;
96 ((SoundStageInterface *) clazz->interface)->play =
play;
98 const int init = Mix_Init(0xff);
125 clazz = _initialize(&(
const ClassDef) {
126 .name =
"SoundStage",
127 .superclass = _Object(),
129 .interfaceOffset = offsetof(
SoundStage, interface),
130 .interfaceSize =
sizeof(SoundStageInterface),
143 SDL_Window *window = SDL_GL_GetCurrentWindow();
View logging facilities via SDL_Log.
#define MVC_LogInfo(fmt,...)
#define MVC_LogError(fmt,...)
static void destroy(Class *clazz)
static void dealloc(Object *self)
static void initialize(Class *clazz)
OBJECTIVELYMVC_EXPORT void MVC_PlaySound(const Sound *sound)
Plays the specified Sound through the current SoundStage (if any).
#define OBJECTIVELYMVC_EXPORT
A WindowController manages a ViewController and its descendants within an SDL_Window.
CollectionView * init(CollectionView *self, const SDL_Rect *frame)
Initializes this CollectionView with the specified frame and style.
Sound loading and playback.
Mix_Chunk * chunk
The backing audio chunk.
Sound * soundWithBytes(const uint8_t *bytes, size_t length)
Instantiates an Sound with the specified bytes.
Class * _SoundStage(void)
The SoundStage archetype.
void play(const SoundStage *self, const char *sound)
Enqueues the given Sound for playback.
A WindowController manages a ViewController and its descendants within an SDL_Window.
WindowController * windowController(SDL_Window *window)
SoundStage * soundStage
The SoundStage.