#include <simgear/math/SGMath.hxx>
using std::string;
+using std::vector;
extern bool isNaN(float *v);
// initialize the sound manager
void SGSoundMgr::init(const char *devname) {
- SG_LOG( SG_GENERAL, SG_INFO, "Initializing OpenAL sound manager" );
+ SG_LOG( SG_SOUND, SG_INFO, "Initializing OpenAL sound manager" );
ALCdevice *device = alcOpenDevice(devname);
if ( testForError(device, "Audio device not available, trying default") ) {
}
if (_context != NULL)
- SG_LOG(SG_GENERAL, SG_ALERT, "context is already assigned");
+ SG_LOG(SG_SOUND, SG_ALERT, "context is already assigned");
_context = context;
_working = true;
}
if (_free_sources.size() == 0) {
- SG_LOG(SG_GENERAL, SG_ALERT, "Unable to grab any OpenAL sources!");
+ SG_LOG(SG_SOUND, SG_ALERT, "Unable to grab any OpenAL sources!");
}
}
for (unsigned int i=0; i<_free_sources.size(); i++) {
ALuint source = _free_sources[i];
alDeleteSources( 1 , &source );
+ testForALError("SGSoundMgr::stop: delete sources");
}
_free_sources.clear();
refUint ref = buffers_current->second;
ALuint buffer = ref.id;
alDeleteBuffers(1, &buffer);
+ testForALError("SGSoundMgr::stop: delete buffers");
}
_buffers.clear();
for (unsigned int i=0; i<_free_sources.size(); i++) {
ALuint source = _free_sources[i];
alDeleteSources( 1 , &source );
+ testForALError("SGSoundMgr::unbind: delete sources");
}
_free_sources.clear();
// and hence orientation) of the sources.
//
// The Sound Manager is (and should be) the only one knowing about source
-// management. Sources further away should be suspendped to free resources for
+// management. Sources further away should be suspended to free resources for
// newly added sounds close by.
unsigned int SGSoundMgr::request_source()
{
_sources_in_use.push_back(source);
}
else
- SG_LOG( SG_GENERAL, SG_INFO, "No more free sources available\n");
+ SG_LOG( SG_SOUND, SG_BULK, "Sound manager: No more free sources available!\n");
return source;
}
ALint result;
alGetSourcei( source, AL_SOURCE_STATE, &result );
- if ( result == AL_PLAYING ) {
+ if ( result == AL_PLAYING || result == AL_PAUSED ) {
alSourceStop( source );
}
bool res = load(sample_name, &sample_data, &format, &size, &freq);
if (res == false) return NO_BUFFER;
} catch (sg_exception& e) {
- SG_LOG(SG_GENERAL, SG_ALERT,
- "failed to load sound buffer:" << e.getFormattedMessage());
- return NO_BUFFER;
+ SG_LOG(SG_SOUND, SG_ALERT,
+ "failed to load sound buffer: " << e.getFormattedMessage());
+ sample->set_buffer( SGSoundMgr::FAILED_BUFFER );
+ return FAILED_BUFFER;
}
sample->set_frequency( freq );
// occurs: e.g. -43 on Mac when file is not found.
// In this case, alGetString() sets 'Invalid Enum' error, so
// showing with the original error number is helpful.
- stringstream ss;
+ std::stringstream ss;
ss << alGetString(alGetError()) << "(" << error << ")";
msg.append(ss.str());
}
#endif
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);
}
bool SGSoundMgr::testForError(void *p, string s)
{
if (p == NULL) {
- SG_LOG( SG_GENERAL, SG_ALERT, "Error: " << s);
+ SG_LOG( SG_SOUND, SG_ALERT, "Error: " << s);
return true;
}
return false;
{
ALenum error = alGetError();
if (error != AL_NO_ERROR) {
- SG_LOG( SG_GENERAL, SG_ALERT, "AL Error (sound manager): "
+ SG_LOG( SG_SOUND, SG_ALERT, "AL Error (sound manager): "
<< alGetString(error) << " at " << s);
return true;
}
ALCenum error;
error = alcGetError(_device);
if (error != ALC_NO_ERROR) {
- SG_LOG( SG_GENERAL, SG_ALERT, "ALC Error (sound manager): "
+ SG_LOG( SG_SOUND, SG_ALERT, "ALC Error (sound manager): "
<< alcGetString(_device, error) << " at "
<< s);
return true;
ALenum error;
error = alutGetError ();
if (error != ALUT_ERROR_NO_ERROR) {
- SG_LOG( SG_GENERAL, SG_ALERT, "ALUT Error (sound manager): "
+ SG_LOG( SG_SOUND, SG_ALERT, "ALUT Error (sound manager): "
<< alutGetErrorString(error) << " at "
<< s);
return true;