Oolite
Loading...
Searching...
No Matches
OOSoundChannel Class Reference

#include <OOALSoundChannel.h>

Inheritance diagram for OOSoundChannel:
Collaboration diagram for OOSoundChannel:

Instance Methods

(void) - update
(void) - setDelegate:
(OOSoundChannel *) - next
(void) - setNext:
(void) - setPosition:
(void) - setGain:
(BOOL) - playSound:looped:
(void) - stop
(OOSound *) - sound
(id) - init [implementation]
(void) - dealloc [implementation]
(void) - getNextSoundBuffer [implementation]
(void) - hasStopped [implementation]
(BOOL) - enqueueBuffer: [implementation]

Protected Attributes

OOSoundChannel * _next
id _delegate
OOSound * _sound
ALuint _buffer
ALuint _lastBuffer
BOOL _bigSound
ALuint _source
BOOL _playing
BOOL _loop

Detailed Description

Definition at line 40 of file OOALSoundChannel.h.

Method Documentation

◆ dealloc

- (void) dealloc
implementation

Definition at line 61 of file OOALSoundChannel.m.

62{
63 [self hasStopped]; // make sure buffers are dequeued and deleted
64 OOAL(alDeleteSources(1, &_source));
65 [super dealloc];
66}
#define OOAL(cmd)
Definition OOOpenAL.h:40

References _source, dealloc, hasStopped, and OOAL.

Referenced by dealloc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ enqueueBuffer:

- (BOOL) enqueueBuffer: (OOSound*) sound
implementation

Provided by category OOSoundChannel(Private).

Definition at line 194 of file OOALSoundChannel.m.

194 :(OOSound*)sound
195{
196 // get sound data
197 _buffer = [sound soundBuffer];
198 // bind sound data to buffer
199 OOAL(alSourceQueueBuffers(_source, 1, &_buffer));
200 ALuint error;
201 if ((error = alGetError()) != AL_NO_ERROR) {
202 OOLog(@"ov.debug", @"Error %u queueing buffers (_source: %u (%p), _buffer: %u (%p))",
203 error, _source, &_source, _buffer, &_buffer);
204 return NO;
205 }
206 ALint playing = 0;
207 OOAL(alGetSourcei(_source, AL_SOURCE_STATE, &playing));
208 if (playing != AL_PLAYING) {
209 OOAL(alSourcePlay(_source));
210 if ((error = alGetError()) != AL_NO_ERROR) {
211 OOLog(@"ov.debug", @"Error %d playing source", error);
212 return NO;
213 }
214 }
215 return YES;
216}
#define OOLog(class, format,...)
Definition OOLogging.h:84
ALuint soundBuffer()
Definition OOALSound.m:148

References OOAL, OOLog, and OOSound::soundBuffer.

Referenced by OOSoundChannel(Private)::getNextSoundBuffer.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getNextSoundBuffer

- (void) getNextSoundBuffer
implementation

Provided by category OOSoundChannel(Private).

Definition at line 89 of file OOALSoundChannel.m.

90{
91 if (!_bigSound) {
92 // we've only loaded one buffer so far
93 _bigSound = YES;
95 [self enqueueBuffer:_sound];
96 } else {
97 // _lastBuffer has something in it, so only queue up
98 // another one if we've finished with that
99 ALint processed = 0;
100 OOAL(alGetSourcei(_source, AL_BUFFERS_PROCESSED, &processed));
101 if (processed > 0) // slot free
102 {
103 // dequeue and delete lastBuffer
104 ALuint buffer;
105 OOAL(alSourceUnqueueBuffers(_source, 1, &buffer));
106 assert(buffer == _lastBuffer);
107 OOAL(alDeleteBuffers(1, &_lastBuffer));
108 // shuffle along, and grab the next bit
110 [self enqueueBuffer:_sound];
111 }
112 }
113}

References enqueueBuffer:, OOSoundChannel(Private)::getNextSoundBuffer, and OOAL.

