tonegenerator
Advanced tools
Comparing version 0.3.2 to 0.3.3
16
index.js
@@ -68,6 +68,11 @@ /* | ||
var cycles = samplesLeft/cycle; | ||
var ret = []; | ||
const ret = new Int16Array(samplesLeft); | ||
let retIndex = 0; | ||
for(var i = 0; i < cycles; i++) { | ||
ret = ret.concat(generateCycle(cycle, volume, shape)); | ||
const cycleValues = generateCycle(cycle, volume, shape); | ||
cycleValues.forEach((value) => { | ||
ret[retIndex++] = value; | ||
}); | ||
} | ||
@@ -89,3 +94,8 @@ | ||
return generateWaveForm(opts) | ||
const data = generateWaveForm(opts) | ||
if (opts.Int16Array) { | ||
return data | ||
} | ||
return Array.from(data) | ||
} | ||
@@ -92,0 +102,0 @@ |
{ | ||
"name": "tonegenerator", | ||
"description": "Generates a tone as raw PCM WAV data, so you can do operations on it", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"scripts": { | ||
@@ -29,2 +29,2 @@ "test": "node test.js", | ||
"readmeFilename": "README.md" | ||
} | ||
} |
@@ -18,3 +18,4 @@ ToneGenerator for node.js | ||
rate: 44100, | ||
shape: 'triangle' | ||
shape: 'triangle', | ||
Int16Array: true // use this mode when generating very long notes | ||
}) | ||
@@ -21,0 +22,0 @@ |
14
test.js
@@ -6,3 +6,2 @@ var assert = require('assert') | ||
var tone1 = tonegenerator({ freq: 440, lengthInSecs: 2, volume: 10 }) | ||
@@ -87,2 +86,15 @@ var tone2 = tonegenerator({ freq: 440, lengthInSecs: 2, volume: 30 }) | ||
console.log('Testing generating a 30 minute tone') | ||
var long = tonegenerator({ | ||
freq: 440, | ||
lengthInSecs: 30 * 60, | ||
volume: 60, | ||
Int16Array: true | ||
}) | ||
assert.equal(long instanceof Int16Array, true, 'Should have an Int16Array mode') | ||
long = null | ||
console.log('...done') |
24159
163
193