• Stars
    star
    155
  • Rank 233,339 (Top 5 %)
  • Language
    C++
  • License
    MIT License
  • Created over 10 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

bindings to libgroove - music player backend library

node-groove

Node.js bindings to libgroove - generic music player backend library.

Live discussion in #libgroove on freenode.

Here are the main interfaces. See API Documentation below for more details.

  • GrooveFile - represents an open audio file.
  • GroovePlaylist - put files in the playlist, and the playlist decodes the files and fills up the attached sinks.
  • GroovePlayer - attach this sink to a playlist to play the decoded audio over the system's speakers.
  • GrooveEncoder - attach this sink to a playlist to obtain encoded audio buffers, such as an mp3 stream.
  • GrooveLoudnessDetector - attach this sink to a playlist to compute how loud files sound to the human ear, along with the "true peak" value. You can use this to implement ReplayGain.
  • GrooveFingerprinter - attach this sink to a playlist to compute an acoustid fingerprint. This can be used to look up a file by its audio content and figure out which tags should be applied.
  • GrooveWaveformBuilder - attach this sink to a playlist to compute a JSON representation of an audio file. This can be used to display a visualization of the audio file.

Usage

  1. Install libgroove to your system. libgroove is a set of 4 libraries; node-groove depends on all of them. So for example on ubuntu, make sure to install libgroove-dev, libgrooveplayer-dev, libgrooveloudness-dev, and libgroovefingerprinter-dev.
  2. npm install --save groove

Versions

  • node-groove >=3.0.0 depends on libgroove >=5.0.0
  • node-groove >=2.4.0 <3.0.0 depends on libgroove >=4.3.0 <5.0.0
  • node-groove 2.3.4 depends on libgroove <4.3.0

See CHANGELOG.md for release notes and upgrade guide.

Get Metadata from File

var groove = require('groove');

groove.open("danse-macabre.ogg", function(err, file) {
  if (err) throw err;
  console.log(file.metadata());
  console.log("duration:", file.duration());
  file.close(function(err) {
    if (err) throw err;
  });
});

More Examples

  • example/metadata.js - read or update metadata in a media file
  • example/playlist.js - play several files in a row and then exit
  • example/replaygain.js - compute replaygain values for media files
  • example/transcode.js - convert and splice several files together
  • example/fingerprint.js - create an acoustid fingerprint for media files
  • example/devices.js - list the playback devices on the system
  • example/waveform.js - calculate a waveformjs compatible representation of a media file

API Documentation

globals

groove.setLogging(level)

level can be:

  • groove.LOG_QUIET
  • groove.LOG_ERROR
  • groove.LOG_WARNING
  • groove.LOG_INFO

groove.loudnessToReplayGain(loudness)

Converts a loudness value which is in LUFS to the ReplayGain-suggested dB adjustment.

groove.dBToFloat(dB)

Converts dB format volume adjustment to a floating point gain format.

groove.getVersion()

Returns an object with these properties:

  • major
  • minor
  • patch

GrooveFile

groove.open(filename, callback)

callback(err, file)

file.close(callback)

callback(err)

file.duration()

In seconds.

file.shortNames()

A comma-separated list of short names for the format.

file.getMetadata(key, [flags])

Flags:

  • groove.TAG_MATCH_CASE
  • groove.TAG_DONT_OVERWRITE
  • groove.TAG_APPEND

file.setMetadata(key, value, [flags])

See getMetadata for flags.

Pass null for value to delete a key.

file.metadata()

This returns an object populated with all the metadata. Updating the object does nothing. Use setMetadata to update metadata and then save to write changes to disk.

file.dirty

Boolean whether save will do anything.

file.filename

The string that was passed to groove.open

file.overrideDuration(duration)

If you know for sure the actual duration of the file, call this function to set the actual duration in seconds of the file. GrooveWaveformBuilder will use this value instead of file.duration().

