Here's something I've been working on a bit recently. It's a software synthesizer written in Haskell. Right now it can generate tones with square waves, sawtooth waves, sine waves, and triangle waves. It also has code in place to support different types of filters (One of the most basic being a volume filter), though I haven't made any especially interesting ones yet.
As far as some more technical information goes, right now all audio sources are functions of time. They are provided the time in seconds of an audio sample, and return an amplitude in the range of [-1,1]. Since they always take time in seconds that makes them independant of sample rate. Once a final sample has been generated from all the combined sources, it's converted to a 16 bit integer from [-32767,32767] and written to STDOUT little endian. The current code uses a sample rate of 44100hz, but that can be changed to anything else pretty easily.
To actually play the audio, I can either pipe the output to a program like aplay which can play the raw data directly to my headphones, or I can dump it to a file. I can also probably pipe it to lame to encode it to mp3 on the fly, but I havent tried that yet.
I want to expand it to create more interesting/complex sounds, but I know very little about how sound actually works, so if anyone knows of any specific resources beyond wikipedia I could learn from (although wikipedia is interesting
), that'd be awesome. I know that I can implement an ADSR Envelope to make notes more distinct, and that should be simple enough, but beyond that I'm not sure what I'd like to try next.
Also feel free to criticize/suggest changes to my Haskell code. I'm new to haskell and still learning my way around the language
.
Anyways...
Code: https://github.com/unknownloner/HaskellSynth
Sample output (might be loud): http://z80.ukl.me/rfact.mp3
Composed of
►Square wave @ base frequency
►Triangle wave down one octave
►Triangle wave down two octaves
►Saw wave down two octaves
It also has two sets of notes playing at once, one being an octave lower than the first, so I believe you can double those for a total of either 4 or 8 tones playing depending on the time.
EDIT: Forgot to mention, I don't have a nice way to handle multi-channel sources yet, though I am thinking on it. Right now though everything's restricted to mono output.
As far as some more technical information goes, right now all audio sources are functions of time. They are provided the time in seconds of an audio sample, and return an amplitude in the range of [-1,1]. Since they always take time in seconds that makes them independant of sample rate. Once a final sample has been generated from all the combined sources, it's converted to a 16 bit integer from [-32767,32767] and written to STDOUT little endian. The current code uses a sample rate of 44100hz, but that can be changed to anything else pretty easily.
To actually play the audio, I can either pipe the output to a program like aplay which can play the raw data directly to my headphones, or I can dump it to a file. I can also probably pipe it to lame to encode it to mp3 on the fly, but I havent tried that yet.
I want to expand it to create more interesting/complex sounds, but I know very little about how sound actually works, so if anyone knows of any specific resources beyond wikipedia I could learn from (although wikipedia is interesting

Also feel free to criticize/suggest changes to my Haskell code. I'm new to haskell and still learning my way around the language

Anyways...
Code: https://github.com/unknownloner/HaskellSynth
Sample output (might be loud): http://z80.ukl.me/rfact.mp3
Composed of
►Square wave @ base frequency
►Triangle wave down one octave
►Triangle wave down two octaves
►Saw wave down two octaves
It also has two sets of notes playing at once, one being an octave lower than the first, so I believe you can double those for a total of either 4 or 8 tones playing depending on the time.
EDIT: Forgot to mention, I don't have a nice way to handle multi-channel sources yet, though I am thinking on it. Right now though everything's restricted to mono output.