   [SDL] Mix_SetDistance issue
  Hey.I'm using Mix_SetDistance to affect the volume of sounds played. I cache each sound so that there is only ever chunk for the same sound file. I play sounds and call Mix_SetDistance on whatever channel is available:void SDL_Audio_Player::Do_Play_Sound(const std::string& file_name, int channel){    int channel_played = Mix_PlayChannel(channel, audio_cache.Get_Shared_Sound(file_name), 0);    if(channel_played == -1)    { // Bad.throw LRE_Exception(Mix_GetError());    }    else    { // Fine.   channel_playing_map[channel] = true;   LOG("Played sound \"" + file_name + "\" on channel " +  Conversions::to_string(channel_played) + ".");    }}Uint8 SDL_Audio_Player::Calculate_Distance(const Positional_Sound& pos_sound){    Point distance = positional_target->Get_Position() - pos_sound.Get_Position();    // The "flat" or "1-dimensional" distance is pretty simply worked out... it's all we need.    unsigned int dist_avg = abs((distance.x + distance.y) / 2);    // The normalised distance takes into account the strength of positional sound    // and the MAX_AUDIBLE_DISTANCE. Will always be >= 0 (since abs is used above).    return static_cast<Uint8>(get_clamped_max<int>(   dist_avg * MAX_AUDIBLE_DISTANCE / pos_sound_str,   std::numeric_limits<Uint8>::max()));}bool SDL_Audio_Player::Worth_Playing(int distance){    return distance <= MAX_AUDIBLE_DISTANCE;}void SDL_Audio_Player::Do_Play_Positional_Sound(const Positional_Sound& pos_sound){    int channel = Get_First_Free_Channel();    Uint8 distance = Calculate_Distance(pos_sound);    if(Worth_Playing(distance))    {   if(!Mix_SetDistance(channel, static_cast<Uint8>(distance)))   {  throw LRE_Exception(Mix_GetError());   }   else   {  LOG("Set distance to " + Conversions::to_string((int)distance) + ".");   }   Do_Play_Sound(pos_sound.Get_File_Name(), -1);    }}My problem is that when I play a sound repeatedly when the distance is large (and hence the sound should be very quiet) the sound only seems to be as quiet as it should be on one channel, and on the rest it sounds like the distance is not affecting it. Here is a snippet from my game's log (where I was playing the sound repeatedly):Quote:Fri Jun 12 15:33:13: Set distance to 238.Fri Jun 12 15:33:13: Played sound "sound.wav" on channel 0.Fri Jun 12 15:33:14: Set distance to 238.Fri Jun 12 15:33:14: Played sound "sound.wav" on channel 0.Fri Jun 12 15:33:14: Set distance to 238.Fri Jun 12 15:33:14: Played sound "sound.wav" on channel 1.Fri Jun 12 15:33:14: Set distance to 238.Fri Jun 12 15:33:14: Played sound "sound.wav" on channel 2.Fri Jun 12 15:33:14: Set distance to 238.Fri Jun 12 15:33:14: Played sound "sound.wav" on channel 3.Fri Jun 12 15:33:15: Set distance to 238.Fri Jun 12 15:33:15: Played sound "sound.wav" on channel 4.Fri Jun 12 15:33:16: Set distance to 238.Fri Jun 12 15:33:16: Played sound "sound.wav" on channel 0.Fri Jun 12 15:33:16: Set distance to 238.Fri Jun 12 15:33:16: Played sound "sound.wav" on channel 1.Fri Jun 12 15:33:17: Set distance to 238.Fri Jun 12 15:33:17: Played sound "sound.wav" on channel 0.Fri Jun 12 15:33:17: Set distance to 238.Fri Jun 12 15:33:17: Played sound "sound.wav" on channel 1.Fri Jun 12 15:33:18: Set distance to 238.Fri Jun 12 15:33:18: Played sound "sound.wav" on channel 0.Fri Jun 12 15:33:19: Set distance to 238.Fri Jun 12 15:33:19: Played sound "sound.wav" on channel 1.Fri Jun 12 15:33:20: Set distance to 238.Fri Jun 12 15:33:20: Played sound "sound.wav" on channel 0.Fri Jun 12 15:33:20: Set distance to 238.Fri Jun 12 15:33:20: Played sound "sound.wav" on channel 1.Fri Jun 12 15:33:21: Set distance to 238.Fri Jun 12 15:33:21: Played sound "sound.wav" on channel 0.Fri Jun 12 15:33:22: Set distance to 238.Fri Jun 12 15:33:22: Played sound "sound.wav" on channel 0.Fri Jun 12 15:33:22: Set distance to 238.Fri Jun 12 15:33:22: Played sound "sound.wav" on channel 1.Fri Jun 12 15:33:23: Set distance to 238.Fri Jun 12 15:33:23: Played sound "sound.wav" on channel 0.Fri Jun 12 15:33:23: Set distance to 238.Fri Jun 12 15:33:23: Played sound "sound.wav" on channel 2.Fri Jun 12 15:33:24: Set distance to 238.Fri Jun 12 15:33:24: Played sound "sound.wav" on channel 0.Fri Jun 12 15:33:24: Set distance to 238.Fri Jun 12 15:33:24: Played sound "sound.wav" on channel 1.Fri Jun 12 15:33:25: Set distance to 238.Fri Jun 12 15:33:25: Played sound "sound.wav" on channel 2.Fri Jun 12 15:33:25: Set distance to 238.Fri Jun 12 15:33:25: Played sound "sound.wav" on channel 0.Fri Jun 12 15:33:26: Set distance to 238.Fri Jun 12 15:33:26: Played sound "sound.wav" on channel 1.Fri Jun 12 15:33:26: Set distance to 238.Fri Jun 12 15:33:26: Played sound "sound.wav" on channel 0.Fri Jun 12 15:33:27: Set distance to 238.Fri Jun 12 15:33:27: Played sound "sound.wav" on channel 1.Fri Jun 12 15:33:27: Set distance to 238.Fri Jun 12 15:33:27: Played sound "sound.wav" on channel 2.Fri Jun 12 15:33:27: Set distance to 238.Fri Jun 12 15:33:27: Played sound "sound.wav" on channel 0.Fri Jun 12 15:33:28: Set distance to 238.Fri Jun 12 15:33:28: Played sound "sound.wav" on channel 1.Fri Jun 12 15:33:28: Set distance to 238.Fri Jun 12 15:33:28: Played sound "sound.wav" on channel 0.Fri Jun 12 15:33:29: Set distance to 238.Fri Jun 12 15:33:29: Played sound "sound.wav" on channel 1.Fri Jun 12 15:33:29: Set distance to 238.Fri Jun 12 15:33:29: Played sound "sound.wav" on channel 0.Does anyone know what this might be? Would it have anything to do with registering effects on each channel?Cheers.   
 Ok, you are getting an available channel using Get_First_Free_Channel() Then you set the Mix_SetDistance for that channel Then you pass -1 as the channel into Do_Play_Sound ??  why not channel ? Because then you call Mix_PlayChannel, using -1 as the channel for it to play on, which might find a different channel than the one that you Mix_SetDistanced Meaning, if you are playing lots of sound repeatedly, that would cause your problem.. If I were you, I'd also make your output text include what channel is having its distance set, so that you can see the problem... but I imagine that if you replace the -1 in the Do_Play_Sound parameters with channel, it should work.   