This must only be called when no GroovePlaylistItem references to this file.

file.save(callback)

callback(err)

GroovePlaylist

groove.createPlaylist()

A playlist managers keeping an audio buffer full. To send the buffer to your speakers, use playlist.createPlayer().

Note: you probably only want one playlist. In node-groove, a playlist is a low-level audio processing concept, not to be confused with user-facing playlists where users might add, remove, and re-order songs.

playlist.destroy()

When finished with your playlist you must destroy it.

playlist.items()

Returns a read-only array of playlist items. Use playlist.insert and playlist.remove to modify.

[playlistItem1, playlistItem2, ...]

playlist.play()

playlist.pause()

playlist.seek(playlistItem, position)

Seek to playlistItem, position seconds into the song.

playlist.insert(file, gain, peak, nextPlaylistItem)

Creates a new playlist item with file and puts it in the playlist before nextPlaylistItem. If nextPlaylistItem is null, appends the new item to the playlist.

gain is a float format volume adjustment that applies only to this item. defaults to 1.0

peak is float format, see item.peak. defaults to 1.0

Returns the newly added playlist item.

Once you add a file to the playlist, you must not file.close() it until you first remove it from the playlist.

playlist.remove(playlistItem)

Remove playlistItem from the playlist.

Note that you are responsible for calling file.close() on every file that you open with groove.open. playlist.remove will not close files.

playlist.position()

Returns {item, pos} where item is the playlist item currently being decoded and pos is how many seconds into the song the decode head is.

Note that typically you are more interested in the position of the play head, not the decode head. Example methods which return the play head are player.position() and encoder.position().

playlist.playing()

Returns true or false.

playlist.clear()

Remove all playlist items.

playlist.count()

How many items are on the playlist.

playlist.gain

playlist.setGain(value)

Between 0.0 and 1.0. You probably want to leave this at 1.0, since using replaygain will typically lower your volume a significant amount.

playlist.setItemGainPeak(playlistItem, gain, peak)

gain is a float that affects the volume of the specified playlist item only. To convert from dB to float, use exp(log(10) * 0.05 * dBValue).

See item.peak

playlist.setFillMode(mode)

mode can be:

  • groove.EVERY_SINK_FULL

    The playlist will decode audio if any sinks are not full. If any sinks do not drain fast enough the data will buffer up in the playlist.

  • groove.ANY_SINK_FULL

    This is the default behavior. With this behavior, the playlist will stop decoding audio when any attached sink is full, and then resume decoding audio every sink is not full.

Defaults to groove.EVERY_SINK_FULL.

GroovePlaylistItem

These are not instantiated directly; instead they are returned from playlist.items().

A GroovePlaylistItem is merely a pointer into a GroovePlaylist. If you remove a playlist item from a playlist, any playlist item references you have lying around become dangling pointers.

item.file

Read-only.

item.gain

A volume adjustment in float format to apply to the file when it plays. This is typically used for loudness compensation, for example ReplayGain. To convert from dB to float, use groove.dBToFloat

Read-only. Use playlist.setItemGain to modify.

item.peak

The sample peak of this playlist item is assumed to be 1.0 in float format. If you know for certain that the peak is less than 1.0, you may set this value which may allow the volume adjustment to use a pure amplifier rather than a compressor. This results in slightly better audio quality.

Read-only. Use playlist.setItemPeak to modify.

item.id

Every time you obtain a playlist item from groove, you will get a fresh JavaScript object, but it might point to the same underlying libgroove pointer as another. The id field is a way to check if two playlist items reference the same one.

Read-only.

GroovePlayer

groove.getDevices()

Before you can call this function, you must call groove.connectSoundBackend().

Returns an object like this:

{
  list: [
    {
      name: "User-Friendly Device Name",
      id: "unique device ID that persists across plugs and unplugs",
      isRaw: false, // true if this device would claim exclusive access
      probeError: 3, // non zero if scanning this device did not work
    },
    //...
  ],
  defaultIndex: 0,
}

