Class: SignalRecorder

SignalRecorder

Record an signal input stream of arbitrary duration and retrieve it when done.

When recording is stopped (either when the stop method is called, the defined duration has been recorded, or the source of the graph finalized the stream), the callback given as parameter is executed with the AudioBuffer or Float32Array containing the recorded signal as argument.

Constructor

new SignalRecorder(options)

Parameters:
Name Type Description
options Object

Override default parameters.

Properties
Name Type Attributes Default Description
duration Number <optional>
10

Maximum duration of the recording.

callback Number <optional>

Callback to execute when a new record is ended. This can happen: stop is called on the recorder, stop is called on the source or when the buffer is full according to the given duration.

ignoreLeadingZeros Object <optional>
true

Start the effective recording on the first non-zero value.

retrieveAudioBuffer Boolean <optional>
false

Define if an AudioBuffer should be retrieved or only the raw Float32Array of data. (works only in browser)

audioContext AudioContext <optional>
null

If retrieveAudioBuffer is set to true, audio context to be used in order to create the final audio buffer. (works only in browser)

Source:
To Do:
  • - add option to return only the Float32Array and not an audio buffer (node compliant) `retrieveAudioBuffer: false`
Example
import * as lfo from 'waves-lfo/client';

const audioContext = new AudioContext();

navigator.mediaDevices
  .getUserMedia({ audio: true })
  .then(init)
  .catch((err) => console.error(err.stack));

function init(stream) {
  const source = audioContext.createMediaStreamSource(stream);

  const audioInNode = new lfo.source.AudioInNode({
    sourceNode: source,
    audioContext: audioContext,
  });

  const signalRecorder = new lfo.sink.SignalRecorder({
    duration: 6,
    retrieveAudioBuffer: true,
    audioContext: audioContext,
    callback: (buffer) => {
      const bufferSource = audioContext.createBufferSource();
      bufferSource.buffer = buffer;
      bufferSource.connect(audioContext.destination);
      bufferSource.start();
    }
  });

  audioInNode.connect(signalRecorder);
  audioInNode.start();
  signalRecorder.start();
});

Methods

start()

Start recording.

Source:

stop()

Stop recording and execute the callback defined in parameters.

Source: