npm package: @ircam/sc-signal
Description: Set of simple processing utilities
Latest version: 1.2.0

# @ircam/sc-signal

Simple signal processing utilities.

## Install

```sh

npm install --save @ircam/sc-signal

```

## API

<!-- api -->
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### Table of Contents

*   [Clipper][1]
*   [Hysteresis][2]
*   [Lowpass][3]
*   [Scaler][4]

## Clipper

Represents a Clipper object that limits the range of input values.

### Parameters

*   `$0` **[Object][5]**  (optional, default `{}`)

    *   `$0.min`   (optional, default `-Infinity`)
    *   `$0.max`   (optional, default `Infinity`)
*   `options` **[Object][5]?** The options object.

### Examples

```javascript
// clip to [0,1]
const clipper = new Clipper({
 min: 0,
 max: 1,
});

clipper.process(0.5); // 0.5
clipper.process(2); // 1
clipper.process(-1); // 0
```

```javascript
// min only
const clipper = new Clipper({
  min: 0,
});

clipper.process(0.5); // 0.5
clipper.process(2); // 2
clipper.process(-1); // 0
```

### set

Sets the attributes of the Clipper object.

#### Parameters

*   `attributes` **[Object][5]** The attributes to be set. Same as constructor options.

### process

Processes the input value and returns the clipped value within the specified range.

#### Parameters

*   `inputValue` **[number][6]** The input value to be processed.

Returns **[number][6]** The clipped value within the specified range.

## Hysteresis

Represents an Hysteresis filter.

### Parameters

*   `$0` **[Object][5]**  (optional, default `{}`)

    *   `$0.sampleRate`   (optional, default `2`)
    *   `$0.lowpassFrequencyUp`   (optional, default `0.5`)
    *   `$0.lowpassFrequencyDown`   (optional, default `0.5`)
*   `options` **[Object][5]?** The options object.

### Examples

```javascript
// hysteresis with quick up and slow down
const hysteresis = new Hysteresis({
 sampleRate: 2, // normalised frequency
 lowpassFrequencyUp: 0.9,
 lowpassFrequencyDown: 0.1,
});

hysteresis.process(0); // 0
hysteresis.process(1); // 0.9
hyteresis.process(1); // 0.99
hysteresis.process(1); // 0.999
hysteresis.process(1); // 0.9999
hysteresis.process(1); // 0.99999
hysteresis.process(1); // 0.999999
hysteresis.process(0); // 0.899999
hysteresis.process(0); // 0.809999
hysteresis.process(0); // 0.728999
hysteresis.process(0); // 0.656099
hysteresis.process(0); // 0.590489
```

### set

Sets the attributes of the Hysteresis filter.

#### Parameters

*   `attributes` **[Object][5]** The attributes to set. Same as constructor options.

### init

Initializes the Hysteresis filter.

### process

Processes the input value through the Hysteresis filter.

#### Parameters

*   `inputValue` **[number][6]** The input value to process.

Returns **[number][6]** The output value of the Hysteresis filter.

### reset

Resets the Hysteresis filter.

## Lowpass

Represents a Lowpass filter.

### Parameters

*   `$0` **[Object][5]**  (optional, default `{}`)

    *   `$0.sampleRate`   (optional, default `2`)
    *   `$0.lowpassFrequency`   (optional, default `0.5`)
*   `options` **[Object][5]?** The options object.

### Examples

```javascript
const lowpass = new Lowpass({
sampleRate: 2, // normalised frequency
lowpassFrequency: 0.9,
});

lowpass.process(0); // 0
lowpass.process(1); // 0.9
lowpass.process(1); // 0.99
lowpass.process(1); // 0.999
lowpass.process(1); // 0.9999
lowpass.process(1); // 0.99999
lowpass.process(1); // 0.999999
```

### set

Sets the attributes of the Lowpass filter.

#### Parameters

*   `attributes` **[Object][5]** The attributes to set. Same as constructor options.

### init

Initializes the Lowpass filter.

### process

Processes the input value through the Lowpass filter.

#### Parameters

*   `inputValue` **[number][6]** The input value to process.

Returns **[number][6]** The filtered output value.

### reset

Resets the Lowpass filter.

## Scaler

Represents a Scaler that maps values from an input range to an output range.

### Parameters

*   `$0` **[Object][5]**  (optional, default `{}`)

    *   `$0.inputStart`   (optional, default `0`)
    *   `$0.inputEnd`   (optional, default `1`)
    *   `$0.outputStart`   (optional, default `0`)
    *   `$0.outputEnd`   (optional, default `1`)
    *   `$0.clip`   (optional, default `false`)
    *   `$0.type`   (optional, default `'linear'`)
    *   `$0.base`   (optional, default `1`)
*   `options` **[Object][5]?** The options object.

### Examples

```javascript
// linear
const scaler = new Scaler({
  inputStart: 0,
  inputEnd: 10,
  outputStart: 0,
  outputEnd: 100,
});

scaler.process(5); // 50
scaler.process(0); // 0
scaler.process(10); // 100
```

```javascript
// MIDI pitch to Hertz
const scaler = new Scaler({
  inputStart: 69,
  inputEnd: 81,
  outputStart: 440,
  outputEnd: 880,
  type: 'exponential',
  base: 2,
  clip: false,
});

scaler.process(69); // 440
scaler.process(81); // 880
scaler.process(72); // 523.251131
scaler.process(93); // 1760 (no clipping)
```

```javascript
// decibel to amplitude
const scaler = new Scaler({
  inputStart: 0,
  inputEnd: 20,
  outputStart: 1,
  outputEnd: 10,
  type: 'exponential',
  base: 10,
  clip: false,
});

scaler.process(0); // 1
scaler.process(20); // 10
scaler.process(-20); // 0.1 (no clipping)
```

### set

Set the scaler attributes.

#### Parameters

*   `attributes` **[Object][5]** The attributes to set. Same as constructor options.

### init

Initialize the scaler.

### process

Process the input value and return the scaled value.

#### Parameters

*   `inputValue` **[number][6]** The input value to scale.

Returns **[number][6]** The scaled output value.

[1]: #clipper

[2]: #hysteresis

[3]: #lowpass

[4]: #scaler

[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object

[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number

<!-- apistop -->

## License

[BSD-3-Clause](./LICENSE)