volume = max_volume - sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));

That's a pretty bad answer...

You want to decide on a falloff function. Physics dictates that the sound volume should be proportional to 1/distance^2. If you want to cut it off completely at some point, you should probably get a smooth function that roughly looks like 1/distance^2 but reaches 0 at the desired distance and doesn't have a discontinuity. For instance

volume = reference_volume * max(1/distance_squared - 1/max_distance_squared, 0);

I think it depends some on what a person wants from the sound-source.

for example, the falloff can be used to various effects for different kinds of things, like say, for the sound of a general area (such as a crowd of people or a large room), you might want square-root falloff, but for the ambient noises of a chirping console, you might want squared falloff, and for a character making noise (speaking, yelling, ...), a linear falloff might be better.

for example, in my mixer, there are multiple levels of attenuation:

none, same volume everywhere in the world;

low, square-root falloff (sqrt(volume/dist));

default, linear falloff (volume/dist);

high, square falloff (volume/dist^2).

note that the minimum value for distance is 1.

the sound is skipped if the calculated volume falls below 0.001, and there is also some math to handle things like panning and Doppler shifting and similar (basically, tweaking playback speeds based on relative velocities).

generally, some of these calculations also take relative camera orientation into effect as well, such as things may be slightly louder in-front than above or behind, and things generally above/below will be closer to center-pan than ones at roughly the same height.