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