LibSound77: making noise with g77 (base functions)

This library contains two minimalist Ansi C wrappers around two sound libraries: libao for playing beeps over your speakers, and libsndfile for reading and writing WAV files on your disk. They are currently only tested on Slackware Linux, but can work on other Linux distributions. I hope that the @Donis team make a port to OpenBSD in a (not really) near futur.

This is a work in progress. If you found a bug, or need a feature, you can send mail to tontonth O free o fr, or try to reach me on, I'm tth. And now, download this tarball for breaking the noise frontier, with a real 'dino' spirit.


The gnu compiler g77 is an "end-of-life" product, and I'me thinking about a gfortran interface to libsndfile. This is juste a work-in-progress, at this time only on paper.

Playing sound

Mono and stereo output are supported. See the files beep77.f and play77.f for example code. For changing buffer size, you have to edit ao77.c, and change the constant T_BUFF to any value that you thinks right, eg. 42.

call ao77ini()
Initialise library, must be called before ploping.
call ao77set(samplerate, nbrchannels)
set up parameters: samplerate is an integer like 44100, nbrchannels is an integer and must be 1 for mono and 2 for stereo.
call ao77out(sample)
Put a sound sample, who is an integer*2, on the way to the speakers. Do it as quickly as possible...
call ao77out2(left, right)
Put a stereophonic sample, who is two integer*2, on the way to the speakers. Do it as quickly as possible...
call ao77end()
Stop the sound-system, release ressources. Must be called after use. Nobody like looking the driver, you don't like a looked driver.

Writing and reading .WAV

At this time, I support only 16 bits signed datas in WAV format. Stereophonics files are now supported, still semi-experimental. See the file sinus.f for writing example code. See the file play77.f for reading example code.

fn = sndfopen('plop.wav', MODE, rate, channels)
Open a file for reading, if mode is 'I' or writing if mode is 'O'. You can have up to 42 files simultaneously open.
When you are a writer, you must set the samplerate to a reasonable value (eg: 24000, 44100 or 42) and set the number of channels to 1 or 2.
When you are a reader, you get values encoded in the file.
call sndfput(fn, sample)
Add a sample to a mono file. Samples are integer*2 values.
call sndfput2(fn, left, right)
Add two samples to the stereo file. Samples are integer*2 values.
err = sndfget(fn, sample)
Get a sample from a file opened for read. When success, return value is 1, when at end of file, return value is 0. Negatives are errors.
err = sndfget2(fn, left, right)
Get a stereo sample (two integer*2 valuers) from a file opened for read.
call sndfclose(fn)
Flush all pending datas and close the file.

Auxiliary functions

foo = sndf77version()
Return the integer version number of the library
call snd77hello(foo)
Print a small message with the version number. Parameter foo must be (for now) equal to zero.

"MIDI" functions

No, no, no. At this time (2007, July), I have absolutly no functions for talking MIDI from g77. But, after my move to a more recent fortran compiler, maybe I can try to make some mixed FTN/C code talking to my tr505. Wait and see...

freq = midi2hz(numnote)
Convert a midi note number to a frequency, returning a double precision value. this function assume a 440hz diapason. This func was never really tested. Ymmv.

There was a few others functions, not documented here. You have to "use the source, Luke" to experiment with them. Eg: writing an array of samples to a file. If you look at snd77misc.f, you can see buff1wav and buff2wav functions...

More infos about Unix sound

This kluge now have a Freshmeat page. You can also look at the Linux Audio Developers (and Users) website. For french speaking peoples: Vous devriez aller voir linuxmao, and blog77, my place for FORTRAN divagations.


Why FORTRAN77 ? Because it was fun, really. You can play with GOTO and COMEFROM. If you know C, you can wrap a lot of interesting library, and use g77 as a glue language. It was a nice challenge to debug. And I like Fortrash. Have fun with your computers...