New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

tonegenerator

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tonegenerator

Generates a tone as raw PCM WAV data, so you can do operations on it

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
46
decreased by-23.33%
Maintainers
1
Weekly downloads
 
Created
Source

ToneGenerator for node.js

This thing generates raw PCM data, specified by a frequency and length in seconds.

tone(frequency, lengthInSeconds, volume = 30, sampleRate, = 44100)

volume and sampleRate are optional, the default is shown above. If you want to specify sampleRate, you have to specify volume!

var tone = require("tonegenerator");
var A440 = tone(440, 20, 30); // get PCM data for a 440hz A, 20 seconds, volume 30
var A440_low_sample = tone(440, 20, 30, 22050); // this array has lower sample rate and will only be half as long

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:

var tone = require("tonegenerator");
// Use this package to write a header for the wave file
// https://www.npmjs.org/package/waveheader
var header = require("waveheader");
var fs = require("fs");

// An A-major chord
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
// of gain values. By appending the raw PCM data for one after another,
// we can play them in a sequence
var res = [].concat(tone1);
res = res.concat(tone2);
res = res.concat(tone3);

// By adding values of the tones for each sample,
// we play them simultaneously, as a chord
for(var i = 0; i < tone1.length; i++) {
  res.push(tone1[i] + tone2[i] + tone3[i]);
}

// write to file (note conversion to buffer!)
var writer = new fs.createWriteStream("A-major.wav");
writer.write(header( 44100 * 8 )); // 44100 Hz * 8 seconds
writer.write(new Buffer(res));
writer.end();

Keywords

FAQs

Package last updated on 01 Oct 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc