Skip to content

Instantly share code, notes, and snippets.

@liammclennan
Last active August 29, 2015 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liammclennan/6e7143fe367f478d4b61 to your computer and use it in GitHub Desktop.
Save liammclennan/6e7143fe367f478d4b61 to your computer and use it in GitHub Desktop.
Code puzzle - signal generator

The "standard" encoding for digital audio is pulse code modulation. The analog signal is sampled at regular intervals and stored as an amplitude quantity value.

Facts:

  • CD audio uses 44,100 amplitude samples per second
  • Each sample is a 16-bit integer between -32,768 and 32,767

One way to synthesize a pure frequency (in Hz) is to sample a sine wave.

Your task is to implement a function from a number of milliseconds and a frequency to a collection of samples.

buzz : milliseconds:float -> frequency:float -> seq<int16>

IEnumerable<int16> Buzz(double milliseconds, double frequency);

Buzz(1000, 440) // should produce 44100 samples of concert A
Buzz(2000, 0)   // should produce 88200 zeros.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment