Sound traveling through air is merely a sequence of high and low pressure zones stacked back to back. When something vibrates to produce sound (like the surface of a bell that has just been rung), the air surrounding the object also gets pushed back and forth. When the bell's surface vibrates outward, it squeezes the air just outside the bell. When it vibrates inward, it rarifies (or "un-squeezes") that same air. As it vibrates back and forth the compressions and rarefactions move outward from the surface of the bell, at the speed of sound. Our eardrums are affected by these compressions and rarefactions, and our nerves transmit the information to our brains, which decode it as sound.
For a little bell, the difference between the compressed air and the rarified air isn't that great, so the sound waves don't carry much potential to vibrate your eardrums. For an cannon, it's a different story.
The energy of the hot gases exiting a cannon push suddenly and violently on the air at the muzzle, and this causes a very high-pressure wave to spread outward. There's a very low-pressure zone right behind that wave, so when these waves hit your eardrum there's a tremendous difference between the compressed air and the rarified air. We hear it as a BANG!
The math:
There are four properties that are characteristic of a sound waves: The velocity, frequency, wavelength, and amplitude. The following equation addresses three of the variables.
velocity = frequency X wavelength the velocity is the velocity of sound about 1118 feet per second at STP. The frequency and wavelength are energy related. Increases in either the frequency or wavelength indicate an increase in energy,
The amplitude and wavelength are caused by the pressure, temperature, and mass of the gas exiting the muzzle. Bigger rocks thrown into a pond at a higher velocity cause bigger waves with a longer frequency.
The frequency or tone is controlled by the duration of the pressure pulse (Time).
The velocity of the gasses exiting a barrel can be expressed as
gas velocity = Pressure X Area X Time/Mass of the Gas
This equation to be solved accurately requires a computer and the use of numerial analysis. However, if we examine the equation we see the following:
The energy contained in the gas:
Energy = 0.5 X (Pressure X Area X Time)^2 / Mass of the Gas
The energy of the gas is increased by Pressure, Area (bore), Time, Mass of the Gas.
Time in this case is the pulse time of the pressure wave.
There is also a secondary explosive sound as the unburnt powder ignites, and if the ball bounces along the barrel there is a ring effect like a bell.