- SGPath samplepath( path );
- if ( strlen(file) ) {
- samplepath.append( file );
- }
- sample_name = samplepath.str();
-
- SG_LOG( SG_GENERAL, SG_DEBUG, "From file sounds sample = "
- << samplepath.str() );
-
- source_pos[0] = 0.0; source_pos[1] = 0.0; source_pos[2] = 0.0;
- offset_pos[0] = 0.0; offset_pos[1] = 0.0; offset_pos[2] = 0.0;
- source_vel[0] = 0.0; source_vel[1] = 0.0; source_vel[2] = 0.0;
- direction[0] = 0.0; direction[1] = 0.0; direction[2] = 0.0;
- inner = outer = 360.0; outergain = 0.0;
-
- // clear errors from elsewhere?
- alGetError();
-
- // create an OpenAL buffer handle
- alGenBuffers(1, &buffer);
- if ( print_openal_error("constructor (alGenBuffers)") ) {
- throw sg_exception("Failed to gen OpenAL buffer.");
- }
-
- // Load the sample file
-#if defined(ALUT_API_MAJOR_VERSION) && ALUT_API_MAJOR_VERSION >= 1
-
- buffer = alutCreateBufferFromFile(samplepath.c_str());
- if (buffer == AL_NONE) {
- ALenum error = alutGetError ();
- print_openal_error("constructor (alutCreateBufferFromFile)");
- throw sg_exception("Failed to load wav file: "+string(alutGetErrorString (error)));
- }
-
-#else
- //
- // pre 1.0 alut version
- //
- ALvoid* data = load_file(path, file);
-
- // Copy data to the internal OpenAL buffer
- alBufferData( buffer, format, data, size, freq );
-
- if ( print_openal_error("constructor (alBufferData)") ) {
- throw sg_exception("Failed to buffer data.");
- }
-
- alutUnloadWAV( format, data, size, freq );
-#endif
-
- print_openal_error("constructor return");