Oolite
1.91.0.7659-250410-0031890
Toggle main menu visibility
Main Page
Topics
Classes
Class List
Class Index
Class Hierarchy
Class Members
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Properties
Files
File List
File Members
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Typedefs
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
q
r
s
t
u
v
z
Enumerations
g
k
m
o
r
s
t
w
Enumerator
a
b
c
d
e
g
j
k
m
n
o
p
r
s
t
u
w
Macros
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
x
y
z
•
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Macros
Modules
Pages
Loading...
Searching...
No Matches
src
Core
OOALStreamedSound.m
Go to the documentation of this file.
1
/*
2
3
OOALStreamedSound.m
4
5
6
OOALStreamedSound - OpenAL sound implementation for Oolite.
7
Copyright (C) 2005-2013 Jens Ayton
8
9
Permission is hereby granted, free of charge, to any person obtaining a copy
10
of this software and associated documentation files (the "Software"), to deal
11
in the Software without restriction, including without limitation the rights
12
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
copies of the Software, and to permit persons to whom the Software is
14
furnished to do so, subject to the following conditions:
15
16
The above copyright notice and this permission notice shall be included in all
17
copies or substantial portions of the Software.
18
19
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
SOFTWARE.
26
27
*/
28
29
#import "
OOALStreamedSound.h
"
30
#import "
OOALSoundDecoder.h
"
31
32
@implementation
OOALStreamedSound
33
34
- (void)
dealloc
35
{
36
free(
_buffer
);
37
_buffer
= NULL;
38
[
decoder
release];
39
40
[
super
dealloc];
41
}
34
- (void)
dealloc
{
…
}
42
43
- (NSString *)
name
44
{
45
return
_name
;
46
}
43
- (NSString *)
name
{
…
}
47
48
49
50
- (id)initWithDecoder:(
OOALSoundDecoder
*)inDecoder
51
{
52
BOOL OK = YES;
53
54
[
OOSound
setUp
];
55
if
(![
OOSound
isSoundOK
] ||
nil
== inDecoder) OK = NO;
56
57
if
(OK)
58
{
59
self
= [
super
init
];
60
if
(
nil
==
self
) OK = NO;
61
}
62
63
if
(OK)
64
{
65
_name
= [[
inDecoder
name
] copy];
66
_sampleRate
= [
inDecoder
sampleRate
];
67
_stereo
= [
inDecoder
isStereo
];
68
_reachedEnd
= NO;
69
_buffer
= malloc(
OOAL_STREAM_CHUNK_SIZE
);
70
decoder
= [
inDecoder
retain];
71
[
self
rewind
];
72
}
73
74
if
(!OK)
75
{
76
[
self
release];
77
self
=
nil
;
78
}
79
return
self
;
80
}
50
- (id)initWithDecoder:(
OOALSoundDecoder
*)inDecoder {
…
}
81
82
83
- (void)
rewind
84
{
85
[
decoder
reset
];
86
_reachedEnd
= NO;
87
}
83
- (void)
rewind
{
…
}
88
89
90
- (BOOL)
soundIncomplete
91
{
92
return
!
_reachedEnd
;
93
}
90
- (BOOL)
soundIncomplete
{
…
}
94
95
96
- (ALuint)
soundBuffer
97
{
98
size_t
transferred = [
decoder
streamToBuffer
:_buffer];
99
if
(transferred <
OOAL_STREAM_CHUNK_SIZE
)
100
{
101
// otherwise keep going
102
_reachedEnd
= YES;
103
}
104
105
ALuint buffer;
106
ALint error;
107
OOAL
(alGenBuffers(1,&buffer));
108
if
((error = alGetError()) != AL_NO_ERROR)
109
{
110
OOLog
(
kOOLogSoundLoadingError
,
@"%@"
,
@"Could not create OpenAL buffer"
);
111
return
0;
112
}
113
else
114
{
115
if
(!
_stereo
)
116
{
117
alBufferData(buffer, AL_FORMAT_MONO16,
_buffer
, (ALsizei)transferred,
_sampleRate
);
118
}
119
else
120
{
121
alBufferData(buffer, AL_FORMAT_STEREO16,
_buffer
, (ALsizei)transferred,
_sampleRate
);
122
}
123
return
buffer;
124
}
125
}
96
- (ALuint)
soundBuffer
{
…
}
126
127
@end
OOALSoundDecoder.h
OOAL_STREAM_CHUNK_SIZE
#define OOAL_STREAM_CHUNK_SIZE
Definition
OOALSoundDecoder.h:35
OOALStreamedSound.h
OOLog
#define OOLog(class, format,...)
Definition
OOLogging.h:88
kOOLogSoundLoadingError
static NSString *const kOOLogSoundLoadingError
Definition
OOOpenALController.h:32
OOAL
#define OOAL(cmd)
Definition
OOOpenAL.h:40
nil
return nil
Definition
OOProbabilitySet.m:449
OOALSoundDecoder
Definition
OOALSoundDecoder.h:38
-[OOALSoundDecoder streamToBuffer:]
size_t streamToBuffer:(char *buffer)
Definition
OOALSoundDecoder.m:87
-[OOALSoundDecoder isStereo]
BOOL isStereo()
Definition
OOALSoundDecoder.m:108
-[OOALSoundDecoder reset]
void reset()
Definition
OOALSoundDecoder.m:120
-[OOALSoundDecoder name]
NSString * name()
Definition
OOALSoundDecoder.m:126
-[OOALSoundDecoder sampleRate]
long sampleRate()
Definition
OOALSoundDecoder.m:114
OOALStreamedSound
Definition
OOALStreamedSound.h:31
OOALStreamedSound::_name
NSString * _name
Definition
OOALStreamedSound.h:36
OOALStreamedSound::decoder
OOALSoundDecoder * decoder
Definition
OOALStreamedSound.h:38
OOALStreamedSound::_sampleRate
double _sampleRate
Definition
OOALStreamedSound.h:35
-[OOALStreamedSound rewind]
void rewind()
Definition
OOALStreamedSound.m:83
-[OOALStreamedSound name]
NSString * name()
Definition
OOALStreamedSound.m:43
-[OOALStreamedSound soundBuffer]
ALuint soundBuffer()
Definition
OOALStreamedSound.m:96
-[OOALStreamedSound dealloc]
void dealloc()
Definition
OOALStreamedSound.m:34
OOALStreamedSound::_buffer
char * _buffer
Definition
OOALStreamedSound.h:33
OOALStreamedSound::_reachedEnd
BOOL _reachedEnd
Definition
OOALStreamedSound.h:39
OOALStreamedSound::_stereo
BOOL _stereo
Definition
OOALStreamedSound.h:37
-[OOALStreamedSound soundIncomplete]
BOOL soundIncomplete()
Definition
OOALStreamedSound.m:90
OOSound
Definition
OOALSound.h:31
-[OOSound init]
id init()
Definition
OOALSound.m:90
+[OOSound isSoundOK]
BOOL isSoundOK()
Definition
OOALSound.m:156
+[OOSound setUp]
BOOL setUp()
Definition
OOALSound.m:46
Generated by
1.13.2