Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/coderofsalvation/sunvoxjs
mirror of Alexander Zolotov's sunvoxjs lib
https://github.com/coderofsalvation/sunvoxjs
Last synced: 12 days ago
JSON representation
mirror of Alexander Zolotov's sunvoxjs lib
- Host: GitHub
- URL: https://github.com/coderofsalvation/sunvoxjs
- Owner: coderofsalvation
- Created: 2019-04-21T15:38:52.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-05-28T19:26:18.000Z (over 4 years ago)
- Last Synced: 2024-10-13T06:15:05.347Z (about 1 month ago)
- Language: JavaScript
- Size: 251 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
# sunvoxjs
This is a mirror of Alexander Zolotov's sunvoxjs lib, so it can be served over CORS (unpkg.com)
## Usage
## Demo / Docs
[http://warmplace.ru/soft/sunvox/jsplay/](http://warmplace.ru/soft/sunvox/jsplay/)
## Example
var sfile = "https://unpkg.com/sunvoxjs/test.sunvox"function status(l){ console.log(l) }
function loadFromArrayBuffer( buf )
{
if( buf )
{
var byteArray = new Uint8Array( buf );
if( sv_load_from_memory( 0, byteArray ) == 0 )
{
console.log( "song loaded" )
sv_play_from_beginning( 0 );
}
}
else
{
console.log( "song load error" );
}
}function loadSong(fname){
console.log( "loading: " + fname );
var req = new XMLHttpRequest();
req.open( "GET", fname, true );
req.responseType = "arraybuffer";
req.onload = function( e ) {
if( this.status != 200 ){
console.log( "file not found" );
return;
}
var arrayBuffer = this.response;
loadFromArrayBuffer( arrayBuffer );
};
req.send( null );
}svlib.then( function(Module) {
//
// SunVox Library was successfully loaded.
// Here we can perform some initialization:
//
status( "SunVoxLib loading is complete" );
var ver = sv_init( 0, 44100, 2, 0 ); //Global sound system init
if( ver >= 0 )
{
//Show information about the library:
var major = ( ver >> 16 ) & 255;
var minor1 = ( ver >> 8 ) & 255;
var minor2 = ( ver ) & 255;
console.log( "SunVox lib version: " + major + " " + minor1 + " " + minor2 );
console.log( "init ok" );
}
else
{
console.log( "init error" );
return;
}
sv_open_slot( 0 ); //Open sound slot 0 for SunVox; you can use several slots simultaneously (each slot with its own SunVox engine)
//
// Try to load and play some SunVox file:
//
loadSong( sfile );
});