Referenced by OOSoundChannel(Private)::getNextSoundBuffer, and update.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasStopped

- (void) hasStopped
implementation

Provided by category OOSoundChannel(Private).

Definition at line 168 of file OOALSoundChannel.m.

169{
170 ALint queued;
171 OOAL(alGetSourcei(_source, AL_BUFFERS_QUEUED, &queued));
172
173 while (queued--) {
174 ALuint buffer;
175 OOAL(alSourceUnqueueBuffers(_source, 1, &buffer));
176 }
177
178 OOAL(alDeleteBuffers(1, &_buffer));
179 if (_bigSound) {
180 // then we have two buffers to cleanup
181 OOAL(alDeleteBuffers(1, &_lastBuffer));
182 }
183 _bigSound = NO;
184
185 OOSound* sound = _sound;
186 _sound = nil;
187
188 if (nil != _delegate && [_delegate respondsToSelector:@selector(channel:didFinishPlayingSound:)]) {
189 [_delegate channel:self didFinishPlayingSound:sound];
190 }
191 [sound release];
192}
return nil

References OOSoundChannel(Private)::hasStopped, nil, and OOAL.

Referenced by dealloc, OOSoundChannel(Private)::hasStopped, stop, and update.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init

- (id) init
implementation

Definition at line 43 of file OOALSoundChannel.m.

44{
45 if ((self = [super init])) {
46 ALuint error;
47 OOAL(alGenSources(1, &_source));
48 if ((error = alGetError()) != AL_NO_ERROR) {
49 OOLog(kOOLogSoundInitError, @"%@", @"Could not create OpenAL source");
50 [self release];
51 self = nil;
52 } else {
53 // sources are all relative to listener, defaulting to zero vector
54 OOAL(alSourcei(_source, AL_SOURCE_RELATIVE, AL_TRUE));
55 OOAL(alSource3f(_source, AL_POSITION, 0.0f, 0.0f, 0.0f));
56 }
57 }
58 return self;
59}
static NSString *const kOOLogSoundInitError

References _source, init, kOOLogSoundInitError, nil, OOAL, and OOLog.

Referenced by init.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ next

- (OOSoundChannel *) next

Definition at line 120 of file OOALSoundChannel.m.

121{
122 return _next;
123}
OOSoundChannel * _next

References _next, and next.

Referenced by next, OOSoundMixer::popChannel, and setNext:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ playSound:looped:

- (BOOL) playSound: (OOSound*) sound
looped: (BOOL) loop 

Definition at line 140 of file OOALSoundChannel.m.

140 :(OOSound*)sound looped:(BOOL)loop
141{
142 if (sound == nil)
143 return NO;
144
145 if (_sound != nil)
146 [self stop];
147
148 _loop = loop;
149 _bigSound = NO;
150 [sound rewind];
151 if ([self enqueueBuffer:sound]) {
152 _sound = [sound retain];
153 return YES;
154 } else {
155 return NO;
156 }
157}
void rewind()
Definition OOALSound.m:159

References _bigSound, _loop, _sound, nil, OOSound::rewind, sound, and stop.

Referenced by OOSoundSource::channel:didFinishPlayingSound:, and OOSoundSource::play.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setDelegate:

- (void) setDelegate: (id) delegate

Definition at line 115 of file OOALSoundChannel.m.

115 :(id)delegate
116{
117 _delegate = delegate;
118}

References _delegate.

Referenced by OOSoundSource::channel:didFinishPlayingSound:, OOSoundSource::play, and OOSoundSource::stop.

Here is the caller graph for this function:

◆ setGain:

- (void) setGain: (float) gain

Definition at line 135 of file OOALSoundChannel.m.

135 :(float)gain
136{
137 OOAL(alSourcef(_source, AL_GAIN, gain));
138}

References _source, and OOAL.

Referenced by OOSoundSource::play, and OOSoundSource::setGain:.

Here is the caller graph for this function:

◆ setNext:

