npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pcm-effects

v1.0.3

Published

Add effects on your PCM streams

Downloads

6

Readme

PCM-Effects

Manipulate, transform and add effects to your PCM streams

This package simplifies the process of manipulating PCM streams.

Using this package with discord.js is possible, as it was originally made for usage in discord bots.

Supported PCM stream type

  • [x] s8
  • [x] u8
  • [x] s16le
  • [ ] s16be
  • [ ] u16le
  • [ ] u16be
  • [ ] s32le
  • [ ] s32be
  • [ ] u32le
  • [ ] u32be

Usage example

import PCMEffects from 'pcm-effects';//Importing the module

//--- Create a ffmpeg process to get a PCM stream ---//
const ffmpeg = child_process.spawn('ffmpeg', [
	'-i', ANY_INPUT_OR_STDIN,
	'-analyzeduration', '0',
	'-loglevel', '0',
	'-f', 's16le',//Required : set the PCM stream type
	'-ar', '48000',//Sample rate: not useful for PCM-Effects, but may need be to changed depending on the use case (ex: Discord voice require 48000Hz)
	'-ac', '2',//Force the input to be in stereo
	'pipe:1'//Redirect the output to stdout
], {
	shell: false,
	windowsHide: true
});
//---//

//--- PCM-Effects ---//
const pcm = new PCMEffects("s16le");//Create a new instance of PCM-Effects
pcm.setVolume(1);//Change the volume, can be changed during playing
pcm.setDistortion(1);//Change the distortion, can be changed during playing
ffmpeg.stdout.pipe(pcm);//Redirect the output of ffmpeg to the input of the PCM-Effects class
//---//

//--- Using the output in Discord.js ---//
const prism = require('prism-media');
const { createAudioResource } = require('discord.js');

const encoder = new prism.opus.Encoder({channels: 2, rate: 48000, frameSize: 960});//Encode the PCM stream in Opus format
pcm.pipe(encoder);//Pass the PCM-Effects stream to the encoder
let resource = createAudioResource(encoder, {inputType: "opus"});//Create a Discord.js audioResource
//You can now use this resource in Discord.js (see https://discordjs.guide/voice/audio-resources.html)
//---//

API

PCMEffects.Merge(type, ...streams)

Merge two PCMEffects streams together, and return a new one with his own effects control.

Warning : The first stream should not interrupt transmission, because frames are synced based on it. If this stream cease to emit, sound of the others streams will not be processed

Example :

const pcm1 = new PCMEffects("s16le");
const pcm2 = new PCMEffects("s16le");
const new_pcm = PCMEffects.Merge("s16le", pcm1, pcm2);

Arguments :

  • type : The stream type. Possibles values are listed in Supported PCM stream type
  • streams : An indefinite list of PCMEffects streams

new PCMEffects(type)

Initialize the PCM.

The returned class extends Transform, the class is also a readable and a writable stream.

Example : const pcm = new PCMEffects("s16le")

Arguments :

pcm.setVolume(level)

Set the volume of the stream.

This setting can be changed at any moment

Example : pcm.setVolume(2)//The volume is double as original

Arguments :

  • level : Volume level. This value multiplies the actual volume (0.5 play at half the volume, 2 double it)

pcm.setDistortion(level)

Set the distortion of the stream.

This setting can be changed at any moment

Example : pcm.setSaturation(60)//The volume is double as original

Arguments :

  • level : Distortion threshold in percent. The volume is limited to this threshold

Help and disclaimer

To have a preview of this module working, take a look at the discord bot BaBot (Source code).

I'm far from being expert in programming and, especially in this package, my code is dirty and buggy.

But feel free :

  • To report any issues in this Github repo
  • To make code changes
  • To contact me for any questions or suggestions : Theirémi#4835, BaBot server