/PSpectrum

Allows programs to access the audio loop-back of your system.

Primary LanguageC#MIT LicenseMIT

PSpectrum Audio Visualizer wakatime

PSpectrum allows programs that can not access the audio devices of your system, to access the audio data of the system.
I mainly use it for my PSpectrum Audio Visualizer for Powercord.
You can use the web subcommand to start a demo audio visualizer in your browser.
To capture the system audio I use the Bass library made by un4seen.

Commands

The most interesting commands are web, listen and devices.

Command Description
web Starts a demo audio visualizer in your browser.
listen Prints the current audio data into the output stream.
devices Prints the available audio devices.
help Prints the help page.
version Prints the version of the program.

Nearly all commands have a bunch of options. You can find them by using the --help option.
For example: pspectrum web --help.

How to use

Using PSpectrum should be quite easy.
By using the listen command, PSpectrum will print the audio data into the output stream.
The data that gets printed, is an array of floats containing the audio data of the left and right channel.
You can change the size of the data by using the --buffer-size option.

For example: pspectrum listen --buffer-size=1024
This will return float arrays of size 1024.
The first 512 floats represent the left channel, the next 512 floats the right channel.

Node.js Example
const { spawn } = require('child_process');

// spawn PSpectrum
var pspectrum = spawn('PSpectrum.exe', ['listen']);

// process the output
pspectrum.stdout.on('data', (line) => {
  let data = JSON.parse(line);               // this will contain the left and right channel
  let left = data.slice(0, data.length / 2); // left channel
  let right = data.slice(data.length / 2);   // right channel

  // do something with the data
  ...
});

v1 vs v2

PSpectrum v2 is basically a complete rewrite of the program. It is more stable and has a lot of new features.
The normalization of the audio data has been greatly improved. In v1 the audio data had a maximum of 2 normalization levels. v2 allows infinite normalization levels.
As I mentioned earlier, v2 also has a demo visualizer running in your browser. For the moments when you want to do something like this.

Demos

Web Command
PSpectrum.exe web -b 512
Listen Command
PSpectrum.exe listen -b 64
Devices Command
PSpectrum.exe devices --output
PSpectrum.exe devices --input