- (void) setNext: (OOSoundChannel*) next

Definition at line 125 of file OOALSoundChannel.m.

125 :(OOSoundChannel*)next
126{
127 _next = next;
128}
OOSoundChannel * next()

References _next, and next.

Referenced by OOSoundMixer::popChannel, and OOSoundMixer::pushChannel:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setPosition:

- (void) setPosition: (Vector) vector

Definition at line 130 of file OOALSoundChannel.m.

130 :(Vector)vector
131{
132 OOAL(alSource3f(_source, AL_POSITION, vector.x, vector.y, vector.z));
133}
struct Vector Vector
OOScalar x
Definition OOVector.h:32
OOScalar y
Definition OOVector.h:33
OOScalar z
Definition OOVector.h:34

References _source, OOAL, Vector::x, Vector::y, and Vector::z.

Referenced by OOSoundSource::play, and OOSoundSource::setPosition:.

Here is the caller graph for this function:

◆ sound

- (OOSound *) sound

Definition at line 218 of file OOALSoundChannel.m.

219{
220 return _sound;
221}

References _sound, and sound.

Referenced by playSound:looped:, and sound.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stop

- (void) stop

Definition at line 159 of file OOALSoundChannel.m.

160{
161 if (_sound != nil) {
162 OOAL(alSourceStop(_source));
163 OOAL(alSourcei(_source, AL_BUFFER, AL_NONE));
164 [self hasStopped];
165 }
166}

References _sound, _source, hasStopped, nil, OOAL, and stop.

Referenced by playSound:looped:, stop, and OOSoundSource::stop.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update

- (void) update

Definition at line 68 of file OOALSoundChannel.m.

69{
70 // Check if we've reached the end of a sound.
71 if (_sound != nil) {
72 ALint check;
73 OOAL(alGetSourcei(_source, AL_SOURCE_STATE, &check));
74 if (check == AL_STOPPED) {
75 [self hasStopped];
76 } else if ([_sound soundIncomplete]) // streaming and not finished loading
77 {
78 OOLog(@"sound.buffer", @"Incomplete, trying next for %@", [_sound name]);
79 [self getNextSoundBuffer];
80 } else if (_loop) {
81 OOLog(@"sound.buffer", @"Looping, trying restart for %@", [_sound name]);
82 // sound is complete, but needs to be looped, so start it again
83 [_sound rewind];
84 [self getNextSoundBuffer];
85 }
86 }
87}

References _loop, _sound, _source, getNextSoundBuffer, hasStopped, nil, OOAL, OOLog, OOSound::rewind, and update.

Referenced by update, and OOSoundMixer::update.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _bigSound

- (BOOL) _bigSound
protected

Definition at line 46 of file OOALSoundChannel.h.

Referenced by playSound:looped:.

◆ _buffer

- (ALuint) _buffer
protected

Definition at line 44 of file OOALSoundChannel.h.

◆ _delegate

- (id) _delegate
protected

Definition at line 42 of file OOALSoundChannel.h.

Referenced by setDelegate:.

◆ _lastBuffer

- (ALuint) _lastBuffer
protected

Definition at line 45 of file OOALSoundChannel.h.

◆ _loop

- (BOOL) _loop
protected

Definition at line 49 of file OOALSoundChannel.h.

Referenced by playSound:looped:, and update.

◆ _next

- (OOSoundChannel*) _next
protected

Definition at line 41 of file OOALSoundChannel.h.

Referenced by next, and setNext:.

◆ _playing

- (BOOL) _playing
protected

Definition at line 48 of file OOALSoundChannel.h.

◆ _sound

- (OOSound*) _sound
protected

Definition at line 43 of file OOALSoundChannel.h.

Referenced by playSound:looped:, sound, stop, and update.

◆ _source

- (ALuint) _source
protected

Definition at line 47 of file OOALSoundChannel.h.

Referenced by dealloc, init, setGain:, setPosition:, stop, and update.


The documentation for this class was generated from the following files: