tonegenerator
Advanced tools
Comparing version 0.0.2 to 0.1.0
/* | ||
* ToneGenerator for node.js | ||
* generates raw PCM data for a tone, | ||
* generates raw PCM data for a tone, | ||
* specify length and frequency | ||
@@ -16,8 +16,8 @@ */ | ||
module.exports = function(freq, lengthInSecs) { | ||
module.exports = function(freq, lengthInSecs, volume) { | ||
freq = freq || 440; | ||
lengthInSecs = lengthInSecs || 2.0; | ||
volume = volume || 30 | ||
var cycle = Math.floor(44100/freq); | ||
var volume = 30; | ||
var samplesLeft = lengthInSecs * 44100; | ||
@@ -24,0 +24,0 @@ var cycles = samplesLeft/cycle; |
{ | ||
"name": "tonegenerator", | ||
"description": "Generates a tone as raw PCM WAV data, so you can do operations on it", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"scripts": { | ||
"test": "node test.js", | ||
"semantic-release": "semantic-release pre && npm publish && semantic-release post" | ||
}, | ||
"author": { | ||
@@ -9,10 +13,18 @@ "name": "Karl Westin", | ||
}, | ||
"repository" : { | ||
"type" : "git", | ||
"url" : "https://github.com/karlwestin/node-tonegenerator.git" | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/karlwestin/node-tonegenerator.git" | ||
}, | ||
"keywords": ["audio", "tone", "frequency", "wav", "pcm"], | ||
"dependencies": {}, | ||
"keywords": [ | ||
"audio", | ||
"tone", | ||
"frequency", | ||
"wav", | ||
"pcm" | ||
], | ||
"devDependencies": { | ||
"semantic-release": "^4.3.5" | ||
}, | ||
"main": "./index.js", | ||
"readmeFilename": "README.md" | ||
} | ||
} |
ToneGenerator for node.js | ||
==== | ||
This thing generates raw PCM data, specified by | ||
This thing generates raw PCM data, specified by | ||
a frequency and length in seconds. | ||
```javascript | ||
tone(frequency, lengthInSeconds, [volumen]) | ||
``` | ||
```javascript | ||
var tone = require("tonegenerator"); | ||
var A440 = tone(440, 20); // get PCM data for a 440hz A, 20 seconds. | ||
var A440 = tone(440, 20, 30); // get PCM data for a 440hz A, 20 seconds, volume 30 | ||
``` | ||
The data is returned as a normal array, so you can do operations on it. | ||
I'm really unsure what the 'volume' value means, but you can use it to create | ||
different tones with different volumes, let me know how it works for you! | ||
The data is returned as a normal array, so you can do operations on it. | ||
Before writing to a file, you need to convert it to a buffer: | ||
@@ -21,8 +28,8 @@ | ||
// An A-major chord | ||
var tone1 = tone(440, 2); | ||
var tone2 = tone(554.37, 2); | ||
var tone3 = tone(659.26, 2); | ||
var tone1 = tone(440, 2, 60); | ||
var tone2 = tone(554.37, 2, 30); | ||
var tone3 = tone(659.26, 2, 30); | ||
// "playing" one tone at the time | ||
// note that at this time, our sound is just an array | ||
// note that at this time, our sound is just an array | ||
// of gain values. By appending the raw PCM data for one after another, | ||
@@ -29,0 +36,0 @@ // we can play them in a sequence |
3678
6
37
52
1