Oolite
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 "OOALSound.h"
31#import "OOALSoundChannel.h"
32#import "OOALSoundMixer.h"
33#import "OOFoundation.h"
34
36
37@implementation OOSoundMixer
38
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) {
86 }
87}
88
89- (void)update
90{
91 uint32_t i;
92 for (i = 0; i < kMixerGeneralChannels; ++i) {
94 }
95}
96
98{
99 OOSoundChannel* channel = _freeList;
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
140{
141 return self;
142}
143
144- (NSUInteger)retainCount
145{
146 return UINT_MAX;
147}
148
149- (void)release
150{
151}
152
154{
155 return self;
156}
157
158@end
@ kMixerGeneralChannels
#define DESTROY(x)
static OONullTexture * sSingleton
unsigned count
return nil
OOSoundChannel * next()
void setNext:(OOSoundChannel *next)
OOSoundChannel * _freeList
void pushChannel:(OOSoundChannel *channel)
OOSoundChannel * popChannel()
OOSoundChannel * _channels[kMixerGeneralChannels]