{"id":22066245,"url":"https://github.com/modlfo/vult-webaudio","last_synced_at":"2025-04-09T16:17:29.773Z","repository":{"id":74855070,"uuid":"99359337","full_name":"modlfo/vult-webaudio","owner":"modlfo","description":"Minimal example using Vult with WebAudio","archived":false,"fork":false,"pushed_at":"2017-08-05T08:58:06.000Z","size":4,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"gh-pages","last_synced_at":"2025-04-09T16:17:15.515Z","etag":null,"topics":["audio","dsp","effects","synthesizer","vult","webaudio"],"latest_commit_sha":null,"homepage":null,"language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/modlfo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-04T16:04:28.000Z","updated_at":"2024-10-10T07:44:03.000Z","dependencies_parsed_at":"2023-03-29T18:47:56.752Z","dependency_job_id":null,"html_url":"https://github.com/modlfo/vult-webaudio","commit_stats":{"total_commits":4,"total_committers":1,"mean_commits":4.0,"dds":0.0,"last_synced_commit":"2b766fa4fdf4b6b304d53d6abebb2348e4f9c9a5"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modlfo%2Fvult-webaudio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modlfo%2Fvult-webaudio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modlfo%2Fvult-webaudio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modlfo%2Fvult-webaudio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/modlfo","download_url":"https://codeload.github.com/modlfo/vult-webaudio/tar.gz/refs/heads/gh-pages","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248065284,"owners_count":21041872,"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","dsp","effects","synthesizer","vult","webaudio"],"created_at":"2024-11-30T19:26:51.639Z","updated_at":"2025-04-09T16:17:29.745Z","avatar_url":"https://github.com/modlfo.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Minimal example using Vult with WebAudio\n\nVult is a simple domain specific language with features that simplify developing of DSP algorithms. The generated code (C/++, Js and Lua) can be run efficiently on many platforms and microcontrollers.\n\nYou can find more information in the [Main Site](https://modlfo.github.io/vult/) and the [GitHub repository](https://github.com/modlfo/vult).\n\nThis example shows how to embed the Vult compiler in a Web page and generate a [ScriptProcessorNode](https://developer.mozilla.org/en-US/docs/Web/API/ScriptProcessorNode) to execute your Vult code with [WebAudio](https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API) in a browser.\n\nThe full code is in the [`index.html`](https://github.com/modlfo/vult-webaudio/blob/gh-pages/index.html)\n\nYou can check the results in this link https://modlfo.github.io/vult-webaudio/\n\n## Embedding Vult\n\nThe Vult compiler is available as JavaScript code in three different flavors:\n\n- [Command line application (requires Node.js)](https://www.npmjs.com/package/vult)\n- [Node.js library](https://www.npmjs.com/package/vultlib)\n- [Web Browser library](https://github.com/modlfo/vult/releases)\n\nIn this case we are gonna use the Web Browser library. To embed the latest release in your page you can use the following address:\n\n```\n\u003cscript src=\"https://modlfo.github.io/vult/javascripts/vultweb.js\"\u003e\u003c/script\u003e\n```\n\nYou can download or link an specific version from the compiler from the [releases](https://github.com/modlfo/vult/releases) page. For example:\n\n```\n\u003cscript src=\"https://github.com/modlfo/vult/releases/download/v0.3.27/vultweb.js\"\u003e\u003c/script\u003e\n```\n\nWhen the script is loaded it provides the global `vult` which contains all the methods to call the compiler. The API is the same as in the [Node.js library](https://www.npmjs.com/package/vultlib), which provides all the functionality of the of the [command line application](https://github.com/modlfo/vult/wiki/Command-Line-Options).\n\n## Generating ScriptProcessorNode\n\nTo generate code that is ready for WebAudio we can use the `webaudio` template available when generating JavaScrip. This is done by calling the function `vult.generateJs` and providing the appropriate options:\n\n```\n   var result = vult.generateJs([\n      {\n         file: 'test.vult',   // Name of the file\n         code: #code#         // the code itself as a string\n      }\n      ],\n      {\n         output: \"Test\",      // output name (used to prefix the code)\n         template: 'webaudio' // here we specify the template\n      });\n```\n\nThe result is an array with either errors or generated files. The errors are objects like this:\n```\n{\n   msg  : String, // Error message\n   file : String, // File name\n   line : Number, // Line where it occurs\n   col  : Number  // Column where it occurs\n}\n```\n\nIf the code generation is successful we will get objects like this (same kind as the input files):\n```\n{\n   file : \"foo.cpp\",      // File name or extension\n   code : \".. my code ..\" // Generated code\n}\n```\nWhen generating Web Audio code we only get one file.\n\n## Executing the code\n\nThe generated code is a string so we have to use `eval` in Javscript to execute it:\n\n```\nvar code = result[0].code; // When generating Js there's only one file\nvar vultProcessor = eval(code);\n```\n\nThe `vultProcessor` is a function that receives the `audioContext` and returns the `ScriptProcessorNode`.\n\n```\nvar audioContext = new AudioContext();\nvar vultProcessorNode = vultProcessor(audioContext);\n```\n\nThis node can be connected to your audio graph:\n\n```\nsource = audioContext.createBufferSource();\nsource.connect(vultProcessorNode);\nvultProcessorNode.connect(audioContext.destination);\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmodlfo%2Fvult-webaudio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmodlfo%2Fvult-webaudio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmodlfo%2Fvult-webaudio/lists"}