• Stars
    star
    100
  • Rank 330,139 (Top 7 %)
  • Language
    HTML
  • Created almost 8 years ago
  • Updated about 1 year ago

Reviews

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

Repository Details

Performant waveform renderer.

gl-waveform unstable Build Status

Display time-domain data with WebGL. Provides fair performance / quality among other renderers:

  • no performance deterioration - O(n) for update, O(c) for rendering.
  • no memory limit - O(c * n).
  • no float32 error introduced by shader, at any scale/range/amount of data.
  • floating step compensation for non-regular sample sets.
  • unique render method of adjustable join-width via sample range sdev.

Demo 1, Demo 2

Usage

Install package as

npm i gl-waveform

Examplary set up is

let Waveform = require('gl-waveform')

// new component instance creates new canvas and puts that to document
let waveform = new Waveform()

// update method sets state of the component: data, color etc.
waveform.update({
	data: [0, .5, 1, .5, 0, -.5, -1, ...],
	color: 'gray',
	range: [0, 44100]
})

// render method draws frame, needs to be called when state is changed
waveform.render()

// push method appends new data
waveform.push(newData)
waveform.render()

API

waveform = new Waveform(arg|options?)

arg can be:

  • gl - existing webgl context.
  • regl - existing regl instance.
  • canvas - canvas element to initialize waveform on.
  • container - html element to use as a container for new canvas with webgl context.
  • waveform - gl-waveform instance to create a view for. In this case, the data will be shared.
  • none - new fullscreen canvas in the <body>.

options can provide:

Property Meaning
gl, regl, canvas, container Same as arg.
pixelRatio Device pixel ratio, by default window.devicePixelRatio.
clip Viewport area within the canvas, an array [left, top, width, height] or rectangle {x, y, width, height}, see parse-rect.
flip Use inverted webgl viewport direction (bottom β†’ top) instead of normal canvas2d direction (top β†’ bottom). By default false.
pick If picking data is required. By default true. Disabling reduces memory usage and increases push performance.

waveform.update(options)

Update state of the renderer instance. Possible options:

Property Meaning
data Array or typed array with sample values. Usually it contains values from -1..+1 range, but that can be adjusted via amplitude property. Can be a regl-texture instance or a list of textures, to share data between instances. If you need time series data, have a look at tick-array package to normalize input data values.
range Visible data x-range, an array [start, end] offsets or a number of the last samples to show. Can also be a 4-value array [xStart, minAmplitude, xEnd, maxAmplityde] compatible with other gl-components, in this case amplitude property is ignored. Negative number value counts data from the end. null range displays all available data.
amplitude Amplitudes range, number or array [min, max]. null value uses data min/max.
color Trace line color. Can be a color string or an array with float or uint values, eg. [0,0,1,1] or uint8<[100,120,255,255]>, see color-normalize.
thickness Trace line width, number in pixels or a string with units, eg. 3em.

waveform.set(data, offset=0)

Put samples data by the offset. Existing data by that offset is rewritten.

waveform.push(data)

Append new samples to the end.

waveform.render()

Draw trace frame according to the state.

waveform.pick(event|x)

Get information about samples at x coordinate relative to the canvas. Returns an object with props:

Property Meaning
average Average value for the picking point. The one actually visible on the screen.
sdev Standard deviance for the picking point.
x, y Actual coordinates of picking value relative to canvas.
offset An array with [left, right] offsets within data.

waveform.clear()

Clear viewport area dedicated for the instance.

waveform.destroy()

Dispose waveform instance, data and all assiciated resources.

Properties

  • waveform.gl - WebGL context.
  • waveform.canvas - canvas element.
  • waveform.regl - regl instance.

License

Β© 2018 Dmitry Yv. MIT License

More Repositories

1

wavefont

Typeface for rendering waveform/data
HTML
315
star
2

linefont

Font for rendering line chart data
JavaScript
156
star
3

gl-spectrum

