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