https://github.com/colinbdclark/sf2-parser
A JavaScript SoundFont 2 parser
https://github.com/colinbdclark/sf2-parser
Last synced: 6 months ago
JSON representation
A JavaScript SoundFont 2 parser
- Host: GitHub
- URL: https://github.com/colinbdclark/sf2-parser
- Owner: colinbdclark
- License: other
- Created: 2015-07-06T21:05:58.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2018-05-14T16:21:09.000Z (over 7 years ago)
- Last Synced: 2025-04-02T07:35:11.799Z (7 months ago)
- Language: JavaScript
- Size: 104 KB
- Stars: 54
- Watchers: 4
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: MIT-LICENSE.txt
Awesome Lists containing this project
- awesome-javascript-audio - colinbdclark/sf2-parser - a SoundFont 2 parser, extracted from [sf2synth.js](https://github.com/gree/sf2synth.js) (Sound assets / SoundFonts)
README
SoundFont 2 (and 3) Parser
==================
A library for parsing SoundFont (SF2, SF3) files in JavaScript.
License and Credits
-------------------
This library is based on the SoundFont 2 parser from [sf2synth.js, a SoundFont Synthesizer for WebMidiLink](https://github.com/gree/sf2synth.js). It was written by imaya / GREE Inc and licensed under the MIT license. Modifications to the original are by Colin Clark.
How to Use It
-------------
1. Load your SoundFont file using XHR's arraybuffer responseType and wrap it as a Uint8Array
2. Instantiate a new parser instance
3. Call the parse() method to parse the SoundFont file
4. Use the getPresets() and getInstruments() methods to access preset and instrument data
5. Sample data is stored in the parser's sample member variable
### Example Code ###
// Utility function to load a SoundFont file from a URL using XMLHttpRequest.
// The same origin policy will apply, as for all XHR requests.
function loadSoundFont(url, success, error) {
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.responseType = "arraybuffer";
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
success(new Uint8Array(xhr.response));
} else {
if (options.error) {
options.error(xhr.statusText);
}
}
}
};
xhr.send();
}
// Load and parse a SoundFont file.
loadSoundFont("sf_GMbank.sf2", function (sfData) {
var parser = new sf2.Parser(sf2Data);
parser.parse();
// Do something with the parsed SoundFont data.
});
Summary of Changes from the Original
------------------------------------
* Separated out the SoundFont parsing library from the rest of the sf2synth synthesizer
* Removed the dependence on Google Closure
* Renamed the namespace to sf2 for brevity
* Added boilerplate to support most JS module loaders, including CommonJS, AMD, Node.js and browser globals
* Added a Grunt-based build process
* Created Bower and npm packages
To Do
-----
* Improve the API of the parser by making it stateless
* Add support for parsing in a Web Worker so that the main browser thread doesn't block
* Massively extend the unit test coverage
* Add support for running the unit tests in Node.js