You want to create happiness every time the dog hears a sound. Basically, the dog is associating that noise with something bad, but we want the dog to associate the noise of the gun with something good. From a far distance, you can use a launcher system if you'd like, that has a sound and keep it at a far distance. You'll want your dog thinking that everytime he hears a noise, there's a retrieve and the dog is excited about this. Start this from a good distance, and with something like a starter pistol and a live throw. Get the dog excited about this, and then continue to move in, in small intervals. The dog will soon learn that it's a positive association with the sound, and the sound will no longer scare the dog. You want your dog only focusing on the retrieve, as he would if it were a ball. You'll know that the dog is 100% back when you are close enough to him, he has a gun shot beside him, but pays it no mind and only focuses on the retrieve.
Hope this is of help!