🚨 Active Supply Chain Attack:node-ipc Package Compromised.Learn More
Socket
Book a DemoSign in
Socket

retro-sound

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

retro-sound

An 8-bit style Sound Library based on Web Audio API

latest
npmnpm
Version
1.0.4
Version published
Weekly downloads
18
200%
Maintainers
1
Weekly downloads
 
Created
Source

title: Introducing retro-sound.js layout: demo

retro-sound.js is Lea's new Web Audio Library for 8-bit style retro sounds, based on Web Audio API. It's an npm install away:

npm install retro-sound

Let's have a look how it works. As it is based on Web Audio API, first thing to do is to create a new AudioContext. I also create a gain node to reduce the overall loudness a bit.

const AC = new AudioContext();
const masterVolume = AC.createGain();

masterVolume.gain.setValueAtTime(0.25, 0);
masterVolume.connect(AC.destination);

My library exports a Sound class which uses the Builder pattern to create sounds based on the four basic oscillators available in Web Audio API (triangle, singe, square and sawtooth). There are builder methods to add a couple of effects to the sound, like a modulator or a lowpass filter.

AC.resume();
const FM = new Sound(AC, 'triangle')
  .withModulator('square', 6, 600, 'detune')
  .withModulator('square', 12, 300, 'detune')
  .withFilter('lowpass', 1000)
  .toDestination(masterVolume);

FM.play('A5')
  .rampToVolumeAtTime(0, 1)
  .waitDispose();

There is also a WhiteNoise class. Combining it with a low-pass filter and changing it over time can create interesting effects like swooshes or percussions.

AC.resume();

const noise = new WhiteNoise(AC)
  .withFilter('lowpass', 10000)
  .toDestination(masterVolume);

noise.play()
  .rampFilterFreqAtTime(1000, .25)
  .rampToVolumeAtTime(0, .5).waitDispose();

Keywords

sound

FAQs

Package last updated on 26 Nov 2023

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