{"id":13768544,"url":"https://github.com/itsjoesullivan/envelope-generator","last_synced_at":"2025-07-06T01:05:15.803Z","repository":{"id":142095012,"uuid":"56271912","full_name":"itsjoesullivan/envelope-generator","owner":"itsjoesullivan","description":"Simple ADSR envelope generator for web audio","archived":false,"fork":false,"pushed_at":"2017-04-04T22:54:48.000Z","size":29,"stargazers_count":35,"open_issues_count":3,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-03T19:45:26.152Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/itsjoesullivan.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.MD","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":"2016-04-14T21:44:21.000Z","updated_at":"2024-02-09T22:05:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"2c81fa48-976a-488b-83ef-af07d2914709","html_url":"https://github.com/itsjoesullivan/envelope-generator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/itsjoesullivan/envelope-generator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itsjoesullivan%2Fenvelope-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itsjoesullivan%2Fenvelope-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itsjoesullivan%2Fenvelope-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itsjoesullivan%2Fenvelope-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/itsjoesullivan","download_url":"https://codeload.github.com/itsjoesullivan/envelope-generator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itsjoesullivan%2Fenvelope-generator/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263833416,"owners_count":23517373,"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-03T16:01:22.682Z","updated_at":"2025-07-06T01:05:15.785Z","avatar_url":"https://github.com/itsjoesullivan.png","language":"JavaScript","funding_links":[],"categories":["Sound editing","Obsolete"],"sub_categories":["ADSR envelopes","Community"],"readme":"## Envelope Generator ![Test status](https://api.travis-ci.org/itsjoesullivan/envelope-generator.svg)\n\nBasic ADSR envelope generator for web audio. A demo is running [here](http://joesul.li/van/envelope-generator/).\n\n- The release stage exists as a separate `GainNode`, so the envelope doesn't need to keep track of its output gain internally.\n- Uses the [voltage](https://github.com/mmckegg/adsr/blob/master/index.js#L126) idea from [mmckegg/adsr](https://github.com/mmckegg/adsr).\n\n### Example\n\n```bash\nnpm install --save envelope-generator\n```\n\n```javascript\nimport Envelope from 'envelope-generator';\n\nlet context = new AudioContext();\nlet osc = context.createOscillator();\n\nlet gain = context.createGain();\n\nlet env = new Envelope(context, {\n  attackTime: 0.1,\n  decayTime: 3,\n  sustainLevel: 0.4,\n  releaseTime: 0.1\n});\n\nenv.connect(gain.gain);\n\nvar startAt = context.currentTime;\n\nvar releaseAt = startAt + 0.5;\n\nosc.start(startAt);\nenv.start(startAt);\n\nenv.release(releaseAt);\n\nlet stopAt = env.getReleaseCompleteTime();\nosc.stop(stopAt);\nenv.stop(stopAt);\n```\n\n### Usage\n\n#### Constructor\n\nThe constructor accepts two arguments: an AudioContext and a settings object. All settings are optional, but you will probably want to set at least `attackTime`, `decayTime`, `sustainLevel`, and `releaseTime`.\n\n- All `...Time` properties are in seconds\n- All `curve`, `attackCurve`, `decayCurve`, and `releaseCurve` properties default to `\"linear\"`, with `\"exponential\"` the alternative.\n- attackCurve, decayCurve, and releaseCurve override their respective curves\n- Passing an `initialValueCurve` will determine the shape of the curve usually covered by the attack and decay sections of an envelope, overriding any other curve values.\n- Passing a `releaseValueCurve` will determine the shape of the release, overriding any other release curve value.\n- Both initialValueCurve and releaseValueCurve are expected to be normalized, i.e. not extending outside of the bounds [0, 1]. This is relatively intuitive for the `initialValueCurve`, but ensure that your `releaseValueCurve` also starts at a value of 1 to avoid any jumps in the sound. The reason for this is that these two curves are applied in series.\n- The sampleRate property applies to initialValueCurve and releaseValueCurve, allowing them to be expressed in a sampleRate different from that of the context.\n\n```javascript\nlet context = new AudioContext();\nlet settings = {\n  curve: \"linear\",\n  attackCurve: \"linear\",\n  decayCurve: \"linear\",\n  releaseCurve: \"linear\",\n  initialValueCurve: Float32Array,\n  releaseValueCurve: Float32Array,\n  sampleRate: 44100,\n  delayTime: 0,\n  startLevel: 0,\n  maxLevel: 1,\n  attackTime: 0.1,\n  holdTime: 0,\n  decayTime: 0,\n  sustainLevel: 0.5,\n  releaseTime: 1\n};\nlet env = new Envelope(context, settings)\n```\n\n#### connect\n\nThe `connect` method should be attached directly to `AudioParam`s:\n\n```javascript\nlet osc = context.createOscillator();\nlet gainNode = context.createGain();\nlet env = new Envelope(context, settings);\nenv.connect(gainNode.gain);\n```\n\n#### start\n\nThe `start` method triggers the attack and decay stages of the envelope:\n\n```javascript\nlet osc = context.createOscillator();\nlet gainNode = context.createGain();\nlet env = new Envelope(context, settings);\nenv.connect(gainNode.gain);\n\nosc.start(context.currentTime);\nenv.start(context.currentTime);\n```\n\n#### release\n\nThe `release` method triggers the release stage of the envelope:\n\n```javascript\nlet osc = context.createOscillator();\nlet gainNode = context.createGain();\nlet env = new Envelope(context, settings);\nenv.connect(gainNode.gain);\n\nosc.start(context.currentTime);\nenv.start(context.currentTime);\n\n// Release the envelope after 1 second\nenv.release(context.currentTime + 1);\n```\n\n#### getReleaseCompleteTime\n\nReleasing the envelope isn't the same as stopping the sound source. Once release has been called, `getReleaseCompleteTime()` will return the time that the envelope finishes its release stage. If this is an amp envelope, and the startLevel (i.e., where the envelope will release to) is 0, `getReleaseCompleteTime()` is when your sound source is guaranteed to be silent and can be stopped:\n\n```javascript\nlet osc = context.createOscillator();\nlet gainNode = context.createGain();\nlet env = new Envelope(context, settings);\nenv.connect(gainNode.gain);\n\nosc.start(context.currentTime);\nenv.start(context.currentTime);\n\nenv.release(context.currentTime + 1);\n\n// Stop the oscillator once the envelope has completed.\nosc.stop(env.getReleaseCompleteTime());\n```\n\n#### stop\n\nBecause they are generating a signal, envelopes need to be stopped as well as released. This should coincide with when the actual sound source is stopped.\n\n```javascript\nlet osc = context.createOscillator();\nlet gainNode = context.createGain();\nlet env = new Envelope(context, settings);\nenv.connect(gainNode.gain);\n\nosc.start(context.currentTime);\nenv.start(context.currentTime);\n\nenv.release(context.currentTime + 1);\n\n// Stop the oscillator once the envelope has completed.\nlet stopAt = env.getReleaseCompleteTime();\nosc.stop(stopAt);\nenv.stop(stopAt);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitsjoesullivan%2Fenvelope-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitsjoesullivan%2Fenvelope-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitsjoesullivan%2Fenvelope-generator/lists"}