wf-fragment-adapter

1.0.0 • Public • Published

Waveform data fragment adapter

wf-fragment-adapter is an adapter for waveform-data that allows you to render only a subset of the full graph, and treat it as the full graph.

Let's say you have a sound file that is three hours long, and you're only interested in rendering the graph representing 01:00:00 to 01:30:00, you'd do this:

var WaveformData = require("waveform-data");
var createFragmentAdapter = require("wf-fragment-adapter").createFragmentAdapter;

var start = 3600; // One hour
var duration = 1800; // Half an hour
var data = new WaveformData(wfArrayBuffer, createFragmentAdapter(start, duration));

But why?

WaveformData provides a mechanism for resampling and offsetting data to focus on parts of the graph, so why write a separate adapter for doing the same thing? If you for some reason want to enforce a permanent view on parts of the graph, using WaveformData's offsets and resampling are not practical, because you must manually apply them whenever you make changes in the current view. Couple this with the fact that you cannot nest offsets or segments, and you have a solution where information about the fragment spreads across your entire app.

When rendering multiple UI components based on the same waveform data, using this adapter to enforce the fragment being viewed reduces overall complexity and makes sure you only need to know about the actual start and offset in one place.

As an example, this adapter was originally written to handle the situation where the sound file to be played/visualized contained start/end padding - information that was not relevant in play mode (only while editing). Removing the pads with an adapter spared us from spreading the information about start and duration throughout the system.

Dependents (0)

Package Sidebar

Install

npm i wf-fragment-adapter

Weekly Downloads

1

Version

1.0.0

License

ISC

Last publish

Collaborators

  • cjohansen