License: Public Domain
As an exercise to sharpen my C skills (and out of admiration for older video game music), I've been writing a C program to make some audio files from scratch. It's not very advanced, but it allows you to define a sampling function which in turn it uses to create an .au file.
What you need to know:
- There are two versions of the program. The first version (pwt1) gives you access to the massive array of audio data in case you wanted to mess with it, otherwise you should use the second version (pwt2), which uses a buffer to keep the memory usage close to nothing. The makefile provided is set to create both versions.
- The "sample" function in sample.c is the sampling function I spoke of.
- waves.c/waves.h provide some waveforms for you to play around with.
- notes.c/notes.h provide two functions: noteKey(), which converts a string like "A#4" to the corresponding piano key number, and keyFreq(), which converts that number into the corresponding frequency.
- All options are within #defines in the main1.c, main2.c and sample.c files. There aren't any command-line switches, you just edit the code, compile and run it to make the audio file.
- The code was written with portability in mind and should compile almost anywhere, so long as you compile as C99.
Enjoy.
If you don't like C99, you can ditch the stdint.h and use set integer types from GLib:
ReplyDeletehttp://library.gnome.org/devel/glib/
There are no C99 style comments in the code and the use of types from stdint.h is the only C99 part of the code, otherwise it is pure ANSI C.