πŸ“‰ Spectrum visualizer
JavaScript
93
star
4

pan-zoom

Pan / zoom for any element
JavaScript
88
star
5

sprae

DOM tree microhydration
JavaScript
76
star
6

spect

Observable selectors in DOM
JavaScript
74
star
7

settings-panel

Control panel for app, demo or tests
JavaScript
71
star
8

resizable

Resizable behavior for elements
JavaScript
68
star
9

subscript

Fast and tiny expression evaluator with minimal syntax.
JavaScript
68
star
10

gl-spectrogram

🌌 Render spectrogram of any audio source in webgl or canvas2d
JavaScript
62
star
11

svg-path-bounds

Get boundary box of svg path data
JavaScript
58
star
12

scope-css

Prefix each css selector with parent selector
JavaScript
57
star
13

bitmap-sdf

Calculate SDF for image/bitmap/bw data
JavaScript
43
star
14

svg-path-sdf

Generate signed distance bitmap for an svg path
JavaScript
42
star
15

save-file

Save any data to file in browser or node
JavaScript
42
star
16

plot-grid

2D/webgl grid for plots
JavaScript
33
star
17

fps-indicator

Tiny fps indicator for demo or tests
JavaScript
30
star
18

image-pixels

Load pixel data from any image source
JavaScript
29
star
19

gl-util

Set of practical webgl functions
JavaScript
25
star
20

enhook

Enable hooks for a function
JavaScript
24
star
21

wavearea

Multiline audio player / editor
JavaScript
23
star
22

arraybuffer-to-string

Convert ArrayBuffer to string
JavaScript
23
star
23

xhtm

XHTM βˆ’ eXtended Hyperscript Tagged Markup
JavaScript
23
star
24

draggy

Draggable provider
JavaScript
23
star
25

image-encode

Encode pixels data to PNG, GIF, BMP, TIF or JPG
JavaScript
22
star
26

unihooks

Universal unreacted hooks
JavaScript
21
star
27

image-decode

Decode image data from any image format
JavaScript
21
star
28

autoesm

Import esm in node@13+ based on source, not package.json
JavaScript
21
star
29

font-atlas-sdf

Populate <canvas> with SDF font atlas texture
JavaScript
19
star
30

sort-ids

Calculate ids corresponding to sorting an input array
JavaScript
19
star
31

image-output

Output image to a file, stream, canvas, console, buffer or any other destination
JavaScript
18
star
32

watr

Light & fast wasm text compiler & formatter
WebAssembly
18
star
33

optical-properties

Get character optical properties
JavaScript
18
star
34

gauge

Circular gauge indicator component
JavaScript
16
star
35

swapdom

Fast & tiny DOM differ
JavaScript
15
star
36

mell

Microlanguage for audio-processing
JavaScript
13
star
37

connection-line

Connector line DOM element (NOT MAINTAINED)
JavaScript
13
star
38

point-cluster

2d point clustering for datavis purposes.
JavaScript
12
star
39

dotprop

Get property value by string dot notation
JavaScript
12
star
40

image-equal

Test if two images are equal
JavaScript
11
star
41

sube

Subscribe to any reactive source, weakly
JavaScript
11
star
42

get-uid

Generate unique numeric id.
JavaScript
11
star
43

string-to-arraybuffer

Convert plain/base64/datauri string to ArrayBuffer
JavaScript
10
star
44

templize

Template parts for DOM elements
JavaScript
10
star
45

placer

Place any element relative to any other element the way you define
JavaScript
10
star
46

signal-struct

Combined signal storage
JavaScript
10
star
47

hyperf

Hypertext fragment builder
JavaScript
10
star
48

any-hooks

Resolve any installed hooks
JavaScript
9
star
49

tst

Tests without efforts
JavaScript
9
star
50

to-array-buffer

Convert any binary-like data to ArrayBuffer
JavaScript
9
star
51

color-tool

Color picker component
JavaScript
9
star
52

