I play with python wave module, and read some articles about digital audio, but still do not understand how the data are sufficient.

The digital data is an array of amplitude vs. time. For 1s mono audio with a rate of 22050, I have the amplitude values at 22050 points (1/22050 s intervals).

This curve represents how the loudness is changed over 1s time. But how is this curve different if the 1s audio is a play of A note on a piano or E note?

I expected that at each frame (1/22050 s interval) we have a set of data for amplitude vs. frequency, since a sound is a combination of various frequencies (having different loudness).

How a set of 22050 numbers can produce different 1s audios (zillion number of different sounds)?


closed as off-topic by Aaron Stevens, Thomas Fritsch, ZeroTheHero, John Rennie, PM 2Ring Sep 22 at 15:21

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question appears to be about engineering, which is the application of scientific knowledge to construct a solution to solve a specific problem. As such, it is off topic for this site, which deals with the science, whether theoretical or experimental, of how the natural world works. For more information, see this meta post." – Aaron Stevens, Thomas Fritsch, ZeroTheHero, John Rennie, PM 2Ring
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ If the data is 16 bits per sample, so that each sample can be one of $2^{16}=65536$ different values, then 22050 samples can represent $65536^{22050}$ different 1-second sounds. That is well more than a zillion. $\endgroup$ – G. Smith Sep 21 at 17:35
  • $\begingroup$ @G.Smith sure a time-series of 22050 points has a wide range of unique combinations, but I don't understand how the mere sequence of amplitudes can represent a sound. $\endgroup$ – Googlebot Sep 21 at 18:45
  • $\begingroup$ You will need encoding for the amplitude and the frequency. $\endgroup$ – David White Sep 21 at 18:49
  • $\begingroup$ Is this a physics question? $\endgroup$ – Aaron Stevens Sep 21 at 19:23
  • $\begingroup$ FWIW, here is a little snippet of Python 3 code that uses the wave module. It uses the Karplus-Strong algorithm to synthesize a string sound, saving the result as a .wav file. You can call it like save_wave(kastro(440)) $\endgroup$ – PM 2Ring Sep 22 at 15:11

The important point you are missing in this process is digitization. Here is a simplified explanation. In what follows we assume no data encoding nor data compression.

Imagine first we start with a very low frequency signal, say a sine wave at 1Hz. We sample this waveform at your sample rate of 22050 samples per second. We now have a data file consisting of 22050 sequential amplitude measurements or "slices" of a 1Hz sine wave which starts at zero, climbs to a maximum, falls to a minimum, and ends up at zero again, during one second.

Now we look at each sample number and convert it from an analog voltage measurement in base-10 decimal to a binary number between, say, 0 and 256. Now we have a file consisting of 22050 binary numbers in sequence, each of which is an 8-bit binary number.

Let's make a chart of these numbers, with time slices on the x-axis and those bit counts on the y-axis with one string for each time slice. If we draw a little line between the peaks of each adjacent pair of bit counts we get a replica of the sine wave consisting of 22050 little straight lines that rise up and fall down to follow the outline of the original sine wave.

Now you can see that if we started out with a different frequency sine wave, say 100Hz, we get a similar file of 22050 time slices, each of which is a 256-bit binary number representing the instantaneous height of the 100Hz sine wave. That wave rises and falls 100 times in one second, and if we "connect the dots" as in the first example, we get back a graph of 22015 little straight-line segments that rise and fall and which looks pretty much like the 100Hz sine wave we started with.

This means that we can sample a whole range of different frequencies in this way, and when we "play them back" by making that graph, we get a replica of the waveform we started with.

  • $\begingroup$ WAV files typically use 16 bits per sample (per channel), not 256 bits. $\endgroup$ – PM 2Ring Sep 21 at 20:28
  • $\begingroup$ There are a number of different standards. I arbitrarily used 256 for my example. $\endgroup$ – niels nielsen Sep 22 at 3:58
  • $\begingroup$ If you're using binary numbers in the range from 0 to 255 (inclusive), then you need 8 bits. That was common for audio on computers in the 80s & early 90s, like the C64 & Amiga. Standard CDs use 16 bit samples. Sound editing programs like Audacity normally use 32 bit floating point, to give plenty of margin for rounding errors. 256 bit audio samples is overkill. It's far in excess of what human ears could possibly detect, and it's way beyond our technology to convert such precision to an analog signal: 256 bits is approximately equal to 77 decimal places! $\endgroup$ – PM 2Ring Sep 22 at 14:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.