@ircam/sc-process
v1.0.1
Published
Set of simple processing utilities
Downloads
2
Readme
@ircam/sc-signal
Simple signal processing utilities.
Install
npm install --save @ircam/sc-signal
API
Table of Contents
Clipper
Represents a Clipper object that limits the range of input values.
Parameters
$0
Object (optional, default{}
)$0.min
(optional, default-Infinity
)$0.max
(optional, defaultInfinity
)
options
Object? The options object.
Examples
// 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
// 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 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 The input value to be processed.
Returns number The clipped value within the specified range.
Hysteresis
Represents an Hysteresis filter.
Parameters
$0
Object (optional, default{}
)$0.sampleRate
(optional, default2
)$0.lowpassFrequencyUp
(optional, default0.5
)$0.lowpassFrequencyDown
(optional, default0.5
)
options
Object? The options object.
Examples
// 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 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 The input value to process.
Returns number The output value of the Hysteresis filter.
reset
Resets the Hysteresis filter.
Lowpass
Represents a Lowpass filter.
Parameters
$0
Object (optional, default{}
)$0.sampleRate
(optional, default2
)$0.lowpassFrequency
(optional, default0.5
)
options
Object? The options object.
Examples
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 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 The input value to process.
Returns number 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 (optional, default{}
)$0.inputStart
(optional, default0
)$0.inputEnd
(optional, default1
)$0.outputStart
(optional, default0
)$0.outputEnd
(optional, default1
)$0.clip
(optional, defaultfalse
)$0.type
(optional, default'linear'
)$0.base
(optional, default1
)
options
Object? The options object.
Examples
// 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
// 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)
// 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 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 The input value to scale.
Returns number The scaled output value.