Skip to content

dlorch/tonegen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tone generator

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.

How to use

Compile and run:

$ make
$ ./tonegen
Wrote output/mary.wav
Wrote output/bells.wav

Now play back bells.wav (uploaded to YouTube for convenience).

Visualisation

This is is how Audacity represents the file.

Section with "pure tone" (sine waves):

sine waves

Section with square waves:

square waves

Section with Attack, Decay, Sustain, Release (ADSR) envelope:

adsr envelope

Links / Concepts

About

Tone generator written in C++

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published