#include <assert.h>
#include <SDL2/SDL_mixer.h>
#include "clack.wav.h"
#include "click.wav.h"
#include "Log.h"
#include "SoundStage.h"
#include "WindowController.h"
Go to the source code of this file.
◆ _Class
◆ _SoundStage()
Class * _SoundStage |
( |
void |
| ) |
|
Definition at line 120 of file SoundStage.c.
120 {
121 static Class *clazz;
122 static Once once;
123
124 do_once(&once, {
125 clazz = _initialize(&(const ClassDef) {
126 .name = "SoundStage",
127 .superclass = _Object(),
129 .interfaceOffset = offsetof(
SoundStage, interface),
130 .interfaceSize = sizeof(SoundStageInterface),
133 });
134 });
135
136 return clazz;
137}
static void destroy(Class *clazz)
static void initialize(Class *clazz)
◆ dealloc()
static void dealloc |
( |
Object * |
self | ) |
|
|
static |
- See also
- Object::dealloc(Object *)
Definition at line 42 of file SoundStage.c.
42 {
43
44 Mix_CloseAudio();
45
47}
static void dealloc(Object *self)
◆ destroy()
static void destroy |
( |
Class * |
clazz | ) |
|
|
static |
- See also
- Class::destroy(Class *)
Definition at line 108 of file SoundStage.c.
108 {
109
112
113 Mix_Quit();
114}
◆ init()
Definition at line 55 of file SoundStage.c.
55 {
56
58 if (self) {
59
60 if (Mix_OpenAudioDevice(48000, AUDIO_S16SYS, 2, 2048, NULL, SDL_AUDIO_ALLOW_ANY_CHANGE) == 0) {
62 } else {
63 MVC_LogError(
"Failed to open audio device: %s\n", SDL_GetError());
64 self = release(self);
65 }
66 }
67
68 return self;
69}
#define MVC_LogInfo(fmt,...)
#define MVC_LogError(fmt,...)
CollectionView * init(CollectionView *self, const SDL_Rect *frame)
Initializes this CollectionView with the specified frame and style.
◆ initialize()
static void initialize |
( |
Class * |
clazz | ) |
|
|
static |
- See also
- Class::initialize(Class *)
Definition at line 91 of file SoundStage.c.
91 {
92
93 ((ObjectInterface *) clazz->interface)->dealloc =
dealloc;
94
95 ((SoundStageInterface *) clazz->interface)->init =
init;
96 ((SoundStageInterface *) clazz->interface)->play =
play;
97
98 const int init = Mix_Init(0xff);
100
103}
Sound loading and playback.
Sound * soundWithBytes(const uint8_t *bytes, size_t length)
Instantiates an Sound with the specified bytes.
void play(const SoundStage *self, const char *sound)
Enqueues the given Sound for playback.
◆ MVC_PlaySound()
Plays the specified Sound through the current SoundStage (if any).
- Parameters
-
Definition at line 141 of file SoundStage.c.
141 {
142
143 SDL_Window *window = SDL_GL_GetCurrentWindow();
144 assert(window);
145
149
151}
A WindowController manages a ViewController and its descendants within an SDL_Window.
WindowController * windowController(SDL_Window *window)
SoundStage * soundStage
The SoundStage.
◆ play()
Definition at line 75 of file SoundStage.c.
75 {
76 static unsigned int ch;
77
78 assert(sound);
79
80 Mix_PlayChannel(ch++ % MIX_CHANNELS, sound->
chunk, 0);
81}
Mix_Chunk * chunk
The backing audio chunk.
◆ _clack
◆ _click