groove.connectSoundBackend([backend])

backend is optional. If left blank the best backend is automatically selected. Otherwise it can be one of these:

  • groove.BACKEND_JACK
  • groove.BACKEND_PULSEAUDIO
  • groove.BACKEND_ALSA
  • groove.BACKEND_COREAUDIO
  • groove.BACKEND_WASAPI
  • groove.BACKEND_DUMMY

groove.disconnectSoundBackend()

groove.createPlayer()

Creates a GroovePlayer instance which you can then configure by setting properties.

player.device

Before calling attach(), set this to one of the devices returned from groove.getDevices().

player.attach(playlist, callback)

Sends audio to sound device.

callback(err)

player.detach(callback)

callback(err)

player.position()

Returns {item, pos} where item is the playlist item currently being played and pos is how many seconds into the song the play head is.

player.on('nowplaying', handler)

Fires when the item that is now playing changes. It can be null.

handler()

player.on('bufferunderrun', handler)

Fires when a buffer underrun occurs. Ideally you'll never see this.

handler()

player.on('devicereopened', handler)

Fires when you have set useExactAudioFormat to true and the audio device has been closed and re-opened to match incoming audio data.

handler()

GrooveEncoder

groove.createEncoder()

encoder.bitRate

select encoding quality by choosing a target bit rate

encoder.formatShortName

optional - help libgroove guess which format to use. avconv -formats to get a list of possibilities.

encoder.codecShortName

optional - help libgroove guess which codec to use. avconv-codecs to get a list of possibilities.

encoder.filename

optional - provide an example filename to help libgroove guess which format/codec to use.

encoder.mimeType

optional - provide a mime type string to help libgrooove guess which format/codec to use.

encoder.targetAudioFormat

The desired audio format settings with which to encode. groove.createEncoder() defaults these to 44100 Hz, signed 16-bit int, stereo. These are preferences; if a setting cannot be used, a substitute will be used instead. In this case, actualAudioFormat will be updated to reflect the substituted values.

Properties:

  • sampleRate
  • channelLayout - array of channel ids
  • sampleFormat

encoder.actualAudioFormat

groove sets this to the actual format you get when you attach the encoder. Ideally will be the same as targetAudioFormat but might not be.

Properties:

  • sampleRate
  • channelLayout - array of channel ids
  • sampleFormat

encoder.sinkBufferSize

How big the sink buffer should be, in sample frames. createEncoder defaults this to 8192

encoder.encodedBufferSize

How big the encoded audio buffer should be, in bytes. createEncoder defaults this to 16384

encoder.attach(playlist, callback)

callback(err)

encoder.detach(callback)

callback(err)

encoder.getBuffer()

Returns null if no buffer available, or an object with these properties:

  • buffer - a node Buffer instance which is the encoded data for this chunk this can be null in which case this buffer is actually the end of playlist sentinel.
  • item - the GroovePlaylistItem of which this buffer is encoded data for
  • pos - position in seconds that this buffer represents in into the item

encoder.on('buffer', handler)

handler()

Emitted when there is a buffer available to get. You still need to get the buffer with getBuffer().

encoder.position()

Returns {item, pos} where item is the playlist item currently being encoded and pos is how many seconds into the song the encode head is.

GrooveLoudnessDetector

groove.createLoudnessDetector()

returns a GrooveLoudnessDetector

detector.infoQueueSize

Set this to determine how far ahead into the playlist to look.

detector.disableAlbum

Set to true to only compute track loudness. This is faster and requires less memory than computing both.

detector.attach(playlist, callback)

callback(err)

detector.detach(callback)

callback(err)

detector.getInfo()

Returns null if no info available, or an object with these properties:

  • loudness - loudness in LUFS
  • peak - sample peak in float format of the file
  • duration - duration in seconds of the track
  • item - the GroovePlaylistItem that this applies to, or null if it applies to the entire album.

