ForSynth
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:
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
- Post a message in the GitHub Issues tab to discuss the function you want to work on.
- Concerning coding conventions, follow the stdlib conventions:
https://github.com/fortran-lang/stdlib/blob/master/STYLE_GUIDE.md
- When ready, make a Pull Request.
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.
- https://fortran-lang.discourse.group/t/writing-a-binary-file-in-little-endian/719/4
- https://en.wikipedia.org/wiki/Endianness
WAV / RIFF format
- https://en.wikipedia.org/wiki/Resource_Interchange_File_Format
- https://en.wikipedia.org/wiki/WAV
- http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/WAVE.html
Sound synthesis
- https://sites.google.com/site/learning4synthesizer/home
- https://en.wikipedia.org/wiki/Karplus%E2%80%93Strong_string_synthesis
Bibliography
English
- Jean-Claude Risset, "Computer music: why ?", 2003.
- Dave Benson, Music - A Mathematical Offering, 531 pages, 2008.
- David A. Jaffe and Julius O. Smith, “Extensions of the Karplus-Strong Plucked-String Algorithm.” Computer Music Journal 7, no. 2 (1983): 56. https://doi.org/10.2307/3680063.
- Kevin Karplus and Alex Strong, “Digital Synthesis of Plucked-String and Drum Timbres.” Computer Music Journal 7, no. 2 (1983): 43–55. https://doi.org/10.2307/3680062.
- Jarmo Lähdevaara, Science of Electric Guitars and Guitar Electronics. Helsinki, Finland: Books On Demand, 2012.
- Diana Deutsch, "The Paradox of Pitch Circularity"’. Acoustics Today 6, no. 3 (July 2010): 8–14. https://doi.org/10.1121/1.3488670.
- M.V. Mathews, "The Digital Computer as a Musical Instrument", Science 142, no. 3592 (1963): 553–57.
- M.V. Mathews, F.R. Moore and J.-C. Risset, "Computers and Future Music", Science, New Series, Vol. 183, No. 4122 (Jan. 25, 1974), pp. 263-268.
French
- Vincent Magnin, "Format WAV : créez des ondes sonores en C", GNU/Linux Magazine n°190, février 2016.
- Vincent Magnin, "Format WAV : des sons de plus en plus complexes", GNU/Linux Magazine n°190, février 2016.
- Some sounds created with the C version of the program: http://magnin.plil.net/spip.php?article131
- Laurent de Wilde, Les fous du son - D'Edison à nos jours, Editions Grasset et Fasquelle, 560 pages, 2016, ISBN 9782246859277.
- Laurent Fichet, Les théories scientifiques de la musique aux XIXe et XXe siècles, Vrin, 1996, ISBN 978-2-7116-4284-7.
- Guillaume Kosmicki , Musiques électroniques - Des avant-gardes aux dance floors, Editions Le mot et le reste, 2nd edition, 2016, 416 p., ISBN 9782360541928.
- Olivier Pernot, ELECTRO 100 - Les albums essentiels des musiques électroniques, Editions Le mot et le reste, 2016, 240 p., ISBN 978-2-36054-202-4.
- Bibliothèque Tangente n°11, Mathématiques et musique - des destinées parallèles, Paris : Éditions POLE, septembre 2022, ISBN 9782848842462.
- Blog Devenir Ingeson.
An history of electronic music
full of personal and geographical biases...
Before modern electronics (The Electricity Fairy)
Some ancestors of electronic instruments
- The telharmonium (1897). Patent US580035A.
- The intonarumori is an instrument created in 1913 by the futuristic composer Luigi Russolo. Russolo is the author of a manifesto on The Art of Noises (L'arte dei rumori), a manifesto for futuristic music.
- French translation: http://luigi.russolo.free.fr/mani1.html ; http://luigi.russolo.free.fr/mani2.html ; http://luigi.russolo.free.fr/mani3.html ; http://luigi.russolo.free.fr/mani4.html
-
George Antheil, Ballet Mécanique (1924). Piano, percussions and noises.
-
The Theremin, a non-contact instrument invented in 1919. It is used from time to time by certain bands:
-
Ondes Martenot (1928)
-
Hammond organ (1935):
- Ondioline (1941).
Musique concrète
Before music produced by electronic circuits, experiments were made in the 1940s with electroacoustic music and musique concrète, where (concrete) sounds were recorded on tape or vinyl and arranged and manipulated (the ancestor of sampling):
50's: Stockhausen
50's: misc
50's: Forbidden Planet (1956)
First film whose soundtrack (Louis & Bebe Barron) is entirely electronic:
60's: computers
60's: some famous electric keyboards
- The Doors, "When The Music's Over" (1967) (Ray Manzarek is generally playing a Fender Rhodes electric piano keyboard bass and a Vox Continental combo organ).
60's: Moog synthesizers
Wendy Carlos
Popcorn (Gershon Kingsley, 1969)
The first great success of electronic music.
Bernie Krause
He was a student of Stockhausen. As a guitarist, he will work for Moog and learn about electronic music, before becoming a bio-acoustician: he will study soundscapes, record the sounds of nature, highlight their frequential and temporal organisation, then show the degradation over the decades of soundscapes and therefore of the corresponding ecosystems (https://www.wildsanctuary.com/). He also played with people like The Doors or George Harrison.).
The Beatles (Abbey Road, 1969)
The Moog is used on the tracks "Maxwell's Silver Hammer", "I Want You (She's So Heavy)", "Here Comes The Sun", and "Because".
About modular synthesizers
Before becoming digital, the first synthesizers were analogue and modular: each function corresponds to a button, the functions and modules are connected by cables (wave generators, envelope generators, low frequency oscillators, filters, sequencers...) Ideal to understand what a synthesizer is!
70's: Tangerine Dream and Klaus Schulze
Tangerine Dream:
Klaus Schulze:
70's: Vangelis
Later famous works:
70's: Jean-Michel Jarre
70's: Synth-Punk
70's: Kraftwerk
70's: Giorgio Moroder
70's: misc
- Pierre Henry, Machine Danse (1973).
- François de Roubaix, Le Monde électronique de François de Roubaix (1971-75).
- Isao Tomita:
- Pink Floyd, On the Run (1973, The Dark Side of the Moon).
- Close Encounters of the Third Kind(Steven Spielberg, 1977).
- David Bowie and Brian Eno, Sense of Doubt (1977, Heroes).
- Brian Eno, Ambient 1: Music for Airports (1978).
- Tubeway Army, Are Friends Electric (1979).
- Edward Artemiev, Listening to Bach (From the movie "Solaris" 1972).
- Bernard Parmegiani, De Natura Sonorum (1975).
- Throbbing Gristle, 20 Jazz Funk Greats (1979).
80's: the synth invasion (pop, techno, electro, new wave...)
The synthesiser market skyrockets, prices fall. The year 1980 marks a turning point.
- Joy Division, Isolation (1980).
- Orchestral Manoeuvres In The Dark, Statues (1980).
- Orchestral Manoeuvres In The Dark, Enola Gay (1980).
- Visage, Fade to Grey (1980).
- Taxi Girl,Cherchez le garçon (1980).
- Grauzone, Eisbaer (1980).
- DAF, Alles Ist Gut.
- Depeche Mode, Just Can't Get Enough (1981).
- Soft Cell, Tainted Love (1981).
- The Human League, Don't You Want Me (1981).
- Kim Wilde, Cambodia (1981).
- Liaisons Dangereuses, Los Niños del Parque (1981).
- Guerre Froide, Demain Berlin (1981).
- Yazoo, Don't Go (1982).
- Tears for Fears, Mad World (1982).
- Front 242, Kampfbereit (1982).
- New Order, Blue Monday (1983).
- New Order, Confusion (1983).
- Eurythmics, Sweet Dreams (Are Made Of This) (1983).
- Frankie Goes To Hollywood, Relax (1983).
- The Neon Judgement, The Fashion Party (1983).
- Anne Clark, Our Darkness (1984).
- Fad Gadget, Collapsing New People (1984).
- Talk Talk, Such a Shame (1984).
- Bronski Beat, Smalltown Boy (1984).
- Alphaville, Forever Young (1984).
- Harold Faltermeyer, Axel F (1984) Beverly Hills Cop Soundtrack.
- Art Of Noise, Moments In Love (1985).
- Kraftwerk, Musique Non Stop (1986).
...
We can stop here, with Art of Noise (remember Luigi Russolo) and Musique Non Stop: electronic music is now mainstream!