{"id":20264362,"url":"https://github.com/thi-ng/synstack","last_synced_at":"2025-04-11T02:11:13.469Z","repository":{"id":77980088,"uuid":"50997137","full_name":"thi-ng/synstack","owner":"thi-ng","description":"Modular soft synth \u0026 Forth based VM for audio DSL experiments aimed at embedded devices","archived":false,"fork":false,"pushed_at":"2022-10-11T19:49:28.000Z","size":622,"stargazers_count":121,"open_issues_count":0,"forks_count":4,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-24T23:35:28.647Z","etag":null,"topics":["audio","c11","dsp","forth","portaudio","stm32","synth","vm"],"latest_commit_sha":null,"homepage":"https://hackaday.io/project/9374-stm32f4f7-synstack","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thi-ng.png","metadata":{"files":{"readme":"README.org","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-02-03T12:07:44.000Z","updated_at":"2025-03-08T12:59:47.000Z","dependencies_parsed_at":"2023-03-24T11:33:59.720Z","dependency_job_id":null,"html_url":"https://github.com/thi-ng/synstack","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thi-ng%2Fsynstack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thi-ng%2Fsynstack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thi-ng%2Fsynstack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thi-ng%2Fsynstack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thi-ng","download_url":"https://codeload.github.com/thi-ng/synstack/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248328160,"owners_count":21085261,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["audio","c11","dsp","forth","portaudio","stm32","synth","vm"],"created_at":"2024-11-14T11:39:51.327Z","updated_at":"2025-04-11T02:11:13.448Z","avatar_url":"https://github.com/thi-ng.png","language":"C","readme":"* thi.ng/synstack\n\nSoftsynth engine for tiny \u0026 not-so-tiny devices...\n\n** Contents                                                        :toc_3_gh:\n - [[#thingsynstack][thi.ng/synstack]]\n     - [[#overview][Overview]]\n         - [[#demos][Demos]]\n         - [[#node-dag-synth-engine][Node DAG synth engine]]\n         - [[#forth-like-vm-based-synth][Forth-like VM based synth]]\n     - [[#build-instructions][Build instructions]]\n     - [[#examples][Examples]]\n         - [[#interactive-examples][Interactive examples]]\n         - [[#forth-repl][Forth REPL]]\n     - [[#contributors][Contributors]]\n     - [[#license][License]]\n\n** Overview\n\n[[./assets/thing-synstack.jpg]]\n\n*** Demos\n\n- [[http://soundcloud.com/forthcharlie/sets/stm32f4][Demo set with 40+ tracks on Soundcloud]]\n- [[https://www.youtube.com/watch?v=41FKE3PYjnE][STM32F746 MIDI synth (live performance, 2016-01-31, Youtube)]]\n- [[https://www.youtube.com/watch?v=3lL-ZxyrHiE][STM32F746 synth (live recording, 2016-01-28, Youtube)]]\n\nPlease visit [[https://hackaday.io/project/9374-stm32f4f7-synstack][project log @ Hackaday]]\nfor interim updates, including a PDF with more project details. Thanks!\n\nThis repo currently contains two different experimental \u0026 easily\nextensible implementations of a modular soft synth engine, both\nwritten in portable C11 and originally developed for the STM32F4/F7\nplatform. However, for practical reasons (repo size, easier debugging\nand dev workflow), both versions currently included here were prepared\nwithout STM specifics, have been tested on OSX \u0026 Linux and [[#examples][include\nseveral examples]]. Demo file size after stripping is between ~22-40KB\n(for 32bit, bit larger for 64bit).\n\nThe sub-directories contain:\n\n*** Node DAG synth engine\n\n- =src= - an earlier (2nd or 3rd) iteration of the CTSS synth engine,\n  using block based operators \u0026 node DAG (directed acyclic graph):\n  - 10 oscillator types (incl. formant \u0026 karplus-strong, polyBlep antialiasing)\n  - flexibile LFO setup (global LFO \u0026 arbitrary per voice)\n  - filters (biquad, IIR LP/HP/BP, formant)\n  - ADSR\n  - foldback distortion\n  - buffer ops (sum, product, product sum)\n  - mono / stereo delay lines w/ feedback\n  - mono / stereo mixdowns (int16 \u0026 float)\n- =examples= - examples for this version of the synth (using\n  Portaudio, see below)\n\n*** Forth-like VM based synth\n\n(not embracing ANS Forth standard here):\n\nThe supplied Forth-like VM \u0026 core vocab is general purpose, is configurable\n(e.g. support for floating point \u0026 automatic inlining) and can also be used\nindependently, outside this project. In fact, the synth DSL related aspects\nare implemented as add-ons and can easily be removed.\n\n- =src_vm= - actual stack VM, interpreter \u0026 compiler w/ basic\n  inlining, REPL, core Forth dictionary \u0026 basic synth operators (still\n  need to port more from =src=)\n- =examples_vm= - Forth examples (see below)\n\n** Build instructions\n\nRequirements:\n\n- [[https://premake.github.io/][Premake5]]\n- [[http://www.gnu.org/software/make/][GNU Make]]\n- GCC / Clang (w/ C11 support)\n\nThe library itself has no 3rd party dependencies. Some of the examples\nhowever use these additional libraries:\n\n- [[https://github.com/thi-ng/ct-head][ct-head]] (included as submodule)\n- [[http://portaudio.com][Portaudio]] (on OSX can be installed via =brew=)\n- libncurses (part of OSX \u0026 Linux)\n\n#+BEGIN_SRC shell\ngit clone --recursive https://github.com/thi-ng/synstack\n\ncd synstack\n\npremake5 gmake\n\nmake -f ctss_old.make config=release_sse\n\nmake -f ctss_vm.make config=release_sse\n#+END_SRC\n\n** Examples\n*** Interactive examples\n\nUse the above build instructions to build all components \u0026 examples.\nAlmost all demos in =examples= implement a simple randomized sequence\nplayback (some with multiple voices) and are using the same\ninteractive controls:\n\n| *Key* | *Description*      |\n|-------+--------------------|\n| =-=   | dec delay feedback |\n| =+=   | inc delay feedback |\n| =[=   | pitch -2 semitones |\n| =]=   | pitch +2 semitones |\n| =;=   | pitch -12          |\n| '     | pitch +12          |\n| =q=   | quit               |\n\nThe two exceptions are:\n\n- [[./examples/synth_keys.c][synth_keys]] - play a new note with each keypress (fixed sequence, =q= to quit)\n- [[./examples/synth_render.c][synth_render]] - non-interactive demo, creates /sound.wav file (runtime ~20secs)\n\n#+BEGIN_SRC shell\n  # if you followed above build instructions, the demos can be launched like:\n  bin/release/synth_spiral\n#+END_SRC\n\n*** Forth REPL\n\nUse the command below to launch the VM with input file. Also see\n[[./examples_vm/bass-seq.fs][example source code]]. In this mode the VM goes straight into playback\nmode and is non-interactive (hit =Return= to quit).\n\n#+BEGIN_SRC shell\n  bin/release/repl examples_vm/bass-seq.fs\n#+END_SRC\n\nTo launch the Forth REPL in interactive mode:\n\n#+BEGIN_SRC shell\n  rlwrap bin/release/repl\n#+END_SRC\n\nThere'll be alot of output initially (inlining statistics by the Forth\ncompiler), but no visible input prompt. Try some of the following (hit\nreturn after each line, comment lines are prefixed with '\\\\')...\n\n#+BEGIN_SRC forth\n  \\ evaluate expression\n  \\ forth uses RPN, the '.' word pops \u0026 prints the top stack item\n  \\ forth is a hybrid between interpreted \u0026 compiled execution\n  1 2 + .\n  \\ 3\n\n  \\ define new word (here to calculate a * b + c)\n  \\ the (...) form is a stack effect comment:\n  \\ here it means the word consumes 3 items from the stack\n  \\ and after execution a new item (result) is on the stack\n  : madd ( a b c -- x ) -rot * + ;\n  3 5 10 madd .\n  \\ 25\n\n  \\ the VM differentiates between int \u0026 float based math\n  \\ float ops are prefixed with 'f'\n  : maddf -rot f* f+ ;\n  3.f 5.f 10.f maddf .f\n  \\ 25.0\n\n  \\ store values in \"variables\" (labelled addresses)\n  23 var\u003e foo !\n  \\ get var value\n  foo @ .\n  \\ 23\n\n  \\ by default the VM includes the dictionary of synth related words\n  \\ (defined in /src_vm/synth_dict \u0026 various C files in /src_vm)\n  \\ for example note names map to their frequency\n  A4 .f\n  \\ 440.000000\n\n  \\ convert frequency to ratio of sample rate\n  A4 hz .f\n  \\ 0.062689\n\n  \\ allocate memory for note/chord lookup table\n  C3 E3 G3 A3 4 dup allot dup var\u003e chord ! swap ds\u003edict!\n\n  \\ define word to randomly choose note from chord\n  : rand-chord-note ( -- freq ) 0 4 rand chord @ + @ ;\n\n  \\ call several times\n  rand-chord-note .f\n  rand-chord-note .f\n  rand-chord-note .f\n\n  \\ disassemble word\n  see\u003e rand-chord-note\n  \\ 0x000004da :0x0301a88a docolon\n  \\ 0x000004db :0x00000004 lit 0x00000000 \n  \\ 0x000004dd :0x00000004 lit 0x00000004 \n  \\ 0x000004df :0x00000081 rand\n  \\ 0x000004e0 :0x00000004 lit 0x000004d3 \n  \\ 0x000004e2 :0x0000002a @\n  \\ 0x000004e3 :0x0000004b + 0x0000002a (0x0000050e )\n  \\ 0x000004e5 :0x00000002 ret\n\n  \\ display data stack contents with .s\n  1 2 3 .s\n\n  \\ display VM stats\n  .vm\n\n  \\ display list \u0026 addresses of all words currently defined\n  \\ also see /src_vm/core_dict.h how some control structures\n  \\ are defined in forth itself\n  .words\n\n  \\ display hexdump of VM memory\n  .mem\n#+END_SRC\n\n** Contributors\n\n| *Name*          | *Role*                          | *Website* |\n| [[mailto:k@thi.ng][Karsten Schmidt]] | initiator \u0026 principal developer | [[http://thi.ng][thi.ng]]    |\n\n** License\n\nThis project is open source and licensed under the [[http://www.apache.org/licenses/LICENSE-2.0][Apache Software License 2.0]].\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthi-ng%2Fsynstack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthi-ng%2Fsynstack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthi-ng%2Fsynstack/lists"}