Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
100644 36 lines (36 sloc) 2.422 kb
578b9c3 @grantgalitz readme update.
1 <h1>XAudioJS</h1>
2 <h3>A minimal cross-browser API for writing PCM audio samples without plugins:</h3>
3 <p>This API was originally conceived as part of the JavaScript GameBoy Color emulator handling audio support for various browsers.
4 Since Firefox 4.0 only had the Mozilla Audio Data API and experimental (at the time) WebKit browsers utilized the Web Audio API,
5 there instantly was a need for abstracting the two APIs. This simple JavaScript library abstracts the push-for-audio API of Mozilla Audio
6 and the passive callback API of Web Audio and introduces an abstraction layers that provides a push-for-audio and a callback API in one.</p>
7 <br>
8 <h3>How To Initialize:</h3>
9 <dl>
10 <dt>new XAudioServer(int channels, int sampleRate, int bufferLow, int bufferHigh, function underRunCallback, defaultNeutralLevel);</dt>
11 <dd>Make sure only one instance of XAudioServer is running at any time.</dd>
12 <dd>bufferLow MUST be less than bufferHigh.</dd>
0b7bdc8 @grantgalitz update.
13 <dd>
3c84eb8 @grantgalitz update.
14 <h4>Array underRunCallback (int samplesRequested)</h4>
354aa2d @grantgalitz update.
15 <blockquote>
045f827 @grantgalitz update.
16 Arguments: Passed the number of samples that are needed to replenish the internal audio buffer back to bufferLow.<br><br>
17 Functionality: JS developer set callback that can pass back any number of samples to replenish the audio buffer with.<br><br>
3c84eb8 @grantgalitz update.
18 Return: Array of samples to be passed into the underlying audio buffer. MUST be divisible by number of channels used (Whole frames required.). The return array length DOES NOT NEED to be of length samplesRequested.
354aa2d @grantgalitz update.
19 </blockquote>
0b7bdc8 @grantgalitz update.
20 </dd>
578b9c3 @grantgalitz readme update.
21 </dl>
22 <h3>Function Reference:</h3>
23 <dl>
24 <dt>void writeAudio (Array buffer)</dt>
25 <dd>Arguments: Pass an array of audio samples that is divisible by the number of audio channels utilized (buffer % channels == 0).</dd>
26 <dd>Functionality: Passes the audio samples directly into the underlying audio subsystem, and can call the specified sample buffer under-run callback as needed.</dd>
27 <dd>Return: void (None).</dd>
28 <dt>int remainingBuffer (void)</dt>
29 <dd>Arguments: void (None).</dd>
30 <dd>Functionality: Returns the number of samples left in the audio system before running out of playable samples.</dd>
31 <dd>Return: int samples_remaining</dd>
32 <dt>void executeCallback (void)</dt>
33 <dd>Arguments: void (None).</dd>
34 <dd>Functionality: Executes the audio sample under-run callback if the samples remaining is below the set buffer low limit.</dd>
35 <dd>Return: void (None).</dd>
36 </dl>
Something went wrong with that request. Please try again.