- SGPath samplepath( path );
- if ( strlen(file) ) {
- samplepath.append( file );
- }
-
- SG_LOG( SG_GENERAL, SG_ALERT, "From file sounds sample = "
- << samplepath.str() );
-
- ALuint error;
-
- source_pos[0] = 0.0; source_pos[1] = 0.0; source_pos[2] = 0.0;
- source_vel[0] = 0.0; source_vel[1] = 0.0; source_vel[2] = 0.0;
-
- // clear errors from elsewhere?
- alGetError();
-
- // create an OpenAL buffer handle
- alGenBuffers(1, &buffer);
- error = alGetError();
- if ( error != AL_NO_ERROR ) {
- print_openal_error( error );
- throw sg_exception("Failed to gen OpenAL buffer.");
- } else {
- SG_LOG( SG_GENERAL, SG_ALERT, "Buffer created ok!" );
- }
-
- // Load the sample file
- alutLoadWAVFile( (ALbyte *)samplepath.c_str(),
- &format, &data, &size, &freq, &loop );
- if (alGetError() != AL_NO_ERROR) {
- throw sg_exception("Failed to load wav file.");
- }
-
- // Copy data to the internal OpenAL buffer
- alBufferData( buffer, format, data, size, freq );
- if (alGetError() != AL_NO_ERROR) {
- throw sg_exception("Failed to buffer data.");
- }
-
- alutUnloadWAV( format, data, size, freq );
-
- // Bind buffer with a source.
- alGenSources(1, &source);
- if (alGetError() != AL_NO_ERROR) {
- throw sg_exception("Failed to gen source.");
- }
-
- alSourcei( source, AL_BUFFER, buffer );
- alSourcef( source, AL_PITCH, pitch );
- alSourcef( source, AL_GAIN, volume );
- alSourcefv( source, AL_POSITION, source_pos );
- alSourcefv( source, AL_VELOCITY, source_vel );
- alSourcei( source, AL_LOOPING, loop );