Oolite 1.91.0.7645-241119-222d325
Loading...
Searching...
No Matches
OOOpenALController.m
Go to the documentation of this file.
1/*
2
3OOOpenALController.m
4
5
6Oolite
7Copyright (C) 2004-2013 Giles C Williams and contributors
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22MA 02110-1301, USA.
23
24*/
25
27#import "OOLogging.h"
28#import "OOALSoundMixer.h"
29
30static id sSingleton = nil;
31
32@implementation OOOpenALController
33
35{
36 if (sSingleton == nil)
37 {
38 sSingleton = [[self alloc] init];
39 }
40
41 return sSingleton;
42}
43
44
45- (id) init
46{
47 self = [super init];
48 if (self != nil)
49 {
50 NSArray *arguments = nil;
51 NSEnumerator *argEnum = nil;
52 NSString *arg = nil;
53
54 arguments = [[NSProcessInfo processInfo] arguments];
55 for (argEnum = [arguments objectEnumerator]; (arg = [argEnum nextObject]); )
56 {
57 if ([arg isEqual:@"-nosound"] || [arg isEqual:@"--nosound"])
58 {
59 [self release];
60 return nil;
61 }
62 }
63
64 ALuint error;
65 device = alcOpenDevice(NULL); // default device
66 if (!device)
67 {
68 OOLog(kOOLogSoundInitError, @"%@", @"Failed to open default sound device");
69 [self release];
70 return nil;
71 }
72 context = alcCreateContext(device,NULL); // default context
73 if (!alcMakeContextCurrent(context))
74 {
75 OOLog(kOOLogSoundInitError, @"%@", @"Failed to create default sound context");
76 [self release];
77 return nil;
78 }
79 if ((error = alGetError()) != AL_NO_ERROR)
80 {
81 OOLog(kOOLogSoundInitError,@"Error %d creating sound context",error);
82 }
83 OOAL(alDistanceModel(AL_NONE));
84 }
85 return self;
86}
87
88
89- (void) setMasterVolume:(ALfloat) fraction
90{
91 OOAL(alListenerf(AL_GAIN,fraction));
92}
93
94- (ALfloat) masterVolume
95{
96 ALfloat fraction = 0.0;
97 OOAL(alGetListenerf(AL_GAIN,&fraction));
98 return fraction;
99}
100
101// only to be called at app shutdown
102// is there a better way to handle this?
103- (void) shutdown
104{
105 [[OOSoundMixer sharedMixer] shutdown];
106 OOAL(alcMakeContextCurrent(NULL));
107 OOAL(alcDestroyContext(context));
108 OOAL(alcCloseDevice(device));
109}
110
111@end
static OODebugMonitor * sSingleton
#define OOLog(class, format,...)
Definition OOLogging.h:88
static NSString *const kOOLogSoundInitError
static id sSingleton
#define OOAL(cmd)
Definition OOOpenAL.h:40
return nil
OOOpenALController * sharedController()