detector.position()

Returns {item, pos} where item is the playlist item currently being detected and pos is how many seconds into the song the detect head is.

detector.on('info', handler)

handler()

Emitted when there is info available to get. You still need to get the info with getInfo().

GrooveFingerprinter

groove.createFingerprinter()

returns a GrooveFingerprinter

groove.encodeFingerprint(rawFingerprint)

Given an Array of integers which is the raw fingerprint, encode it into a string which can be submitted to acoustid.org.

groove.decodeFingerprint(fingerprint)

Given the fingerprint string, returns a list of integers which is the raw fingerprint data.

printer.infoQueueSize

Set this to determine how far ahead into the playlist to look.

printer.attach(playlist, callback)

callback(err)

printer.detach(callback)

callback(err)

printer.getInfo()

Returns null if no info available, or an object with these properties:

  • fingerprint - integer array which is the raw fingerprint
  • duration - duration in seconds of the track
  • item - the GroovePlaylistItem that this applies to, or null if it applies to the entire album.

printer.position()

Returns {item, pos} where item is the playlist item currently being fingerprinted and pos is how many seconds into the song the printer head is.

printer.on('info', handler)

handler()

Emitted when there is info available to get. You still need to get the info with getInfo().

GrooveWaveformBuilder

groove.createWaveformBuilder()

returns a GrooveWaveformBuilder

waveform.widthInFrames

How many frames wide the waveform data will be. Defaults to 1920.

If you have a song with 100 frames and widthInFrames is 50, then each waveform data frame will correspond to 2 frames of the original song.

printer.infoQueueSizeBytes

Set this to determine how far ahead into the playlist to look.

waveform.attach(playlist, callback)

callback(err)

waveform.detach(callback)

callback(err)

waveform.getInfo()

Returns null if no info available, or an object with these properties:

  • buffer - A Buffer of the waveform data, one unsigned 8 bit integer per widthInFrames.
  • expectedDuration - This is the duration in seconds that was used to create the waveform data. If this is different than actualDuration then the data is invalid and must be re-calculated, this time using file.overrideDuration()
  • actualDuration - This is the correct duration in seconds for the track, known only after waveform calculation is complete.
  • item - the GroovePlaylistItem that this applies to, or null if this info signals the end of playlist.

waveform.position()

Returns {item, pos} where item is the playlist item currently being calculated and pos is how many seconds into the song the waveform head is.

waveform.on('info', handler)

handler()

Emitted when there is info available to get. You still need to get the info with getInfo().

More Repositories

1

groovebasin

Music player server with a web-based user interface.
JavaScript
1,851
star
2

libsoundio

C library for cross-platform real-time audio input and output
C
1,847
star
3

node-s3-client

high level amazon s3 client for node.js
JavaScript
1,004
star
4

naught

Zero downtime deployment for your Node.js server using builtin cluster API
JavaScript
788
star
5

poop

Performance Optimizer Observation Platform
Zig
712
star
6

jamulator

(unmaintained) recompiling NES roms into native executables
Go
388
star
7

tetris

A simple tetris clone written in zig programming language.
Zig
345
star
8

libgroove

streaming audio processing library
C
286
star
9

node-diacritics

remove diacritics from strings ("ascii folding") - Node.js module
JavaScript
259
star
10

waveform

simultaneously transcode and generate visuals for an audio file
C
251
star
11

HellOS

"hello world" x86 kernel example
Zig
235
star
12

clashos

multiplayer arcade game for bare metal Raspberry Pi 3 B+
Zig
206
star
13

genesis

Genesis Digital Audio Workstation
C++
176
star
14

chem

2d canvas-based rapid prototyping game engine
JavaScript
176
star
15

swig-email-templates

Node.js module for rendering emails with swig templates and email-friendly inline CSS using boost.
JavaScript
162
star
16

