Oolite
Loading...
Searching...
No Matches
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
}
42
43
- (NSString*)
name
44
{
45
return
_name
;
46
}
47
48
- (id)initWithDecoder:(
OOALSoundDecoder
*)inDecoder
49
{
50
BOOL OK = YES;
51
52
[
OOSound
setUp
];
53
if
(![
OOSound
isSoundOK
] ||
nil
== inDecoder)
54
OK = NO;
55
56
if
(OK) {
57
self
= [
super
init
];
58
if
(
nil
==
self
)
59
OK = NO;
60
}
61
62
if
(OK) {
63
_name
= [[
inDecoder
name
] copy];
64
_sampleRate
= [
inDecoder
sampleRate
];
65
_stereo
= [
inDecoder
isStereo
];
66
_reachedEnd
= NO;
67
_buffer
= malloc(
OOAL_STREAM_CHUNK_SIZE
);
68
decoder
= [
inDecoder
retain];
69
[
self
rewind
];
70
}
71
72
if
(!OK) {
73
[
self
release];
74
self
=
nil
;
75
}
76
return
self
;
77
}
78
79
- (void)
rewind
80
{
81
[
decoder
reset
];
82
_reachedEnd
= NO;
83
}
84
85
- (BOOL)
soundIncomplete
86
{
87
return
!
_reachedEnd
;
88
}
89
90
- (ALuint)
soundBuffer
91
{
92
size_t
transferred = [
decoder
streamToBuffer
:_buffer];
93
if
(transferred <
OOAL_STREAM_CHUNK_SIZE
) {
94
// otherwise keep going
95
_reachedEnd
= YES;
96
}
97
98
ALuint buffer;
99
ALint error;
100
OOAL
(alGenBuffers(1, &buffer));
101
if
((error = alGetError()) != AL_NO_ERROR) {
102
OOLog
(
kOOLogSoundLoadingError
,
@"%@"
,
@"Could not create OpenAL buffer"
);
103
return
0;
104
}
else
{
105
if
(!
_stereo
) {
106
alBufferData(buffer, AL_FORMAT_MONO16,
_buffer
, (ALsizei)transferred,
_sampleRate
);
107
}
else
{
108
alBufferData(buffer, AL_FORMAT_STEREO16,
_buffer
, (ALsizei)transferred,
_sampleRate
);
109
}
110
return
buffer;
111
}
112
}
113
114
@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:84
kOOLogSoundLoadingError
static NSString *const kOOLogSoundLoadingError
Definition
OOOpenALController.h:31
OOAL
#define OOAL(cmd)
Definition
OOOpenAL.h:40
nil
return nil
Definition
OOProbabilitySet.m:393
OOALSoundDecoder
Definition
OOALSoundDecoder.h:38
-[OOALSoundDecoder streamToBuffer:]
size_t streamToBuffer:(char *buffer)
Definition
OOALSoundDecoder.m:80
-[OOALSoundDecoder isStereo]
BOOL isStereo()
Definition
OOALSoundDecoder.m:100
-[OOALSoundDecoder reset]
void reset()
Definition
OOALSoundDecoder.m:110
-[OOALSoundDecoder name]
NSString * name()
Definition
OOALSoundDecoder.m:115
-[OOALSoundDecoder sampleRate]
long sampleRate()
Definition
OOALSoundDecoder.m:105
OOALStreamedSound
Definition
OOALStreamedSound.h:30
OOALStreamedSound::_name
NSString * _name
Definition
OOALStreamedSound.h:35
OOALStreamedSound::decoder
OOALSoundDecoder * decoder
Definition
OOALStreamedSound.h:37
OOALStreamedSound::_sampleRate
double _sampleRate
Definition
OOALStreamedSound.h:34
-[OOALStreamedSound rewind]
void rewind()
Definition
OOALStreamedSound.m:79
-[OOALStreamedSound name]
NSString * name()
Definition
OOALStreamedSound.m:43
-[OOALStreamedSound soundBuffer]
ALuint soundBuffer()
Definition
OOALStreamedSound.m:90
-[OOALStreamedSound dealloc]
void dealloc()
Definition
OOALStreamedSound.m:34
OOALStreamedSound::_buffer
char * _buffer
Definition
OOALStreamedSound.h:32
OOALStreamedSound::_reachedEnd
BOOL _reachedEnd
Definition
OOALStreamedSound.h:38
OOALStreamedSound::_stereo
BOOL _stereo
Definition
OOALStreamedSound.h:36
-[OOALStreamedSound soundIncomplete]
BOOL soundIncomplete()
Definition
OOALStreamedSound.m:85
OOSound
Definition
OOALSound.h:31
-[OOSound init]
id init()
Definition
OOALSound.m:84
+[OOSound isSoundOK]
BOOL isSoundOK()
Definition
OOALSound.m:143
+[OOSound setUp]
BOOL setUp()
Definition
OOALSound.m:46
src
Core
OOALStreamedSound.m
Generated by
1.15.0