ObjectivelyMVC 0.1.0
Object oriented MVC framework for OpenGL, SDL2 and GNU C
Public Member Functions | Data Fields | Protected Attributes
Sound Struct Reference

Sound loading and playback. More...

#include <Sound.h>

Inheritance diagram for Sound:

Public Member Functions

Class * _Sound (void)
 The Sound archetype. More...
 
SoundinitWithBytes (Sound *self, const uint8_t *bytes, size_t length)
 Initializes this Sound with the specified bytes. More...
 
SoundinitWithChunk (Sound *, const Chunk *)
 Initializes this Sound with the given audio chunk. More...
 
SoundinitWithData (Sound *, Data *)
 
SoundinitWithData (Sound *self, const Data *data)
 Initializes this Sound with the specified Data. More...
 
SoundinitWithResource (Sound *, const Resource *)
 Initializes this Sound with the specified Resource. More...
 
SoundinitWithResourceName (Sound *, const char *)
 Initializes this Sound with the specified Resource name. More...
 
SoundsoundWithBytes (const uint8_t *bytes, size_t length)
 Instantiates an Sound with the specified bytes. More...
 
SoundsoundWithChunk (Mix_Chunk *chunk)
 Instantiates an Sound with the specified chunk. More...
 
SoundsoundWithData (const Data *data)
 Instantiates an Sound with the specified Data. More...
 
SoundsoundWithResource (const Resource *resource)
 Instantiates an Sound with the specified Resource. More...
 
SoundsoundWithResourceName (const char *name)
 Instantiates an Sound with the specified Resource name. More...
 

Data Fields

Mix_Chunk * chunk
 The backing audio chunk. More...
 
Object object
 The superclass. More...
 

Protected Attributes

SoundInterface * interface
 The interface. More...
 

Detailed Description

Sound loading and playback.

Definition at line 45 of file Sound.h.

Member Function Documentation

◆ _Sound()

Class * _Sound ( void  )

The Sound archetype.

Returns
The Sound Class.

Definition at line 190 of file Sound.c.

190 {
191 static Class *clazz;
192 static Once once;
193
194 do_once(&once, {
195 clazz = _initialize(&(const ClassDef) {
196 .name = "Sound",
197 .superclass = _Object(),
198 .instanceSize = sizeof(Sound),
199 .interfaceOffset = offsetof(Sound, interface),
200 .interfaceSize = sizeof(SoundInterface),
202 });
203 });
204
205 return clazz;
206}
static void initialize(Class *clazz)
Definition: Sound.c:169
Sound loading and playback.
Definition: Sound.h:45
SoundInterface * interface
The interface.
Definition: Sound.h:56

◆ initWithBytes()

Sound * initWithBytes ( Sound self,
const uint8_t *  bytes,
size_t  length 
)

Initializes this Sound with the specified bytes.

Parameters
selfThe Sound.
bytesThe encoded sound data.
lengthThe length of bytes.
Returns
The new Sound, or NULL on error.

Definition at line 52 of file Sound.c.

52 {
53
54 SDL_RWops *src = SDL_RWFromConstMem(bytes, (int) length);
55 if (src) {
56 self = $(self, initWithChunk, Mix_LoadWAV_RW(src, 1));
57 } else {
58 self = release(self);
59 }
60
61 return self;
62}
Sound * initWithChunk(Sound *, const Chunk *)
Initializes this Sound with the given audio chunk.

◆ initWithChunk()

Sound * initWithChunk ( Sound self,
const Chunk *  chunk 
)

Initializes this Sound with the given audio chunk.

Parameters
selfThe Sound.
chunkThe backing chunk.
Returns
The new Sound, or NULL on error.
Remarks
Designated initializer.

◆ initWithData() [1/2]

Sound * initWithData ( Sound ,
Data *   
)

◆ initWithData() [2/2]

Sound * initWithData ( Sound self,
const Data *  data 
)

Initializes this Sound with the specified Data.

