Properly handle stereo wav files; remove data buffer and set buffer to FAILED_BUFFER

This commit is contained in:
Erik Hofman 2011-12-07 10:41:57 +01:00
parent 97fcf48caa
commit ff2eb6d2d3
3 changed files with 10 additions and 5 deletions

View File

@ -157,14 +157,16 @@ void SGSampleGroup::update( double dt ) {
} }
else else
{ {
if (_smgr->request_buffer(sample) == SGSoundMgr::NO_BUFFER) ALuint buffer = _smgr->request_buffer(sample);
if (buffer == SGSoundMgr::FAILED_BUFFER ||
buffer == SGSoundMgr::NO_BUFFER)
{ {
_smgr->release_source(source); _smgr->release_source(source);
continue; continue;
} }
// start playing the sample // start playing the sample
ALuint buffer = sample->get_buffer(); buffer = sample->get_buffer();
if ( alIsBuffer(buffer) == AL_TRUE ) if ( alIsBuffer(buffer) == AL_TRUE )
{ {
alSourcei( source, AL_BUFFER, buffer ); alSourcei( source, AL_BUFFER, buffer );

View File

@ -482,7 +482,8 @@ unsigned int SGSoundMgr::request_buffer(SGSoundSample *sample)
} catch (sg_exception& e) { } catch (sg_exception& e) {
SG_LOG(SG_GENERAL, SG_ALERT, SG_LOG(SG_GENERAL, SG_ALERT,
"failed to load sound buffer: " << e.getFormattedMessage()); "failed to load sound buffer: " << e.getFormattedMessage());
return NO_BUFFER; sample->set_buffer( SGSoundMgr::FAILED_BUFFER );
return FAILED_BUFFER;
} }
sample->set_frequency( freq ); sample->set_frequency( freq );
@ -618,6 +619,7 @@ bool SGSoundMgr::load(string &samplepath, void **dbuf, int *fmt,
#endif #endif
if (format == AL_FORMAT_STEREO8 || format == AL_FORMAT_STEREO16) { if (format == AL_FORMAT_STEREO8 || format == AL_FORMAT_STEREO16) {
free(data);
throw sg_io_exception("Warning: STEREO files are not supported for 3D audio effects: " + samplepath); throw sg_io_exception("Warning: STEREO files are not supported for 3D audio effects: " + samplepath);
} }

View File

@ -200,7 +200,8 @@ public:
enum { enum {
NO_SOURCE = (unsigned int)-1, NO_SOURCE = (unsigned int)-1,
NO_BUFFER = (unsigned int)-1 NO_BUFFER = (unsigned int)-1,
FAILED_BUFFER = (unsigned int)-2
}; };
/** /**