Control L/R Channels of Sound

I don’t care if I have to use EmitSound or CSoundPatch or something else, but I have to control the L/R Channels of a sound. Weapon sounds (npc versions) play the near-the-weapon sound in the left channel, and the far-from-the-weapon sound in the right ear, and it blends them based on the distance a player is from a weapon. I’m trying to make that effect in a SWEP, where it blends the L/R channels to make it sound different based on your distance to the gun, how can I do it? (you can see this in action just by spawning some npcs and going near them while they shoot at you, then really far, it sounds clearly different.)