Lots of variables. If working power as on a grade or when accelerating tonnage, the engines are in run 8. It doesn't get louder than that from the engine alone.
If in dynamic brake as descending a grade or reducing speed, although a different sound it also very weak by comparison.
If drifting along, one can sneak up on you until very close.
Determine that first and then ambient conditions (temperature, barometric pressure, ie altitude, humidity, wind strength and direction) which have a great effect on propagation of sound waves.
By way of example, if there is substantial snow on the ground it sucks up the sound like a huge audio sponge. And, it plugs up the throat of the whistle as well during heavy snowfall to such a degree that it only emits a pitiful squeak if any sound at all.
That is why in real life or fiction, ya gotta pay attention. And, that is also why "Look" is a part of the safety mantra: Look, Listen, Live. You may not hear a train at all in many circumstances and Look is your safety valve.
Thanks for the opportunity to bang the safety drum.