parse-fraction

Parse numerator and denominator from a string
JavaScript
8
star
53

weakset

Weakset polyfill.
JavaScript
8
star
54

element-props

Normalized access to element attributes/properties
JavaScript
8
star
55

emmy

Events toolkit
JavaScript
8
star
56

prepr

C/GLSL-preprocessor in JS
JavaScript
8
star
57

template-parts

Template Parts ponyfill
JavaScript
7
star
58

input-number

Make input recognize numbers
JavaScript
7
star
59

detect-kerning

Calculate kerning pairs for a font
JavaScript
7
star
60

wait-please

Await interval constructors
JavaScript
7
star
61

popoff

Create popups, dropdowns, tooltips and sidebars
JavaScript
7
star
62

st8

Tiny state machine
JavaScript
6
star
63

unhook

Unscoped hooks
JavaScript
6
star
64

analogs

Some research, thoughts and ideas for packages in browserify/webpack
JavaScript
6
star
65

key-name

Dict of keycodes for keynames
6
star
66

value-ref

Value reference with reactivity
JavaScript
6
star
67

slidy

Range slider component
JavaScript
6
star
68

array-rearrange

Rearrange array elements by index
JavaScript
6
star
69

parenthesis

Parse / stringify parenthesis
JavaScript
5
star
70

app-audio

Get audio for application, demo or tests.
JavaScript
5
star
71

pretty-number

Format number to more humane form than toFixed
JavaScript
5
star
72

typographic-hotkeys

Anyhotkeyβ„’ script that extends keyboard with typographic keys.
AutoHotkey
5
star
73

unimorph

Any-framework morphing engine
JavaScript
5
star
74

audio-experiment

Assorted sound experiments
JavaScript
5
star
75

color-ranger

Render range for a color space. Useful in color pickers.
JavaScript
5
star
76

primitive-pool

Get unique object for a primitive value to store primitives in WeakMap etc.
JavaScript
4
star
77

add-font

Attach font to the page by url or from array buffer
JavaScript
4
star
78

gaussian-fit

Fit mixture of gaussians into data
JavaScript
4
star
79

flip-pixels

Flip pixel data after readPixels
JavaScript
4
star
80

mobilify

πŸ“± Make stream of html mobile-friendly
JavaScript
4
star
81

aligner

Align DOM elements as Photoshop/Illustrator does
JavaScript
4
star
82

esdom

Build DOM from AST, change it and convert back to AST.
JavaScript
4
star
83

has-hover

Test if device has hover support
JavaScript
4
star
84

piano-game

Guess notes from stave
JavaScript
3
star
85

audio-lab

πŸ”¬ Audio streams playground
JavaScript
3
star
86

obj-map-prop

Map object properties by a dict
JavaScript
3
star
87

normal-pdf

Get gaussian density at a point
JavaScript
3
star
88

pxls

Convert any input pixels array to normalized 4-channel uint8 array
JavaScript
3
star
89

clip-pixels

Slice rectangle from pixels array
JavaScript
3
star
90

is-svg-path

Check if a string is an svg path data
JavaScript
3
star
91

polyline-clean

Clean polygon or polyline coordinates: remove duplicates, degenerate, collinear or bad items, trim.
JavaScript
2
star
92

parse-rect

Return rectangle object from any possible rect-like argument
JavaScript
2
star
93

to-uint8

Convert input argument to Uint8Array
JavaScript
2
star
94

cln

Clean source code for comparison
JavaScript
2
star
95

nogl

WebGL shim for node
JavaScript
2
star
96

lines-intersection

Get intersection point of two lines, if any
JavaScript
2
star
97

piano-key

Piano keys frequences
JavaScript
2
star
98

russi

Russian language tools
JavaScript
2
star
99

swizz

Provide swizzles for an array
JavaScript
2
star
100

enable-mobile

Provide mobile metas for app, demo or tests
JavaScript
1
star