static qboolean music_process( ALuint b ) { int l = 0; ALuint format; ALenum error; snd_stream_t *music_stream; start: if( s_bgTrackBuffering ) return qtrue; music_stream = s_bgTrack->stream; if( music_stream ) { l = S_ReadStream( music_stream, MUSIC_BUFFER_SIZE, decode_buffer ); } else { l = 0; } if( !l ) { bgTrack_t *cur; cur = s_bgTrack; if( !S_AdvanceBackgroundTrack( 1 ) ) { if( !S_ValidMusicFile( s_bgTrack ) ) return qfalse; } else { // we've advanced to the next track, close this one S_CloseMusicTrack( cur ); goto start; } if( !S_ResetStream( music_stream ) ) { // if failed, close the track? return qfalse; } goto start; } format = S_SoundFormat( music_stream->info.width, music_stream->info.channels ); qalBufferData( b, format, decode_buffer, l, music_stream->info.rate ); if( ( error = qalGetError() ) != AL_NO_ERROR ) return qfalse; return qtrue; }
bool S_LoadBuffer( sfx_t *sfx ) { ALenum error; void *data; snd_info_t info; ALuint format; if( !sfx ) { return false; } if( sfx->filename[0] == '\0' || sfx->inMemory ) return false; if( trap_FS_IsUrl( sfx->filename ) ) return false; data = S_LoadSound( sfx->filename, &info ); if( !data ) { //Com_DPrintf( "Couldn't load %s\n", sfx->filename ); return false; } if( info.channels > 1 ) { void *temp = stereo_mono( data, &info ); if( temp ) { S_Free( data ); data = temp; } } format = S_SoundFormat( info.width, info.channels ); qalGenBuffers( 1, &sfx->buffer ); if( ( error = qalGetError() ) != AL_NO_ERROR ) { S_Free( data ); Com_Printf( "Couldn't create a sound buffer for %s (%s)\n", sfx->filename, S_ErrorMessage( error ) ); return false; } qalBufferData( sfx->buffer, format, data, info.size, info.rate ); error = qalGetError(); // If we ran out of memory, start evicting the least recently used sounds while( error == AL_OUT_OF_MEMORY ) { if( !buffer_evict() ) { S_Free( data ); Com_Printf( "Out of memory loading %s\n", sfx->filename ); return false; } // Try load it again qalGetError(); qalBufferData( sfx->buffer, format, data, info.size, info.rate ); error = qalGetError(); } // Some other error condition if( error != AL_NO_ERROR ) { S_Free( data ); Com_Printf( "Couldn't fill sound buffer for %s (%s)", sfx->filename, S_ErrorMessage( error ) ); return false; } S_Free( data ); sfx->inMemory = true; return true; }