diff --git a/engine/client/s_main.c b/engine/client/s_main.c index c8e55d97..1162b12a 100644 --- a/engine/client/s_main.c +++ b/engine/client/s_main.c @@ -65,6 +65,50 @@ CVAR_DEFINE_AUTO( s_warn_late_precache, "0", FCVAR_ARCHIVE|FCVAR_FILTERABLE, "wa ============================================================================= */ +static int S_AdjustLoopedSamplePosition( const wavdata_t *source, int current_sample, qboolean enable_looping ) +{ + // check if looping is enabled and we've exceeeded the sample boundary + if( enable_looping && FBitSet( source->flags, SOUND_LOOPED ) && current_sample >= source->samples ) + { + // adjust position relative to loop start + current_sample -= source->loop_start; + + // apply modulo to wrap within loop bounds + int loop_range = source->samples - source->loop_start; + if( loop_range > 0 ) + current_sample = source->loop_start + ( current_sample % loop_range ); + } + + return current_sample; +} + +int S_RetrieveAudioSamples( const wavdata_t *source, const void **output_buffer, int start_position, int num_samples, qboolean enable_looping ) +{ + // handle looping + start_position = S_AdjustLoopedSamplePosition( source, start_position, enable_looping ); + + // calculate how many samples are available from current position + int available_samples = Q_max( 0, source->samples - start_position ); + + // limit requested samples to available samples + if( num_samples > available_samples ) + num_samples = available_samples; + + // if none, exit early + if( num_samples <= 0 ) + return 0; + + // calculate the size of each sample frame + int frame_size = Q_max( 1, source->width * source->channels ); + + // convert sample position to byte offset + start_position *= frame_size; + + *output_buffer = source->buffer + start_position; + + return num_samples; +} + /* ================= S_GetMasterVolume diff --git a/engine/client/s_utils.c b/engine/client/s_utils.c deleted file mode 100644 index 3efcd749..00000000 --- a/engine/client/s_utils.c +++ /dev/null @@ -1,61 +0,0 @@ -/* -s_utils.c - common sound functions -Copyright (C) 2009 Uncle Mike - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. -*/ - -#include "common.h" -#include "sound.h" - -int S_AdjustLoopedSamplePosition( const wavdata_t *source, int current_sample, qboolean enable_looping ) -{ - // check if looping is enabled and we've exceeeded the sample boundary - if( enable_looping && FBitSet( source->flags, SOUND_LOOPED ) && current_sample >= source->samples ) - { - // adjust position relative to loop start - current_sample -= source->loop_start; - - // apply modulo to wrap within loop bounds - int loop_range = source->samples - source->loop_start; - if( loop_range > 0 ) - current_sample = source->loop_start + ( current_sample % loop_range ); - } - - return current_sample; -} - -int S_RetrieveAudioSamples( const wavdata_t *source, const void **output_buffer, int start_position, int num_samples, qboolean enable_looping ) -{ - // handle looping - start_position = S_AdjustLoopedSamplePosition( source, start_position, enable_looping ); - - // calculate how many samples are available from current position - int available_samples = Q_max( 0, source->samples - start_position ); - - // limit requested samples to available samples - if( num_samples > available_samples ) - num_samples = available_samples; - - // if none, exit early - if( num_samples <= 0 ) - return 0; - - // calculate the size of each sample frame - int frame_size = Q_max( 1, source->width * source->channels ); - - // convert sample position to byte offset - start_position *= frame_size; - - *output_buffer = source->buffer + start_position; - - return num_samples; -} diff --git a/engine/client/sound.h b/engine/client/sound.h index 62c7f4a0..a0b0bbf1 100644 --- a/engine/client/sound.h +++ b/engine/client/sound.h @@ -170,6 +170,7 @@ float S_GetMusicVolume( void ); // // s_main.c // +int S_RetrieveAudioSamples( const wavdata_t *source, const void **output_buffer, int start_position, int num_samples, qboolean enable_looping ); void S_FreeChannel( channel_t *ch ); // @@ -255,12 +256,6 @@ void S_StreamBackgroundTrack( void ); void S_PrintBackgroundTrackState( void ); void S_MusicFade( float fade_percent ); -// -// s_utils.c -// -int S_AdjustLoopedSamplePosition( const wavdata_t *source, int current_sample, qboolean enable_looping ); -int S_RetrieveAudioSamples( const wavdata_t *source, const void **output_buffer, int start_position, int num_samples, qboolean enable_looping ); - // // s_vox.c //