{"id":22974267,"url":"https://github.com/diversen/adsr-gain-node","last_synced_at":"2025-04-02T07:25:08.022Z","repository":{"id":57173704,"uuid":"97959379","full_name":"diversen/adsr-gain-node","owner":"diversen","description":"A simple and small nodejs module for creating an adsr gain node","archived":false,"fork":false,"pushed_at":"2019-02-10T18:41:41.000Z","size":41,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-08T12:02:30.334Z","etag":null,"topics":["adsr","audiocontext"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/diversen.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}},"created_at":"2017-07-21T14:58:20.000Z","updated_at":"2019-02-10T18:41:43.000Z","dependencies_parsed_at":"2022-08-24T13:20:34.927Z","dependency_job_id":null,"html_url":"https://github.com/diversen/adsr-gain-node","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/diversen%2Fadsr-gain-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diversen%2Fadsr-gain-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diversen%2Fadsr-gain-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diversen%2Fadsr-gain-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/diversen","download_url":"https://codeload.github.com/diversen/adsr-gain-node/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246771749,"owners_count":20831095,"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":["adsr","audiocontext"],"created_at":"2024-12-15T00:00:30.593Z","updated_at":"2025-04-02T07:25:07.995Z","avatar_url":"https://github.com/diversen.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# adsr-gain-node\n\nSimple object for getting an ADSR gain node\n\n## Install: \n\n    npm install --save adsr-gain-node\n\n## Example usage\n\n~~~js\nvar adsrGainNode = require('adsr-gain-node')\nvar audioCtx = new AudioContext();\n\nvar oscillator = audioCtx.createOscillator();\n\n// Helper function to get new gain node\nfunction getADSR () {\n    let adsr = new adsrGainNode(audioCtx);\n    adsr.setOptions({\n        attackAmp: 0.001, \n        decayAmp: 0.3,\n        sustainAmp: 0.7,\n        releaseAmp: 0.001,\n        attackTime: 1.1,\n        decayTime: 0.2,\n        sustainTime: 1.0, \n        releaseTime: 5.0,\n\n        /**\n         * If you are making e.g. a keyboard, then you may \n         * not auto-release the note\n         * If auto release is false then\n         * you should release the note using. \n         * `adsr.releaseNow()´\n         */\n        autoRelease: true\n    });\n    return adsr\n}\n\n// Begin time for gain\nvar nowTime = audioCtx.currentTime\n\n// Get adsr and the gain node\n// Time it to begin in current time + 5 secs\nlet testTime = 2\n\nvar adsr = getADSR()\nvar gainNode = adsr.getGainNode(nowTime + testTime );\n\n// Connect the oscillator to the gain node\noscillator.connect(gainNode);\ngainNode.connect(audioCtx.destination);\n\n// Start\noscillator.start(nowTime + testTime);\n\n// Stop oscillator according to the ADSR\nlet endTime = adsr.releaseTime() + testTime\noscillator.stop(endTime)\n\n// On a piano you may want to release the note, when\n// the key is released. \n// \n// Then you may do something like this to end the note and the gain node: \n// E.g onKeyUp: \n//     oscillator.stop(this.adsr.releaseTimeNow())\n//     adsr.releaseNow()\n~~~~\n\nThere is also a HTML form which can generate a web interface for \nthe control of gain nodes. \n\nYou can see it on [https://diversen.github.io/adsr-gain-node/](https://diversen.github.io/adsr-gain-node/) \n\nThe source is [test.js](test.js)\n\n## License\n\nMIT © [Dennis Iversen](https://github.com/diversen)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiversen%2Fadsr-gain-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdiversen%2Fadsr-gain-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiversen%2Fadsr-gain-node/lists"}