node-mv

Like `fs.rename`, but works across devices, and works with directories. Think of the unix utility `mv`.
JavaScript
155
star
17

ffmpeg

ffmpeg with the build system replaced by zig
C
113
star
18

zig-window

window client library
C++
106
star
19

node-waveform

simultaneously transcode audio and generate visuals - Node.js module
C
99
star
20

node-s3-cli

command line utility to go along with node s3 module
JavaScript
97
star
21

malcheck

Test your code with malcheck to make sure it handles out of memory conditions correctly.
C
95
star
22

mpd.js

Connect to a music player daemon server, send commands, emit events.
JavaScript
89
star
23

zig-wasi

Minimal WASI interpreter
C
87
star
24

zasm

multi-target assembler and disassembler
Zig
87
star
25

PyDaw

python library to mess with Digital Audio Workstations. FL Studio project files (.flp) supported.
C++
87
star
26

sdl-zig-demo

SDL2 hello world in zig
Zig
86
star
27

zig-vulkan-triangle

simple triangle displayed using vulkan, glfw, and zig
Zig
81
star
28

node-flp

FL Studio project file parser for node.js
JavaScript
72
star
29

node-tmx-parser

node.js module to parse and load tiled map editor maps (see mapeditor.org)
JavaScript
71
star
30

node-astar

Generic A* algorithm for node.js
JavaScript
67
star
31

node-sox

(unmaintained) node.js interface to the sox audio utility
JavaScript
61
star
32

mcserve

wraps minecraft server and gives you a web interface
JavaScript
54
star
33

zig-async-demo

Comparing concurrent code example programs between other languages and Zig
Zig
53
star
34

zig-general-purpose-allocator

work-in-progress general purpose allocator intended to be eventually merged into Zig standard library. live streamed development
Zig
45
star
35

StaticHttpFileServer

Zig module for serving a directory of files from memory via HTTP
Zig
44
star
36

autodoc

Zig Documentation Generator
Zig
44
star
37

node-perlin-noise

perlin noise generator for node.js
JavaScript
33
star
38

liblaxjson

C library for parsing JSON config files
C
32
star
39

lua-in-the-browser

using zig to build lua for webassembly
C
32
star
40

node-fd-slicer

safely create multiple ReadStream or WriteStream objects from the same file descriptor
JavaScript
30
star
41

flag2struct

simple CLI tool for converting zig source code using flags-style declarations to packed structs
Zig
28
star
42

connect-sse

connect middleware for server sent events (EventSource)
JavaScript
27
star
43

rucksack

texture packer and resource bundler
C
27
star
44

mime

zig package for mapping extensions to mime types
Zig
26
star
45

PyWaveform

Python library to create an image of a song's waveform
C
26
star
46

zig-stage1

Exploring replacing Zig's stage1 compiler with pure C code that outputs pure C code
C
25
star
47

libavfilter-example

small example of using libavfilter to filter audio
C
22
star
48

xml

Tokenize XML
Zig
22
star
49

node-plan

(unmaintained, deprecated, abandoned) Execute a complicated dependency graph of tasks with smooth progress events.
JavaScript
20
star
50

connect-static

static file server middleware for connect. loads files once at startup and saves gzipped versions in memory
JavaScript
19
star
51

dotfiles

linux yo
Nix
18
star
52

pyedsdk

Python library to control cameras via EDSDK
C
18
star
53

node-pend

dead-simple optimistic async helper in javascript
JavaScript
16
star
54

groove-rs

rust bindings to libgroove - streaming audio processing library
Rust
15
star
55

purgatory

escape from the circles of hell - 7 hour game jam
JavaScript
15
star
56

evo

specification, reference implementation, and examples of Evo, the programming language made for being the DNA of genetic algorithms
Zig
15
star
57

mediablast

(unmaintained, deprecated, abandoned) open source media processing server
JavaScript
14
star
58