Parameters
selfThe Sound.
dataThe Data providing encoded audio data.
Returns
The initialized Sound, or NULL on error.

Definition at line 68 of file Sound.c.

68 {
69
70 if (data) {
71 self = $(self, initWithBytes, data->bytes, data->length);
72 } else {
73 self = release(self);
74 }
75
76 return self;
77}
Sound * initWithBytes(Sound *self, const uint8_t *bytes, size_t length)
Initializes this Sound with the specified bytes.
Definition: Sound.c:52

◆ initWithResource()

Sound * initWithResource ( Sound self,
const Resource *  resource 
)

Initializes this Sound with the specified Resource.

Parameters
selfThe Sound.
resourceThe Resource providing encoded audio data.
Returns
The initialized Sound, or NULL on error.

Definition at line 98 of file Sound.c.

98 {
99
100 if (resource) {
101 self = $(self, initWithData, resource->data);
102 } else {
103 self = release(self);
104 }
105
106 return self;
107}
Sound * initWithData(Sound *, Data *)

◆ initWithResourceName()

Sound * initWithResourceName ( Sound self,
const char *  name 
)

Initializes this Sound with the specified Resource name.

Parameters
selfThe Sound.
nameThe name of the Resource providing encoded audio data.
Returns
The initialized Sound, or NULL on error.

Definition at line 113 of file Sound.c.

113 {
114
115 Resource *resource = $$(Resource, resourceWithName, name);
116
117 self = $(self, initWithResource, resource);
118
119 release(resource);
120
121 return self;
122}
Sound * initWithResource(Sound *, const Resource *)
Initializes this Sound with the specified Resource.
Definition: Sound.c:98

◆ soundWithBytes()

Sound * soundWithBytes ( const uint8_t *  bytes,
size_t  length 
)

Instantiates an Sound with the specified bytes.

Parameters
bytesThe encoded sound bytes.
lengthThe length of bytes.
Returns
The new Sound, or NULL on error.

Definition at line 128 of file Sound.c.

128 {
129 return $(alloc(Sound), initWithBytes, bytes, length);
130}

◆ soundWithChunk()

Sound * soundWithChunk ( Mix_Chunk *  chunk)

Instantiates an Sound with the specified chunk.

Parameters
chunkThe chunk.
Returns
The new Sound, or NULL on error.

Definition at line 136 of file Sound.c.

136 {
137 return $(alloc(Sound), initWithChunk, chunk);
138}
Mix_Chunk * chunk
The backing audio chunk.
Definition: Sound.h:61

◆ soundWithData()

Sound * soundWithData ( const Data *  data)

Instantiates an Sound with the specified Data.

Parameters
dataThe encoded sound Data.
Returns
The new Sound, or NULL on error.

Definition at line 144 of file Sound.c.

144 {
145 return $(alloc(Sound), initWithData, data);
146}

◆ soundWithResource()

Sound * soundWithResource ( const Resource *  resource)

Instantiates an Sound with the specified Resource.

Parameters
resourceThe Resource containing encoded sound data.
Returns
The new Sound, or NULL on error.

Definition at line 152 of file Sound.c.

152 {
153 return $(alloc(Sound), initWithResource, resource);
154}

◆ soundWithResourceName()

Sound * soundWithResourceName ( const char *  name)

Instantiates an Sound with the specified Resource name.

Parameters
nameThe name of a Resource containing encoded sound data.
Returns
The new Sound, or NULL on error.

Definition at line 160 of file Sound.c.

160 {
161 return $(alloc(Sound), initWithResourceName, name);
162}
Sound * initWithResourceName(Sound *, const char *)
Initializes this Sound with the specified Resource name.
Definition: Sound.c:113

Field Documentation

◆ chunk

Mix_Chunk* Sound::chunk

The backing audio chunk.

Definition at line 61 of file Sound.h.

◆ interface

SoundInterface* Sound::interface
protected

The interface.

Definition at line 56 of file Sound.h.

◆ object

Object Sound::object

The superclass.

Definition at line 50 of file Sound.h.


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