Code Monkey home page Code Monkey logo

tonegen's Introduction

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

tonegen's People

Contributors

dlorch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

tonegen's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.