{"id":13805194,"url":"https://github.com/danigb/audio-contour","last_synced_at":"2025-04-11T12:31:17.404Z","repository":{"id":57186605,"uuid":"61411107","full_name":"danigb/audio-contour","owner":"danigb","description":"A 5 stage audio envelope generator","archived":false,"fork":false,"pushed_at":"2016-06-18T14:47:22.000Z","size":69,"stargazers_count":20,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T13:46:33.171Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danigb.png","metadata":{"files":{"readme":"README.md","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}},"created_at":"2016-06-18T01:20:02.000Z","updated_at":"2022-02-17T01:12:13.000Z","dependencies_parsed_at":"2022-09-14T16:50:53.142Z","dependency_job_id":null,"html_url":"https://github.com/danigb/audio-contour","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/danigb%2Faudio-contour","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danigb%2Faudio-contour/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danigb%2Faudio-contour/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danigb%2Faudio-contour/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danigb","download_url":"https://codeload.github.com/danigb/audio-contour/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248401954,"owners_count":21097328,"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":[],"created_at":"2024-08-04T01:00:58.455Z","updated_at":"2025-04-11T12:31:17.142Z","avatar_url":"https://github.com/danigb.png","language":"JavaScript","funding_links":[],"categories":["Obsolete"],"sub_categories":["Community"],"readme":"# audio-contour [![npm](https://img.shields.io/npm/v/audio-contour.svg?style=flat-square)](https://www.npmjs.com/package/audio-contour)\n\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard) [![license](https://img.shields.io/npm/l/audio-contour.svg?style=flat-square)](https://www.npmjs.com/package/audio-contour)\n\nA 5 stage audio envelope generator. You can see the **[demo here](https://danigb.github.io/audio-contour/example)**:\n\n```js\nvar Contour = require('audio-contour')\nvar ac = new AudioContext()\n\nvar vca = ac.createGain()\nvar osc = ac.createOscillator()\nosc.connect(vca)\n\nvar env = Contour(ac, { t1: 0.2, t4: 0.5 })\nenv.connect(vca.gain)\n\nenv.start()\nenv.onstart = function (when) { osc.start(when) }\nenv.onended = function () { osc.stop() }\nenv.stop(ac.currentTime + 3)\n```\n\nThis module implements a alpha-juno style envelope generator:\n\n![Envelope Diagram from audiorealism.se](env.png?raw=true)\n\nIf you want to learn more about envelope generators, read [this](https://github.com/micjamking/synth-secrets/blob/master/part-8.md)\n\nThere are a lot of envelope generator implementations. Here are the standalone ones I know (there are several audio libraries that implements them):\n\n- https://github.com/mmckegg/adsr\n- https://www.npmjs.com/package/adsr-envelope\n- https://github.com/itsjoesullivan/envelope-generator\n\nWhy choose this library over the others:\n\n- Unlike others, it implements a 5 stage envelope (and can be reduced to a standard ADSR envelope)\n- It supports `onstart` and `onended` events\n- Can specify gate duration (for sequencer style)\n- It's small (2.5Kb minified)\n\nWhy don't choose this library:\n\n- It's very young project, still in development and not battle tested.\n- Other libraries are great too!\n\n## Installation\n\nVia npm: `npm i --save audio-contour`\n\n## Usage\n\n**Create an envelope**\n\nTo create an envelope use the `Contour` function:\n\n```js\nvar ac = new AudioContext()\nvar Contour = require('audio-contour')\nvar env = Contour(ac)\n```\n\nYou can pass options to that function:\n\n```js\nvar env = Contour(ac, { t1: 1 })\n```\n\nor change them on the object **before** start:\n\n```js\nvar env = Contour(ac)\nenv.t1 = 1\nenv.t4 = 0.5\n```\n\n**Apply the envelope**\n\nTo apply the envelope, you have to connect it to something. For example, you can create a vca (voltage controlled amplifier) connecting it to a gain's gain param:\n\n```js\nvar vca = ac.createGain()\nenv.connect(vca.gain)\n```\n\nOr create a vcf (voltage controlled filter) ocnnecting it to a filter frequency param:\n\n```js\nvar vcf = ac.createBiquadFilter()\nenv.connect(vcf.frequency)\n```\n\n**Start and stop the envelope**\n\nYou can use `start` and `stop` function to the envelope:\n\n```js\nvar now = ac.currentTime\nenv.start(now)\n// suppose your audio source is an oscillator\nosc.start(now)\nvar finish = env.stop(now + 1)\n```\n\nThe `stop` function returns the time when the release phase ended. Can be used to stop the audio sources:\n\n```js\nosc.start(finish)\n```\n\nRemeber that **if duration is not `Infinity`, the envelope will stop automatically**:\n\n```js\nvar env = Contour(ac)\nenv.duration = 1\nenv.start() // =\u003e it will automatically stop after 1 second\n```\n\n**Events**\n\nTwo events are supported: `onstart` and `onended`. The `onstart` event handler will be trigger at same time as the `start` function of the envelope, so it receives a time parameter. The `onended` event handler will be called when the envelope effectively stops:\n\n```js\nenv.duration = 1\nenv.onstart = function (when) { osc.start(when) }\nenv.onended = function () { osc.stop(ac.currentTime) }\nenv.start() // since duration is not Infinity, both envent handlers will be called\n```\n\n**Create a standard ADSR**\n\nWhen `t3` is 0, the audio-contour behaves like a normal ADSR envelope.\n\nAdditionally, you can use the standard `attack`, `decay`, `sustain` and `release` parameters in the constructor to build the envelope:\n\n```js\nvar env = Contour(ac, { attack: 0.1, decay: 0.2, sustain: 0.8, release: 0.5 })\nenv.t1 // =\u003e 0.1 (the attack)\nenv.t2 // =\u003e 0.2 (the decay)\nenv.t3 // =\u003e 0\nenv.t4 // =\u003e 0.5 (the release)\n```\n\n## Run tests and examples\n\nTo run the tests, clone this repo and: `npm install \u0026\u0026 npm test`.\n\nTo run the example you need watchify installed: `npm install -g watchify`. Then, move to `examples` directory and type: `npm install \u0026\u0026 npm start`\n\n\n## License\n\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanigb%2Faudio-contour","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanigb%2Faudio-contour","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanigb%2Faudio-contour/lists"}