Mix_Volume(sfx, volume);
if(sfx >= 0) Mix_Volume(sfx, volume);
void Object_sfx::set_obj	(	Game_object *o	)	{	Game_window *gwin = Game_window::get_game_window();	Tile_coord apos = gwin->get_main_actor()->get_tile();	Tile_coord opos = o->get_tile();	int active = 0;	if(sfx != -1)	 	active = Mix_Playing(sfx);	int new_distance = apos.distance(opos);	if (active && new_distance >= distance && o != obj)		return;			// Farther than current source.	obj = o;	dir = 0;	bool repeat = true;	distance = new_distance;	int volume = MIX_MAX_VOLUME;	// Set volume based on distance.	if (distance)		{			// 160/8 = 20 tiles. 20*20=400.		volume = (MIX_MAX_VOLUME*64)/(distance*distance);		if (!volume)		// Dead?			repeat = false;	// Time to kill it.		if (volume < 8)			volume = 8;		else if (volume > MIX_MAX_VOLUME)			volume = MIX_MAX_VOLUME;		dir = Get_direction16(apos.ty - opos.ty, opos.tx - apos.tx);		}	if (sfx == -1)		// First time?		{						// Start playing, and repeat.		sfx = Audio::get_ptr()->play_sound_effect(sfxnum, MIX_MAX_VOLUME, dir, -1);		Mix_Volume(sfx, volume);		}	else				// Set new volume, position.		{		//Just change the "location" of the sound		if(!repeat)			{			Mix_HaltChannel(sfx);			sfx = -1;			}		else			{			Mix_Volume(sfx, volume);			Mix_SetPosition(sfx, (dir * 22), 0);			}		}	}