From examples of real sound waves it might seem that trying to use a cosine or sine function to describe a sound wave is pointless because real sound waves ave very complex waveforms. However the French Mathematician Jean Baptiste Joseph Fourier showed any periodic function can be formed from an infinite sum of sines and cosines. This is very convenient because it means that everything we know about sines and cosines applies to a periodic function of any shape. Although the sum is infinite in theory, in many cases using just a few terms may be close enough to provide a good approximation.
Suppose you wanted to make a square wave but only had sine waves to work with. The pictures below were made with the graphing calculator we used earlier. A series of seven sine waves are plotted on the left and the sum of those waves is plotted on the right, below. Although the square wave is not perfect, the more waves that are added, the closer it becomes to a square wave. (You can try this; here is the sum that made the graph on the right: \(1.0\ast\sin (t)+.3333\ast\sin (3\ast t)+.2\ast\sin (5\ast t)+.1428\ast\sin (7\ast t)+.1111\ast\sin (9\ast t)+.0909\ast\sin (11\ast t) +0.0769\ast\sin (13\ast t)\). Try plotting just the first term, then the first two terms, then the first three, etc. )
As you can see from the example of the square wave, any periodic shape can be formed by adding sine waves. This is the concept behind constructing an electronic instrument called a synthesizer. Electric pianos also use this principle. By combining the right frequencies and amplitudes of sine and cosine waves the synthesizer can duplicate the sound wave of any other instrument. The exact electronics the do this are somewhat complicated but the principle is simple; the right combination of sine waves can create the sound of any musical instrument.
Modern synthesizers also often use digitally recorded samples of instruments or other sounds which are electronically modified for output, in addition to pure sine and cosine waves.