GithubHelp home page GithubHelp logo

tumarsal / xaudiojs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from taisel/xaudiojs

0.0 1.0 0.0 54 KB

A PCM audio stream output library that provides cross-browser compatibility.

ActionScript 9.51% JavaScript 90.49%

xaudiojs's Introduction

XAudioJS

A minimal cross-browser API for writing PCM audio samples:

This simple JavaScript library abstracts the push-for-audio API of Mozilla Audio, and the passive callback API of Web Audio. This library introduces an abstraction layer that provides a push-for-audio and a callback API in one. We even provide a flash fallback to bring us to a total of 3 APIs supported.


This software is hereby placed in the public domain for anyone to use.

How To Initialize:

new XAudioServer(int channels, double sampleRate, int bufferLow, int bufferHigh, function underRunCallback, function heartbeatCallback, function postheartbeatCallback, double volume, function failureCallback, object userEventLatch);
Make sure only one instance of XAudioServer is running at any time.
bufferLow MUST be less than bufferHigh.
bufferHigh sets the internal FIFO buffer length for all APIs except the Mozilla Audio Data API. Overfill on FIFO causes the oldest samples to be dropped first.

Array underRunCallback (int samplesRequested)

Arguments: Passed the number of samples that are needed to replenish the internal audio buffer back to bufferLow.

Functionality: JS developer set callback that can pass back any number of samples to replenish the audio buffer with.

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.

void heartbeatCallback (void)

Functionality: JS developers set this callback as a way to program against an audio clock, firing inside an audio event.

void postheartbeatCallback (void)

Functionality: JS developers set this callback as a way to program against an audio clock, firing immediately after an audio event.
volume is the output volume.

void failureCallback (void)

Functionality: JS developers set this callback to handle no audio support being available from the browser.

object userEventLatch

Functionality: JS developers set this DOM object for the Web Audio API to enable audio from.

Function Reference:

void writeAudio (Array buffer, Integer upTo)
Arguments: Pass an array of audio samples that is divisible by the number of audio channels utilized (buffer % channels == 0), and an integer length delimiter that follows the same restriction.
Functionality: Passes the audio samples directly into the underlying audio subsystem, and can call the specified sample buffer under-run callback as needed (Does the equivalent of executeCallback in addition to the forced sample input.).
Return: void (None).
void writeAudioNoCallback (Array buffer, Integer upTo)
Arguments: Pass an array of audio samples that is divisible by the number of audio channels utilized (buffer % channels == 0), and an integer length delimiter that follows the same restriction.
Functionality: Passes the audio samples directly into the underlying audio subsystem.
Return: void (None).
int remainingBuffer (void)
Arguments: void (None).
Functionality: Returns the number of samples left in the audio system before running out of playable samples.
Return (On valid): int samples_remaining (CAN BE NEGATIVE)
Return (On invalid): null
void executeCallback (void)
Arguments: void (None).
Functionality: Executes the audio sample under-run callback if the samples remaining is below the set buffer low limit.
Return: void (None).
void changeVolume (double volume)
Arguments: double float between 0 and 1 specifying the volume.
Functionality: Changes the volume. Will affect samples in buffer, so has a low-latency effect (Use this to do a fast-mute).
Return: void (None).

xaudiojs's People

Contributors

taisel avatar jsemu2 avatar

Watchers

James Cloos avatar

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.