OPAL_SOUND_MGR bool SoundManager::loadAudio( std::string filename, unsigned int *audioId, bool loop ) { if ( filename.empty() || filename.length() > MAX_FILENAME_LENGTH ) return false; if ( mAudioSourcesInUseCount == MAX_AUDIO_SOURCES ) return false; // out of Audio Source slots! int bufferID = -1; // Identity of the Sound Buffer to use int sourceID = -1; // Identity of the Source Buffer to use alGetError(); // Clear Error Code // Check and see if the pSoundFile is already loaded into a buffer bufferID = locateAudioBuffer( filename ); if ( bufferID < 0 ) { // The sound file isn't loaded in a buffer, lets attempt to load it on the fly bufferID = loadAudioInToSystem( filename ); if ( bufferID < 0 ) return false; // failed! } // If you are here, the sound the requester wants to reference is in a buffer. // Now, we need to find a free Audio Source slot in the sound system sourceID = 0; while ( mAudioSourceInUse[ sourceID ] == true ) sourceID++; // When you are here, 'mSourceID' now represents a free Audio Source slot // The free slot may not be at the end of the array but in the middle of it. *audioId = sourceID; // return the Audio Source ID to the caller mAudioSourceInUse[ sourceID ] = true; // mark this Source slot as in use mAudioSourcesInUseCount++; // bump the 'in use' counter // Now inform OpenAL of the sound assignment and attach the audio buffer // to the audio source alSourcei( mAudioSources[sourceID], AL_BUFFER, mAudioBuffers[bufferID] ); // Steven : Not in the original code !!!!! alSourcei( mAudioSources[sourceID], AL_LOOPING, loop ); if ( checkALError( "loadSource()::alSourcei" ) ) return false; return true; }
bool SoundManager::loadDefaultSounds( std::string filename ) { FILE *myfile; unsigned linecount=0; char key[255], buff[512]; if ( (myfile = fopen( filename.c_str() ,"r") )==NULL ) { sprintf(buff, "---> Can't Open File: %s\n", filename.c_str() ); printf( "SoundManager::loadDefaultSounds : %s\n", buff ); return false; } fseek(myfile,0L,SEEK_SET); // Make sure we are at the begining of the file while (!feof(myfile)) { fgets(buff,sizeof(buff),myfile); // Read a line from the file. linecount++; if (strncmp(buff,"#",1) && // Is this a comment line? strncmp(buff,"",1) && strncmp(buff,"/",1)) { // We have some data, attempt to load it strcpy(key,buff); trimTrailingSpace(key); // First, make sure it isn't already loaded if ( locateAudioBuffer( key ) < 0 ) { // Nope, its not already loaded if ( loadAudioInToSystem( key ) < 0 ) { sprintf(buff,"Can't load audio file: %s\n",key); printf( "SoundManager::loadDefaultSounds() : %s\n", buff ); } } } } // Were done fclose(myfile); return true; }