{"id":37029220,"url":"https://github.com/danigb/sample-player","last_synced_at":"2026-01-14T03:30:21.056Z","repository":{"id":41449526,"uuid":"48401641","full_name":"danigb/sample-player","owner":"danigb","description":"A web audio audio sample player","archived":true,"fork":false,"pushed_at":"2023-05-16T17:02:28.000Z","size":1254,"stargazers_count":31,"open_issues_count":6,"forks_count":9,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-22T00:28:38.295Z","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":"CHANGELOG","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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-12-22T00:36:47.000Z","updated_at":"2025-03-21T08:03:28.000Z","dependencies_parsed_at":"2024-06-18T17:47:20.571Z","dependency_job_id":"0d31a18a-f5d0-4933-9a16-9f670e1eb52b","html_url":"https://github.com/danigb/sample-player","commit_stats":{"total_commits":28,"total_committers":2,"mean_commits":14.0,"dds":0.0357142857142857,"last_synced_commit":"5bd90d2dcda7572142c5d2080c6db3d5a29db096"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/danigb/sample-player","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danigb%2Fsample-player","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danigb%2Fsample-player/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danigb%2Fsample-player/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danigb%2Fsample-player/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danigb","download_url":"https://codeload.github.com/danigb/sample-player/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danigb%2Fsample-player/sbom","scorecard":{"id":320687,"data":{"date":"2025-08-11","repo":{"name":"github.com/danigb/sample-player","commit":"e0852adc90bc159d2a9f7011b03e9c2a1a391f5c"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Code-Review","score":0,"reason":"Found 1/29 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"project is archived","details":["Warn: Repository is archived."],"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 2 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-18T01:17:18.319Z","repository_id":41449526,"created_at":"2025-08-18T01:17:18.319Z","updated_at":"2025-08-18T01:17:18.319Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28408843,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T01:52:23.358Z","status":"online","status_checked_at":"2026-01-14T02:00:06.678Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2026-01-14T03:30:16.624Z","updated_at":"2026-01-14T03:30:20.927Z","avatar_url":"https://github.com/danigb.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sample-player [![npm](https://img.shields.io/npm/v/sample-player.svg?style=flat-square)](https://www.npmjs.com/package/sample-player)\n\n[![Build Status](https://img.shields.io/travis/danigb/sample-player/master.svg?style=flat-square)](https://travis-ci.org/danigb/sample-player)\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/sample-player.svg?style=flat-square)](https://www.npmjs.com/package/sample-player)\n\n⚠️ This is old codebase I don't want to maintain anymore. There are lot of alternatives out there, this is one: https://github.com/danigb/smplr Thanks! ⚠️\n\nFlexible audio sample player for browser:\n\n```js\nvar player = require('sample-player')\nvar ac = new AudioContext()\n\nvar sample = player(ac, \u003cAudioBuffer\u003e)\nsample.start()\nsample.start() // can start several samples at the same time\nsample.stop() // stop all playing sounds\n```\n\n## Features\n\n#### Create multi-sample player\n\nPass a map of names to audio buffers to create a multi-sample player:\n\n```js\nvar player = require('sample-player')\nvar ac = new AudioContext()\nvar drums = player(ac, {\n  kick: \u003cAudioBuffer\u003e,\n  snare: \u003cAudioBuffer\u003e,\n  hihat: \u003cAudioBuffer\u003e\n})\ndrums.start('kick')\ndrums.start('snare', ac.currentTime, { gain: 0.5 })\n```\n\n#### Map note names to midi (and oposite)\n\nIf the buffers are mapped to note names, you can pass note names (including enharmonics) or midi numbers:\n\n```js\nvar samples = { 'C2': \u003cAudioBuffer\u003e, 'Db2': \u003cAudioBuffer\u003e, ... }\nvar piano = player(ac, samples)\npiano.start(69) // =\u003e Plays 'A4'\npiano.start('C#2') // =\u003e Plays 'Db2'\n```\n\nDecimal midi note numbers can be used to detune the notes:\n\n```js\npiano.start(69.5) // =\u003e Plays a note in the middle of 'A4' and 'Bb4'\n```\n\n#### Events\n\nYou can register event handlers with the `on` function:\n\n```js\nvar drums = player(ac, { kick: ..., snare: ..., hihat ... })\ndrums.on('start', function (when, name) {\n  console.log('start', name)\n})\ndrums.on('ended', function (when, name) {\n  console.log('ended', name)\n})\ndrums.start('kick')\n// console logs 'start kick'\n// console.logs 'ended kick' when sound ends\n```\n\nTo add a listener to all events use: `player.on(function (eventName, when, obj, opts))`.\n\nCurrently it fires: `start`,  `started`, `stop`, `ended`, `scheduled`\n\n#### Amplitude envelope control\n\nYou can apply an amplitude envelope control player-wide or shot-wide. You can pass a signle `adsr` option with an array of `[attack, decay, sustain, release]` or add each parameter to the options object:\n\n```js\n// using a single option to set all envelop\nvar longSound = player(ac, \u003cAudioBuffer\u003e, { adsr: [1.2, 0.5, 0.8, 1.3] })\nlongSound.start()\n// override only the attack\nlongSound.start(ac.currentTime + 10, { attack: 3 })\n```\n\n#### Listen to midi inputs\n\nEasily attach the player to a Web MIDI API `MidiInput`:\n\n```js\nvar piano = player(...)\nwindow.navigator.requestMIDIAccess().then(function (midiAccess) {\n  midiAccess.inputs.forEach(function (midiInput) {\n    piano.listenToMidi(midiInput)\n  })\n})\n```\n\n#### Schedule to play buffers at given times\n\n```js\nvar buffers = { 'C2': \u003cAudioBuffer\u003e, 'Db2': \u003cAudioBuffer\u003e, ... }\nvar marimba = player(ac, buffers)\nmarimba.schedule(ac.currentTime, [\n  { note: 'c2', time: 0, gain: 0.9 },\n  { note: 'e2', time: 0.25, gain: 0.7 },\n  { note: 'g2', time: 0.5, gain: 0.5 },\n  { note: 'c3', time: 0.75, gain: 0.3 }\n])\n```\n\n## Install\n\nVia npm: `npm i --save sample-player` or grab the [browser ready file](https://raw.githubusercontent.com/danigb/sample-player/master/dist/sample-player.min.js) which exports `SamplePlayer` as window global.\n\n## Options\n\nThe options can be passed to the `SamplePlayer` function to apply to all buffers, or to `start` function to apply to one shot.\n\n- `gain`: float between 0 to 1\n- `attack`: the attack time of the amplitude envelope\n- `decay`: the decay time of the amplitude envelope\n- `sustain`: the sustain gain value of the amplitude envelope\n- `release`: the release time of the amplitude envelope\n- `adsr`: an array of `[attack, decay, sustain, release]`. Overrides other parameters.\n- `duration`: set the playing duration in seconds of the buffer(s)\n- `loop`: set to true to loop the audio buffer\n\n## API\n\n\u003ca name=\"SamplePlayer\"\u003e\u003c/a\u003e\n\n## SamplePlayer(ac, source, options) ⇒ \u003ccode\u003eplayer\u003c/code\u003e\nCreate a sample player.\n\n**Returns**: \u003ccode\u003eplayer\u003c/code\u003e - the player  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| ac | \u003ccode\u003eAudioContext\u003c/code\u003e | the audio context |\n| source | \u003ccode\u003eArrayBuffer\u003c/code\u003e \u0026#124; \u003ccode\u003eObject.\u0026lt;String, ArrayBuffer\u0026gt;\u003c/code\u003e |  |\n| options | \u003ccode\u003eOnject\u003c/code\u003e | (Optional) an options object |\n\n**Example**  \n```js\nvar SamplePlayer = require('sample-player')\nvar ac = new AudioContext()\nvar snare = SamplePlayer(ac, \u003cAudioBuffer\u003e)\nsnare.start()\n```\n\n* [SamplePlayer(ac, source, options)](#SamplePlayer) ⇒ \u003ccode\u003eplayer\u003c/code\u003e\n  * [.play](#player.play)\n  * [.start(name, when, options)](#player.start) ⇒ \u003ccode\u003eAudioNode\u003c/code\u003e\n  * [.stop(when, nodes)](#player.stop) ⇒ \u003ccode\u003eArray\u003c/code\u003e\n  * [.on(event, callback)](#player.on) ⇒ \u003ccode\u003e[SamplePlayer](#SamplePlayer)\u003c/code\u003e\n  * [.connect(destination)](#player.connect) ⇒ \u003ccode\u003e[SamplePlayer](#SamplePlayer)\u003c/code\u003e\n  * [.schedule(source, map, when)](#player.schedule) ⇒ \u003ccode\u003eArray\u003c/code\u003e\n  * [.listenToMidi(input, options)](#player.listenToMidi) ⇒ \u003ccode\u003e[SamplePlayer](#SamplePlayer)\u003c/code\u003e\n\n\u003ca name=\"player.play\"\u003e\u003c/a\u003e\n### player.play\nAn alias for `player.start`\n**See**: player.start  \n\n\u003ca name=\"player.start\"\u003e\u003c/a\u003e\n### player.start(name, when, options) ⇒ \u003ccode\u003eAudioNode\u003c/code\u003e\nStart a sample buffer. The returned object has a function `stop(when)` to stop the sound.\n\n**Returns**: \u003ccode\u003eAudioNode\u003c/code\u003e - an audio node with a `stop` function  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| name | \u003ccode\u003eString\u003c/code\u003e | the name of the buffer. If the source of the SamplePlayer is one sample buffer, this parameter is not required |\n| when | \u003ccode\u003eFloat\u003c/code\u003e | (Optional) when to start (current time if by default) |\n| options | \u003ccode\u003eObject\u003c/code\u003e | additional sample playing options |\n\n**Example**  \n```js\n// A single sample player\nvar sample = player(ac, \u003cAudioBuffer\u003e).connect(ac.destination)\nvar first = sample.start(ac.currentTime, { loop: true })\nvar second = sample.start(ac.currentTime + 0.5, { loop: true, gain: 0.7 }) // name not required since is only one AudioBuffer\nfirst.stop(ac.currentTime + 1) // only stops first sound\nsample.stop() // stop all sounds\n```\n\n**Example**  \n```js\n// A multi-sample player\nvar drums = player(ac, { snare: \u003cAudioBuffer\u003e, kick: \u003cAudioBuffer\u003e, ... }).connect(ac.destination)\ndrums.start('snare')\ndrums.start('snare', 0, { gain: 0.3 })\n```\n\n\u003ca name=\"player.stop\"\u003e\u003c/a\u003e\n### player.stop(when, nodes) ⇒ \u003ccode\u003eArray\u003c/code\u003e\nStop some or all samples\n\n**Returns**: \u003ccode\u003eArray\u003c/code\u003e - an array of ids of the stoped samples  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| when | \u003ccode\u003eFloat\u003c/code\u003e | (Optional) an absolute time in seconds (or currentTime if not specified) |\n| nodes | \u003ccode\u003eArray\u003c/code\u003e | (Optional) an array of nodes or nodes ids to stop |\n\n**Example**  \n```js\nvar longSound = player(ac, \u003cAudioBuffer\u003e).connect(ac.destination)\nlongSound.start(ac.currentTime)\nlongSound.start(ac.currentTime + 1)\nlongSound.start(ac.currentTime + 2)\nlongSound.stop(ac.currentTime + 3) // stop the three sounds\n```\n\n\u003ca name=\"player.connect\"\u003e\u003c/a\u003e\n### player.connect(destination) ⇒ \u003ccode\u003eAudioPlayer\u003c/code\u003e\nConnect the player to a destination node\n\n**Chainable**  \n**Returns**: \u003ccode\u003eAudioPlayer\u003c/code\u003e - the player  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| destination | \u003ccode\u003eAudioNode\u003c/code\u003e | the destination node |\n\n**Example**  \n```js\nvar sample = player(ac, \u003cAudioBuffer\u003e).connect(ac.destination)\n```\n\n\u003ca name=\"player.on\"\u003e\u003c/a\u003e\n### player.on(event, callback) ⇒ \u003ccode\u003e[SamplePlayer](#SamplePlayer)\u003c/code\u003e\nAdds a listener of an event\n\n**Chainable**  \n**Returns**: \u003ccode\u003e[SamplePlayer](#SamplePlayer)\u003c/code\u003e - the player  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| event | \u003ccode\u003eString\u003c/code\u003e | the event name |\n| callback | \u003ccode\u003efunction\u003c/code\u003e | the event handler |\n\n**Example**  \n```js\nplayer.on('start', function(time, note) {\n  console.log(time, note)\n})\n```\n\n\u003ca name=\"player.schedule\"\u003e\u003c/a\u003e\n### player.schedule(when, events) ⇒ \u003ccode\u003eArray\u003c/code\u003e\n\nSchedule a list of events to be played at specific time.\n\nIt supports two formats of events:\n\n- An array with `[time, note]`\n- An array with objects `{ time: ?, [name|note|midi|key]: ? }`\n\n**Returns**: \u003ccode\u003eArray\u003c/code\u003e - an array of ids  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| when | \u003ccode\u003eFloat\u003c/code\u003e | an absolute time to start (or AudioContext's currentTime if it's less than currentTime) |\n| source | \u003ccode\u003eArray\u003c/code\u003e | the events array |\n\n**Example**  \n```js\n// Event format: [time, note]\nvar piano = player(ac, ...).connect(ac.destination)\npiano.schedule(0, [ [0, 'C2'], [0.5, 'C3'], [1, 'C4'] ])\n```\n\n**Example**  \n```js\n// Event format: object { time: , name: }\nvar drums = player(ac, ...).connect(ac.destination)\ndrums.schedule(ac.currentTime, [\n  { name: 'kick', time: 0 },\n  { name: 'snare', time: 0.5 },\n  { name: 'kick', time: 1 },\n  { name: 'snare', time: 1.5 }\n])\n```\n\n\u003ca name=\"player.listenToMidi\"\u003e\u003c/a\u003e\n### player.listenToMidi(input, options) ⇒ \u003ccode\u003e[SamplePlayer](#SamplePlayer)\u003c/code\u003e\nConnect a player to a midi input\n\nThe options accepts:\n\n- channel: the channel to listen to. Listen to all channels by default.\n\n**Returns**: \u003ccode\u003e[SamplePlayer](#SamplePlayer)\u003c/code\u003e - the player  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| input | \u003ccode\u003eMIDIInput\u003c/code\u003e |  |\n| options | \u003ccode\u003eObject\u003c/code\u003e | (Optional) |\n\n**Example**  \n```js\nvar piano = player(...)\nwindow.navigator.requestMIDIAccess().then(function (midiAccess) {\n  midiAccess.inputs.forEach(function (midiInput) {\n    piano.listenToMidi(midiInput)\n  })\n})\n```\n\n## Run tests and examples\n\nTo run the test, clone this repo and:\n\n```bash\nnpm install\nnpm test\n```\n\nTo run the examples:\n\n```bash\nnpm i -g budo\nbudo examples/microtone.js\n```\n\n(Take a look into `examples` folder)\n\n## License\n\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanigb%2Fsample-player","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanigb%2Fsample-player","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanigb%2Fsample-player/lists"}