This repository has been archived by the owner on Jun 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,109 @@ | ||
# web-audio-mock | ||
[![NPM Version](http://img.shields.io/npm/v/web-audio-mock.svg?style=flat)](https://www.npmjs.org/package/web-audio-mock) | ||
[![Build Status](http://img.shields.io/travis/mohayonao/web-audio-mock.svg?style=flat)](https://travis-ci.org/mohayonao/web-audio-mock) | ||
[![Coverage Status](http://img.shields.io/coveralls/mohayonao/web-audio-mock.svg?style=flat)](https://coveralls.io/r/mohayonao/web-audio-mock?branch=master) | ||
[![Dependency Status](http://img.shields.io/david/mohayonao/web-audio-mock.svg?style=flat)](https://david-dm.org/mohayonao/web-audio-mock) | ||
[![devDependency Status](http://img.shields.io/david/dev/mohayonao/web-audio-mock.svg?style=flat)](https://david-dm.org/mohayonao/web-audio-mock) | ||
|
||
> Web Audio API mock library for node.js | ||
## Installing | ||
|
||
##### node.js | ||
|
||
```sh | ||
% npm install web-audio-mock | ||
``` | ||
|
||
## Usage | ||
|
||
##### Module Routing | ||
|
||
```javascript | ||
require("./web-audio-mock"); | ||
|
||
var ctx = new AudioContext(); | ||
var osc = ctx.createOscillator(); | ||
var amp = ctx.createGain(); | ||
|
||
osc.type = "sawtooth"; | ||
osc.frequency.value = 220; | ||
|
||
osc.connect(amp); | ||
amp.connect(ctx.destination); | ||
|
||
ctx.toJSON(); | ||
|
||
{ | ||
"name": "AudioDestinationNode", | ||
"inputs": [ | ||
{ | ||
"name": "GainNode", | ||
"gain": { | ||
"name": "gain", | ||
"value": 1, | ||
"inputs": [] | ||
}, | ||
"inputs": [ | ||
{ | ||
"name": "OscillatorNode", | ||
"type": "sawtooth", | ||
"frequency": { | ||
"name": "frequency", | ||
"value": 220, | ||
"inputs": [] | ||
}, | ||
"detune": { | ||
"name": "detune", | ||
"value": 0, | ||
"inputs": [] | ||
}, | ||
"inputs": [] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
``` | ||
|
||
##### DecodeAudioData | ||
|
||
```javascript | ||
var ctx = new AudioContext(); | ||
|
||
it("AudioContext#decodeAudioData", function(done) { | ||
|
||
// ctx.DECODE_AUDIO_DATA_FAILED = true; | ||
|
||
ctx.decodeAudioData(buffer, function(e) { | ||
done(); | ||
}, function() { | ||
// failed | ||
}); | ||
|
||
}); | ||
``` | ||
|
||
##### ScriptProcessing | ||
|
||
```javascript | ||
var ctx = new AudioContext(); | ||
|
||
it("ScriptProcessorNode#onaudioprocess", function(done) { | ||
var scp = ctx.createScriptProcessor(1024, 2, 2); | ||
var count = 0; | ||
|
||
scp.onaudioprocess = function(e) { | ||
count += 1; | ||
if (count === 5) { | ||
done(); | ||
} | ||
}; | ||
|
||
ctx.process(0.5); // process 0.5sec | ||
}); | ||
``` | ||
|
||
## License | ||
|
||
web-audio-mock is available under the The MIT License. |