Skip to content

A small Fortran synthesizer to explore sound synthesis, sound effects, electronic music, algorithmic music, etc. Humbly follow the steps of Stockhausen, Kraftwerk and the Daft Punk!

License

Notifications You must be signed in to change notification settings

vmagnin/forsynth

Repository files navigation

A small Fortran synthesizer to explore sound synthesis, sound effects, electronic music, algorithmic music, etc. But ForSynth could also be used for scientific data sonification, for acoustic simulations or for teaching programming in a fun way.

Humbly follow the steps of Stockhausen, Kraftwerk and the Daft Punk (see the ELECTRONIC_MUSIC_HISTORY.md file).

Features

  • ForSynth is a semi-analog semi-digital studio: time is discretized (44100 samples/s) but the amplitude is coded as a Fortran real and digitized as a 16 bits signed integer only after the final mixing, when generating the output WAV file.
  • You can use as many stereo tracks as you need. The track 0 is used for the final mix and some algorithms also use it as an auxilliary track. Do you know The Beatles used a 8 tracks tape recorder the first time in August 1968 to record Hey Jude? The second song was Dear Prudence.
  • Basic music theory elements (scales, circle of fifths, chords...).
  • Various signals and Karplus-Strong algorithms (guitar and drums).
  • Envelopes generators: ADSR, fade in, fade out.
  • Some audio effects: delay, fuzz, tremolo, reverse and autopan.
  • Final mixing with the level and panoramic of each track.
  • The API is documented with FORD: https://vmagnin.github.io/forsynth/
  • Various examples.
  • You just need a modern Fortran compiler and a media player, whatever your OS.
  • GPL-3.0-or-later license.

If you are more interested by composing than sound synthesis, you may also be interested by its twin project ForMIDI.

Compilation and execution

You can easily build the project using the Fortran Package Manager fpm (https://github.com/fortran-lang/fpm) at the root of the project directory:

$ fpm build

Or if you don't have fpm, you can use the build.sh script (the examples will be built inside the build/ directory).

Running the examples

The examples can be found in the example/ directory. For example, the chords_and_melody.f90 example can be run with the command:

$ fpm run --example chords_and_melody

But you can also use the optimization flags of your compiler, for example with GFortran:

$ fpm run --example chords_and_melody --flag "-Ofast -static-libgfortran"

A WAV file was generated in the root directory of the project:

$ file chords_and_melody.wav
chords_and_melody.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, stereo 44100 Hz
$ hexdump -C chords_and_melody.wav
00000000  52 49 46 46 a4 ff 42 01  57 41 56 45 66 6d 74 20  |RIFF..B.WAVEfmt |
00000010  10 00 00 00 01 00 02 00  44 ac 00 00 10 b1 02 00  |........D.......|
00000020  04 00 10 00 64 61 74 61  80 ff 42 01 3d 0e 3d 0e  |....data..B.=.=.|
00000030  56 03 56 03 d4 f5 d4 f5  9d 0e 9d 0e 91 f6 91 f6  |V.V.............|
...

You can listen to your WAV using any media player, for example the SoX play command (or the ALSA command aplay):

$ play chords_and_melody.wav

chords_and_melody.wav:

 File Size: 21.2M     Bit Rate: 1.41M
  Encoding: Signed PCM
  Channels: 2 @ 16-bit
Samplerate: 44100Hz
Replaygain: off
  Duration: 00:02:00.00

In:2.32% 00:00:02.79 [00:01:57.21] Out:123k  [!=====|=====!] Hd:0.0 Clip:0

You can also use Audacity or Sonic Visualiser to visualise your music, either as a waveform or a spectrogram.

Contributing

Technical information

Endianness

A WAV comprises a header with metadata then the soundtracks in PCM (https://en.wikipedia.org/wiki/Pulse-code_modulation), written in little endian. This program asserts your machine is little endian. If you are big endian, please use the -fconvert=big-endian flag with gfortran, or -convert big_endian with ifort. Or contribute to the code to allow an automatic detection of endianness.

WAV / RIFF format

Sound synthesis

Bibliography

English

French

About

A small Fortran synthesizer to explore sound synthesis, sound effects, electronic music, algorithmic music, etc. Humbly follow the steps of Stockhausen, Kraftwerk and the Daft Punk!

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published