browserify-lite

browserify, minus some of the advanced features and heavy dependencies
JavaScript
14
star
59

pillagers

Real time strategy game with space physics
JavaScript
12
star
60

hackerrank

my solutions to hackerrank puzzles
Go
11
star
61

connect-nocache

connect middleware to insert no cache headers
JavaScript
11
star
62

andrewkelley.me

my personal site
HTML
11
star
63

SIMD-test

exploring SIMD optimization
C
10
star
64

truthfinder

TruthFinder.org website
Python
10
star
65

mc-bot-server

(unmaintained) server that spins up minecraft bots
JavaScript
9
star
66

pulseaudio

pulseaudio with the build system replaced by zig
C
9
star
67

zig-mandelbrot-gl

mandelbrot set in zig
Zig
9
star
68

node-yawl

yet another websockets library for Node.js
JavaScript
8
star
69

clashproto

prototyping the game for andrewrk/clashos
Zig
8
star
70

planet-evo

evolution simulation software
C++
8
star
71

advent-of-code

https://adventofcode.com
Zig
8
star
72

node-music-library-index

node module to build a searchable javascript object model given track metadata objects
JavaScript
7
star
73

github-popularity-contest

see who has the most collective stars
JavaScript
7
star
74

node-human-size

tiny node.js module to get human readable file size from byte count
JavaScript
7
star
75

libmp3lame

libmp3lame with the build system replaced by zig
C
7
star
76

node-stream-counter

node.js module to keep track of how many bytes have been written to a stream
JavaScript
7
star
77

mpd

a fork of mpd to add library management, better search, and a sophisticated dynamic playlist
C
7
star
78

boost

Inline CSS into your HTML source
JavaScript
6
star
79

Secure-WordVault

(unmaintained, deprecated, abandoned) Enables you to store sensitive information in a portable manner
C++
6
star
80

TrenchBowl

simple music player UI to demonstrate libgroove
C++
6
star
81

node-spritesheet

node.js module: given a list of image files, create a spritesheet using cairo
JavaScript
6
star
82

chem-cli

html5 canvas game engine optimized for rapid development - command line interface
JavaScript
5
star
83

face-the-music

indie speed run game jam
JavaScript
5
star
84

dominion

Node.js module and command line program to play Dominion, the card game by Donald X. Vaccarino.
JavaScript
5
star
85

ruff

little tool to help my dad quickly find info in a .csv file
C++
5
star
86

gbremote

Groove Basin remote control command line app and Node.js module
JavaScript
5
star
87

archerbot

mineflayer bot that engages you in a gentlemanly duel
JavaScript
5
star
88

holocaust

html5 video game - rebuild society after a nuclear holocaust ravages the world
JavaScript
4
star
89

planetarius

Ludum Dare 30 Entry. networked multiplayer arcade shooter
JavaScript
4
star
90

Camlift-Controller

Controls a Canon camera and operates a motorized lift
Visual Basic
4
star
91

swig-dummy-context

given a swig template, create a dummy context which is useful for template composing tools
JavaScript
4
star
92

node-passthrough-truncate

truncate the last N bytes of a stream - Node.js module
JavaScript
3
star
93

scrabble

Scrabble solving AI
3
star
94

spacefight

vaporware 3D space-dogfighting simulator game
C++
3
star
95

math3d-rs

computer-graphics matrix calculations for dummies like me
Rust
3
star
96

lemming-js

PyWeek #12 entry ported to JavaScript with chem
JavaScript
3
star
97

pypowerusb

Python library to control a PowerUSB
C
3
star
98

opengl-multi-window-test

see if multiple windows in opengl causes a framerate issue
C
3
star
99

disinfecticide

A game about controlling a disease outbreak.
JavaScript
2
star
100

socketio-ssl-test

test whether we can use socket.io with xhr requests securely on an insecure page
JavaScript
2
star