GithubHelp home page GithubHelp logo

toyoshim / z-music.js Goto Github PK

View Code? Open in Web Editor NEW
12.0 4.0 1.0 954 KB

Z-MUSIC v1.10 and v2.08 for the web

License: BSD 3-Clause "New" or "Revised" License

Makefile 6.41% C++ 23.61% C 37.24% JavaScript 32.75%

z-music.js's Introduction

z-music.js

Z-MUSIC v1.10 and v2.08 for the web

How to build

emcc should be installed via emsdk (Emscripten) beforehand.

% git clone https://github.com/toyoshim/z-music.js.git
% cd z-music.js
% git submodule update --init --recursive
% make

How to use

<html>
<head>
<script src="dist/zmusic.js"></script>
<script>
// Make XHR to support Promise.
function xhr (url) {
  return new Promise(function (resolve, reject) {
    var xhr = new XMLHttpRequest();
    xhr.open('GET', url, true);
    xhr.responseType = 'arraybuffer';
    xhr.addEventListener('load', e => {
      resolve(xhr.response);
      xhr.abort();
    }, false);
    xhr.send();
  });
}

Promise.all([
    ZMUSIC.install(),
    xhr('data/bgm1.zmd'),
    xhr('data/bgm.zpd')]).then(results => {
  ZMUSIC.play(results[1], results[2]);
});
</script>
</head>
<body><button onclick="ZMUSIC.resume()">Unmute</button></body>
</html>

WebAssembly

Now, z-music.js relies on WebAssembly by default. dist/zmusic.asm.js is still available for users who are not ready for WebAssembly, but not maintained well.

Initialize with detailed parameters

Use Z-MUSIC v1.10

ZMUSIC.install(['ZMUSIC110.X']);

Use Z-MUSIC v2.08 (default)

ZMUSIC.install(['ZMUSIC208.X']);

With Z-MUSIC options

ZMUSIC.install(['ZMUSIC110.X', '-n', '-u', -'t0', '-w0']);

With specified audio buffer size

ZMUSIC.install(null, { buffer: 8192 });

Redirect output to another AudioNode

ZMUSIC.install(null, { context: myAudioContext });
ZMUSIC.connect(myAudioNodeCreatedFromMyAudioContext);

Compile ZMS and play

Promise.all([
    ZMUSIC.install(),
    xhr('data/bgm1.zms')]).then(results => {
  ZMUSIC.compileAndPlay(results[1]);
});

.adpcm_block_data

If .adpcm_block_data command is used in ZMS and ZMD, play() or compileAndPlay() call will be asynchronously done. It returns Pomise to notify its completion.

The filename for the ZPD would be converted to a name in capitals. Since this is performed inside ZMUSIC.X, I have no plan to fix this problem. E.g., FooBar.zpd will be accessed by FOOBAR.ZPD and /FOOBAR.ZPD.

If someone request, I would add an asynchronous interface to handle ZPD file reads in a customized way.

Requires a user initiated interaction.

mobile Safari

Since mobile Safari does not allow us to playback any audio without user actions, you need to call the first play() or compileAndPlay() call inside an event handler for user actions.

Others

Today, other browsers have the same restriction with mobile Safari. You can resume audio playback at anytime after you call ZMUSIC.install() by calling ZMUSIC.resume() in an event handler for user actions.

<button onclick="ZMUSIC.resume()">Unmute</button>

ZMUSIC.js API

See src/prolog.js

z-music.js's People

Contributors

toyoshim avatar

Stargazers

IWATSUKI Hiroyuki avatar grim13b avatar Yos Awed avatar GOROman avatar  avatar  avatar Uniskie avatar  avatar Uki_213 avatar molety avatar  avatar DeltaRazero avatar

Watchers

 avatar James Cloos avatar DeltaRazero avatar  avatar

Forkers

yosawed

z-music.js's Issues

`.adpcm_block_data` directive does not work

Probably .adpcm_block_data needs to handle file open/read/close DOSCALLs in a suitable way.
z-music.js may need to have an interface to handle a file loading callback, or just implement a default function to fetch the ZPD data via XHR.

Allocate Inter-VM communication buffer at safer place

Currently, 1MB-2MB area is used as an inter-VM communication buffer.
This area can be read/written outside X68k VM, but now it would conflict with ZMUSIC buffer if it's allocate relatively large buffer for PCM via -P.

Filename case issue of '.Adpcm_Block_Data'

  • Found at z-music.js v1.2.1.0

The line, `.Adpcm_Block_Data = ZPD_filename'
The case is ignored and it uses Uppercase.

For example, in ZMS, .Adpcm_Block_Data = MoonRevenge.ZPD
This tries to find the file 'MOONREVENGE.ZPD'.
( GET MOONREVENGE.ZPD could be seen in Browser console.)

So, ZPD filename needs to be Uppercase currently.
(It should be the different behavior between UN*X-based and Human68k file system.... :-| )

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.