SGSoundSample *sample = sample_current->second;
if ( sample->is_valid_source() ) {
+ ALint source = sample->get_source();
if ( sample->is_playing() ) {
- alSourcePause( sample->get_source() );
+ alSourceStop( source );
+ alSourcei( source, AL_BUFFER, 0 );
}
- _smgr->release_source( sample->get_source() );
+ _smgr->release_source( source );
sample->no_valid_source();
+ }
+ if (sample->is_valid_buffer() ) {
_smgr->release_buffer( sample );
sample->no_valid_buffer();
}
}
- testForALError("suspend");
+ testForALError("stop");
}
// resume playing all associated samples
// stop the sound manager
void SGSoundMgr::stop() {
- if (_working) {
- _working = false;
- _active = false;
- // clear any OpenAL buffers before shutting down
- buffer_map_iterator buffers_current = _buffers.begin();
- buffer_map_iterator buffers_end = _buffers.end();
- for ( ; buffers_current != buffers_end; ++buffers_current ) {
- refUint ref = buffers_current->second;
- ALuint buffer = ref.id;
- alDeleteBuffers(1, &buffer);
- }
- _buffers.clear();
+ // first stop all sample groups
+ sample_group_map_iterator sample_grp_current = _sample_groups.begin();
+ sample_group_map_iterator sample_grp_end = _sample_groups.end();
+ for ( ; sample_grp_current != sample_grp_end; ++sample_grp_current ) {
+ SGSampleGroup *sgrp = sample_grp_current->second;
+ sgrp->stop();
+ }
- sample_group_map_iterator sample_grp_current = _sample_groups.begin();
- sample_group_map_iterator sample_grp_end = _sample_groups.end();
- for ( ; sample_grp_current != sample_grp_end; ++sample_grp_current ) {
- SGSampleGroup *sgrp = sample_grp_current->second;
- sgrp->stop();
- }
+ // clear all OpenAL sources
+ for (unsigned int i=0; i<_free_sources.size(); i++) {
+ ALuint source = _free_sources[i];
+ alDeleteSources( 1 , &source );
+ }
+ _free_sources.clear();
+ // clear any OpenAL buffers before shutting down
+ buffer_map_iterator buffers_current = _buffers.begin();
+ buffer_map_iterator buffers_end = _buffers.end();
+ for ( ; buffers_current != buffers_end; ++buffers_current ) {
+ refUint ref = buffers_current->second;
+ ALuint buffer = ref.id;
+ alDeleteBuffers(1, &buffer);
+ _buffers.erase( buffers_current );
+ }
+ _buffers.clear();
+
+ if (_working) {
+ _working = false;
+ _active = false;
_context = alcGetCurrentContext();
_device = alcGetContextsDevice(_context);
alcDestroyContext(_context);