This program generates sound.
What is sound? Sound is essentially air molecules travelling away from its source in pockets of high and low pressure. Humans can "hear" sound, because the ear drums are able to detect the sound waves.
How is sound generated? A loud speaker can generate sound by moving a diaphragm back and forth. The diagram in the loudspeaker is connected to an electromagnet, which can be moved forward and backwards to create the sound waves in the air.
How does a computer generate sound? A digital-to-analog converter (DAC), typically "the sound card", takes sequence of numbers and turn them into eletric current, which in turn moves the speaker's electromagnet forward or backwards. Suppose I use an 8-bit value for a single a sound sample, then the values 0 and 255 respectively move the magnet from one to the other extremity.
A common format to represent sound waves in digital form is given by Pulse Code Modulation (PCM) where analog sound waves are simply represented by sequences of numbers.
Compile and run:
$ make
$ ./tonegen
Wrote output/mary.wav
Wrote output/bells.wav
Now play back bells.wav (uploaded to YouTube for convenience).
This is is how Audacity represents the file.
Section with "pure tone" (sine waves):
Section with square waves:
Section with Attack, Decay, Sustain, Release (ADSR) envelope:
- Fundamentals of Sound
- Synthesis of Complex Sounds
- Project 1 - Synthesis of Musical Notes and Instrument Sounds with Sinusoids (Qi, 2015)
- Overtones, harmonics and Additive synthesis
- Additive synthesis
- Harmonic
- Music Meets Science. 1 Pitch & Frequency, 2.Timbre & Complex Wave, 3. Frequency & Harmonics
- FM SYNTHS in under 4 minutes | Andrew Huang
- Frequency modulation synthesis
- Synthesis of Complex Audio Spectra by Means of Frequency Modulation (Chowning, 1973)
- Envelope
- WAVE File Format