Oolite
Loading...
Searching...
No Matches
OOALSoundMixer.m
Go to the documentation of this file.
1
/*
2
3
OOALSoundMixer.m
4
5
OOALSound - OpenAL sound implementation for Oolite.
6
Copyright (C) 2006-2013 Jens Ayton
7
8
Permission is hereby granted, free of charge, to any person obtaining a copy
9
of this software and associated documentation files (the "Software"), to deal
10
in the Software without restriction, including without limitation the rights
11
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
copies of the Software, and to permit persons to whom the Software is
13
furnished to do so, subject to the following conditions:
14
15
The above copyright notice and this permission notice shall be included in all
16
copies or substantial portions of the Software.
17
18
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
SOFTWARE.
25
26
*/
27
28
#include <assert.h>
29
30
#import "
OOALSound.h
"
31
#import "
OOALSoundChannel.h
"
32
#import "
OOALSoundMixer.h
"
33
#import "
OOFoundation.h
"
34
35
static
OOSoundMixer
*
sSingleton
=
nil
;
36
37
@implementation
OOSoundMixer
38
39
+ (id)
sharedMixer
40
{
41
if
(
nil
==
sSingleton
) {
42
[[
self
alloc] init];
43
}
44
return
sSingleton
;
45
}
46
47
- (id)
init
48
{
49
BOOL OK = YES;
50
uint32_t idx = 0,
count
=
kMixerGeneralChannels
;
51
OOSoundChannel
* channel;
52
53
if
(!(
self
= [super
init
]))
54
return
nil
;
55
if
(![
OOSound
setUp])
56
OK = NO;
57
58
if
(OK) {
59
// Allocate channels
60
do
{
61
channel = [[
OOSoundChannel
alloc] init];
62
if
(
nil
!= channel) {
63
_channels
[
idx
++] = channel;
64
[
self
pushChannel
:channel];
65
}
66
}
while
(--
count
);
67
}
68
69
if
(!OK) {
70
[
super
release];
71
// static analyser complains about this next line; probably nothing - CIM
72
self
=
nil
;
73
}
else
{
74
sSingleton
=
self
;
75
}
76
77
return
sSingleton
;
78
}
79
80
// only to be called at app shutdown by OOOpenALController::shutdown
81
- (void)
shutdown
82
{
83
uint32_t i;
84
for
(i = 0; i <
kMixerGeneralChannels
; ++i) {
85
DESTROY
(
_channels
[i]);
86
}
87
}
88
89
- (void)
update
90
{
91
uint32_t i;
92
for
(i = 0; i <
kMixerGeneralChannels
; ++i) {
93
[
_channels
[
i
]
update
];
94
}
95
}
96
97
- (
OOSoundChannel
*)
popChannel
98
{
99
OOSoundChannel
* channel =
_freeList
;
100
_freeList
= [
channel
next
];
101
[
channel
setNext
:nil];
102
103
return
channel;
104
}
105
106
- (void)pushChannel:(
OOSoundChannel
*)channel
107
{
108
assert(channel !=
nil
);
109
110
[
channel
setNext
:_freeList];
111
_freeList
= channel;
112
}
113
114
@end
115
116
@implementation
OOSoundMixer (Singleton)
117
118
/* Canonical singleton boilerplate.
119
See Cocoa Fundamentals Guide: Creating a Singleton Instance.
120
See also +sharedMixer above.
121
122
NOTE: assumes single-threaded access.
123
*/
124
125
+ (id)allocWithZone:(NSZone*)inZone
126
{
127
if
(
sSingleton
==
nil
) {
128
sSingleton
= [
super
allocWithZone:inZone];
129
return
sSingleton
;
130
}
131
return
nil
;
132
}
133
134
- (id)copyWithZone:(NSZone*)inZone
135
{
136
return
self
;
137
}
138
139
- (id)
retain
140
{
141
return
self
;
142
}
143
144
- (NSUInteger)
retainCount
145
{
146
return
UINT_MAX;
147
}
148
149
- (void)
release
150
{
151
}
152
153
- (id)
autorelease
154
{
155
return
self
;
156
}
157
158
@end
OOALSoundChannel.h
OOALSoundMixer.h
kMixerGeneralChannels
@ kMixerGeneralChannels
Definition
OOALSoundMixer.h:37
OOALSound.h
OOFoundation.h
DESTROY
#define DESTROY(x)
Definition
OOFoundation.h:62
sSingleton
static OONullTexture * sSingleton
Definition
OONullTexture.m:32
count
unsigned count
Definition
OOParticleSystem.m:253
nil
return nil
Definition
OOProbabilitySet.m:393
-[OOSoundMixer(Singleton) release]
void release()
Definition
OOALSoundMixer.m:149
-[OOSoundMixer(Singleton) autorelease]
id autorelease()
Definition
OOALSoundMixer.m:153
-[OOSoundMixer(Singleton) retain]
id retain()
Definition
OOALSoundMixer.m:139
-[OOSoundMixer(Singleton) retainCount]
NSUInteger retainCount()
Definition
OOALSoundMixer.m:144
OOSoundChannel
Definition
OOALSoundChannel.h:40
-[OOSoundChannel next]
OOSoundChannel * next()
Definition
OOALSoundChannel.m:120
-[OOSoundChannel update]
void update()
Definition
OOALSoundChannel.m:68
-[OOSoundChannel setNext:]
void setNext:(OOSoundChannel *next)
Definition
OOALSoundChannel.m:125
OOSoundMixer
Definition
OOALSoundMixer.h:40
OOSoundMixer::_freeList
OOSoundChannel * _freeList
Definition
OOALSoundMixer.h:42
+[OOSoundMixer sharedMixer]
id sharedMixer()
Definition
OOALSoundMixer.m:39
-[OOSoundMixer shutdown]
void shutdown()
Definition
OOALSoundMixer.m:81
-[OOSoundMixer pushChannel:]
void pushChannel:(OOSoundChannel *channel)
Definition
OOALSoundMixer.m:106
-[OOSoundMixer popChannel]
OOSoundChannel * popChannel()
Definition
OOALSoundMixer.m:97
-[OOSoundMixer init]
id init()
Definition
OOALSoundMixer.m:47
OOSoundMixer::_channels
OOSoundChannel * _channels[kMixerGeneralChannels]
Definition
OOALSoundMixer.h:41
-[OOSoundMixer update]
void update()
Definition
OOALSoundMixer.m:89
OOSound
Definition
OOALSound.h:31
src
Core
OOALSoundMixer.m
Generated by
1.15.0