Liking cljdoc? Tell your friends :D

clojure2d.extra.signal

Signal processing and generation.

Signal

Signal is array of doubles from range [-1.0.1.0] packed into Signal type.

Signal can be:

  • obtained from Pixels with pixels->signal function.
  • generated by calling [[signal-from-wave]].
  • loaded from file with load-signal function. Signal should be encoded as 16-bit signed integer big endian.

Pixels as Signal

Pixels (Image) can be treated as Signal. Conversion to Signal is based on strategies of converting image to RAW and then converting to audio. It includes channel data layout and packing into integer, encoding, endianess, etc.

To convert Pixels to Signal use pixels->signal function. To convert back use signal->pixels. signal->pixels requires target Pixels object to store result of conversion. Target is mutated then.

To filter Pixels directly (without explicit conversion to and from Signals) you can use [[filter-channels]] with effects-filter.

Wave as Signal

You can create wave function from oscillator. You can also sum waves with sum-waves.

To sample wave to signal, call wave->signal with following parameters:

  • f - wave function
  • samplerate - sample rate (samples per second)
  • seconds - how many seconds generate

File operations

You can save-signal or load-signal. Representation is 16 bit signed, big endian. Use Audacity or SoX to convert to/from audio files.

Signal processing

To process Signal use apply-effects function on it.

Effect is signal filter, created with effect multimethod. Effects can be composed with compose-effects. Effect can be treated as function and can be called for given sample.

Each effect has it's own parametrization which should be passed during creation.

List of all available effects is under effects-list value.

Effects parametrization

Each effect has its own parametrization

:simple-lowpass, :simple-highpass

  • :rate - sample rate (default 44100.0)
  • :cutoff - cutoff frequency (default 2000.0)

:biquad-eq

Biquad equalizer

  • :fc - center frequency
  • :gain - gain
  • :bw - bandwidth (default: 1.0)
  • :fs - sampling rate (defatult: 44100.0)

:biquad-hs, :biquad-ls

Biquad highpass and lowpass shelf filters

  • :fc - center frequency
  • :gain - gain
  • :slope - shelf slope (default 1.5)
  • :fs - sampling rate (default 44100.0)

:biquad-lp, :biquad-hp, :biquad-bp

Biquad lowpass, highpass and bandpass filters

  • :fc - cutoff/center frequency
  • :bw - bandwidth (default 1.0)
  • :fs - sampling rate (default 44100.0)

:dj-eq

  • :high - high frequency gain (10000Hz)
  • :mid - mid frequency gain (1000Hz)
  • :low - low frequency gain (100Hz)
  • :shelf-slope - shelf slope for high frequency (default 1.5)
  • :peak-bw - peak bandwidth for mid and low frequencies (default 1.0)
  • :rate - sampling rate (default 44100.0)

:phaser-allpass

  • :delay - delay factor (default: 0.5)

:divider

  • :denom (long, default 2.0)

:fm

Modulate and demodulate signal using frequency

  • :quant - quantization value (0.0 - if no quantization, default 10)
  • :omega - carrier factor (default 0.014)
  • :phase - deviation factor (default 0.00822)

:bandwidth-limit

https://searchcode.com/file/18573523/cmt/src/lofi.cpp#

  • :rate - sample rate (default 44100.0)
  • :freq - cutoff frequency (default 1000.0)

:distort

  • :factor - distortion factor (default 1.0)

:foverdrive

Fast overdrive

  • :drive - drive (default 2.0)

:decimator

  • :bits - bit depth (default 2)
  • :fs - decimator sample rate (default 4410.0)
  • :rate - input sample rate (default 44100.0)

:basstreble

  • :bass - bass gain (default 1.0)
  • :treble - treble gain (default 1.0)
  • :gain - gain (default 0.0)
  • :rate - sample rate (default 44100.0)
  • :slope - slope for both (default 0.4)
  • :bass-freq - bass freq (default 250.0)
  • :treble-freq - treble freq (default 4000.0)

:echo

  • :delay - delay time in seconds (default 0.5)
  • :decay - decay (amount echo in signal, default 0.5)
  • :rate - sample rate (default 44100.0)

Warning! Echo filter uses mutable array as a internal state, don't use the same filter in paraller processing.

:vcf303

  • :rate - sample rate (default 44100.0)
  • :trigger - boolean, trigger some action (default false), set true when you reset filter every line
  • :cutoff - cutoff frequency (values 0-1, default 0.8)
  • :resonance - resonance (values 0-1, default 0.8)
  • :env-mod - envelope modulation (values 0-1, default 0.5)
  • :decay - decay (values 0-1, default 1.0)
  • :gain - gain output signal (default: 1.0)

:slew-limit

http://git.drobilla.net/cgit.cgi/omins.lv2.git/tree/src/slew_limiter.c

  • :rate - sample rate
  • :maxrise - maximum change for rising signal (in terms of 1/rate steps, default 500)
  • :maxfall - maximum change for falling singal (default 500)

:mda-thru-zero

  • :rate - sample rate
  • :speed - effect rate
  • :depth
  • :mix
  • :depth-mod
  • :feedback

Warning: like :echo internal state is kept in doubles array.

Signal processing and generation.

## Signal

Signal is array of doubles from range `[-1.0.1.0]` packed into `Signal` type.

Signal can be:

* obtained from `Pixels` with [[pixels->signal]] function.
* generated by calling [[signal-from-wave]].
* loaded from file with [[load-signal]] function. Signal should be encoded as 16-bit signed integer big endian.

### Pixels as Signal

`Pixels` (`Image`) can be treated as `Signal`. Conversion to Signal is based on strategies of converting image to RAW and then converting to audio. It includes channel data layout and packing into integer, encoding, endianess, etc.

To convert `Pixels` to `Signal` use [[pixels->signal]] function. To convert back use [[signal->pixels]]. [[signal->pixels]] requires target `Pixels` object to store result of conversion. Target is mutated then.

To filter `Pixels` directly (without explicit conversion to and from Signals) you can use [[filter-channels]] with [[effects-filter]].

### Wave as Signal

You can create [[wave]] function from oscillator. You can also sum waves with [[sum-waves]].

To sample wave to signal, call [[wave->signal]] with following parameters:

* `f` - wave function
* `samplerate` - sample rate (samples per second)
* `seconds` - how many seconds generate

### File operations

You can [[save-signal]] or [[load-signal]]. Representation is 16 bit signed, big endian. Use Audacity or SoX to convert to/from audio files.

## Signal processing

To process Signal use [[apply-effects]] function on it.

Effect is signal filter, created with [[effect]] multimethod. Effects can be composed with [[compose-effects]]. Effect can be treated as function and can be called for given sample.

Each effect has it's own parametrization which should be passed during creation.

List of all available effects is under [[effects-list]] value.

### Effects parametrization

Each effect has its own parametrization

#### :simple-lowpass, :simple-highpass

* `:rate` - sample rate (default 44100.0)
* `:cutoff` - cutoff frequency (default 2000.0)

#### :biquad-eq

Biquad equalizer

* `:fc` - center frequency
* `:gain` - gain
* `:bw` - bandwidth (default: 1.0)
* `:fs` - sampling rate (defatult: 44100.0)

#### :biquad-hs, :biquad-ls

Biquad highpass and lowpass shelf filters

* `:fc` - center frequency
* `:gain` - gain
* `:slope` - shelf slope (default 1.5)
* `:fs` - sampling rate (default 44100.0)

#### :biquad-lp, :biquad-hp, :biquad-bp

Biquad lowpass, highpass and bandpass filters

* `:fc` - cutoff/center frequency
* `:bw` - bandwidth (default 1.0)
* `:fs` - sampling rate (default 44100.0)

#### :dj-eq

* `:high` - high frequency gain (10000Hz)
* `:mid` - mid frequency gain (1000Hz)
* `:low` - low frequency gain (100Hz)
* `:shelf-slope` - shelf slope for high frequency (default 1.5)
* `:peak-bw` - peak bandwidth for mid and low frequencies (default 1.0)
* `:rate` - sampling rate (default 44100.0)

#### :phaser-allpass

* `:delay` - delay factor (default: 0.5)

#### :divider

* `:denom` (long, default 2.0)

#### :fm

Modulate and demodulate signal using frequency

 * `:quant` - quantization value (0.0 - if no quantization, default 10)
 * `:omega` - carrier factor (default 0.014)
 * `:phase` - deviation factor (default 0.00822)

#### :bandwidth-limit

https://searchcode.com/file/18573523/cmt/src/lofi.cpp#

* `:rate` - sample rate (default 44100.0)
* `:freq` - cutoff frequency (default 1000.0)

#### :distort

* `:factor` - distortion factor (default 1.0)

#### :foverdrive

Fast overdrive

* `:drive` - drive (default 2.0)

#### :decimator

* `:bits` - bit depth (default 2)
* `:fs` - decimator sample rate (default 4410.0)
* `:rate` - input sample rate (default 44100.0)

#### :basstreble

* `:bass` - bass gain (default 1.0)
* `:treble` - treble gain (default 1.0)
* `:gain` - gain (default 0.0)
* `:rate` - sample rate (default 44100.0)
* `:slope` - slope for both (default 0.4)
* `:bass-freq` - bass freq (default 250.0)
* `:treble-freq` - treble freq (default 4000.0)

#### :echo

* `:delay` - delay time in seconds (default 0.5)
* `:decay` - decay (amount echo in signal, default 0.5)
* `:rate` - sample rate (default 44100.0)

_Warning! Echo filter uses mutable array as a internal state, don't use the same filter in paraller processing._

#### :vcf303

* `:rate` - sample rate (default 44100.0)
* `:trigger` - boolean, trigger some action (default `false`), set true when you reset filter every line
* `:cutoff` - cutoff frequency (values 0-1, default 0.8)
* `:resonance` - resonance (values 0-1, default 0.8)
* `:env-mod` - envelope modulation (values 0-1, default 0.5)
* `:decay` - decay (values 0-1, default 1.0)
* `:gain` - gain output signal (default: 1.0)

#### :slew-limit

http://git.drobilla.net/cgit.cgi/omins.lv2.git/tree/src/slew_limiter.c

* `:rate` - sample rate
* `:maxrise` - maximum change for rising signal (in terms of 1/rate steps, default 500)
* `:maxfall` - maximum change for falling singal (default 500)

#### :mda-thru-zero

* `:rate` - sample rate
* `:speed` - effect rate
* `:depth`
* `:mix`
* `:depth-mod`
* `:feedback`

_Warning: like `:echo` internal state is kept in doubles array._
raw docstring

apply-effectsclj

(apply-effects sig effects)
(apply-effects s effects reset)

Apply effects to signal.

If reset is positive, reinit state each reset number of samples.

Returns new signal.

Apply effects to signal.

If `reset` is positive, reinit state each `reset` number of samples.

Returns new signal.
sourceraw docstring

apply-effects-to-pixelsclj

(apply-effects-to-pixels effects pixels)
(apply-effects-to-pixels effects reset pixels)
(apply-effects-to-pixels effects config config-back pixels)
(apply-effects-to-pixels effects config config-back reset pixels)

Apply effects directly to Pixels.

Provide configurations to properly convert Pixels to Signal and back. Optionally set reset value (reinit effects' state after reset samples).

If you prefer operating through [[filter-channels]] use [[effect-filter]].

Apply effects directly to `Pixels`.

Provide configurations to properly convert Pixels to Signal and back.
Optionally set `reset` value (reinit effects' state after `reset` samples).
  
If you prefer operating through [[filter-channels]] use [[effect-filter]].
sourceraw docstring

compose-effectsclj

(compose-effects e & es)

Compose effects.

Compose effects.
sourceraw docstring

db->linearclj

(db->linear x)

DB to Linear

DB to Linear
sourceraw docstring

effectcljmultimethod

Create effect for given name (as keyword) and optional parametrization.

List of all possible effects is under effects-list.

Effect is a custom type which contains: name, sample (result of last call), effect function and current state.

Effect can be considered as function: call with sample to effect with next state or call without parameter to obtain latest result. Effects are also composable with compose-effects.

Create effect for given name (as keyword) and optional parametrization.

List of all possible effects is under [[effects-list]].

Effect is a custom type which contains: name, sample (result of last call), effect function and current state.

Effect can be considered as function: call with sample to effect with next state or call without parameter to obtain latest result. Effects are also composable with [[compose-effects]].
sourceraw docstring

effects-filterclj

(effects-filter effects)
(effects-filter effects reset)
(effects-filter effects config config-back)
(effects-filter effects config config-back reset)

Creates filter to process Pixels as Signal using [[filter-channels]].

Provide configurations to properly convert Pixels to Signal and back. Optionally set reset value (reinit effects' state after reset samples).

Filter operates on one channel at time and is defined to be used with [[filter-channels]]. If you want to operate on Pixels directly, use apply-effects-to-pixels.

Creates filter to process `Pixels` as `Signal` using [[filter-channels]].

Provide configurations to properly convert Pixels to Signal and back.
Optionally set `reset` value (reinit effects' state after `reset` samples).

Filter operates on one channel at time and is defined to be used with [[filter-channels]].
If you want to operate on `Pixels` directly, use [[apply-effects-to-pixels]].
sourceraw docstring

effects-listclj

List of effects.

List of effects.
sourceraw docstring

linear->dbclj

(linear->db x)

Linear to DB

Linear to DB
sourceraw docstring

load-signalclj

(load-signal filename)

Read signal from file

Expected representation is 16 bit signed, big endian file.

Read signal from file

Expected representation is 16 bit signed, big endian file.
sourceraw docstring

oscillatorsclj

List of oscillator names used with wave

List of oscillator names used with [[wave]]
sourceraw docstring

pixels->signalclj

(pixels->signal p)
(pixels->signal p
                {:keys [planar? signed? little-endian? bits channels coding]
                 :or {planar? true
                      little-endian? true
                      bits 8
                      signed? false
                      channels [0 1 2]
                      coding :none}})

Convert Pixels to Signal for given specifications.

Specification for conversion is based on Audacity importing options and image to RAW conversions practices. Spec contains:

  • planar? - layout of channels data, planar (true, default) or interleaved (false)
  • signed? - channel data are encoded as signed (true, default) or unsigned (false) integer.
  • little-endian? - for 16 and 24 bits pack channel data with little-endian order (true, default) or big-endian (false)
  • bits - pack channel data in 8 (default), 16 or 24 bits.
  • channels - list of channels to convert to signal, default [0 1 2] (for all you can use :all keyword).
  • coding - encode signal with one of the encoders: :alaw, :alaw-rev, :ulaw, :ulaw-rev or :none (default).

Pixels can be restored from Signal with signal->pixels function.

Convert `Pixels` to `Signal` for given specifications.

Specification for conversion is based on Audacity importing options and image to RAW conversions practices. Spec contains:

* `planar?` - layout of channels data, planar (true, default) or interleaved (false)
* `signed?` - channel data are encoded as signed (true, default) or unsigned (false) integer.
* `little-endian?` - for 16 and 24 bits pack channel data with little-endian order (true, default) or big-endian (false)
* `bits` - pack channel data in 8 (default), 16 or 24 bits.
* `channels` - list of channels to convert to signal, default `[0 1 2]` (for all you can use `:all` keyword).
* `coding` - encode signal with one of the encoders: `:alaw`, `:alaw-rev`, `:ulaw`, `:ulaw-rev` or `:none` (default).

Pixels can be restored from Signal with [[signal->pixels]] function.
sourceraw docstring

save-signalclj

(save-signal s filename)

Save signal to file.

Representation is: 16 bit signed, big endian file You can use Audacity/SOX utilities to convert files to audio.

Save signal to file.

Representation is: 16 bit signed, big endian file
You can use Audacity/SOX utilities to convert files to audio.
sourceraw docstring

signalclj

(signal xs)

Signal creator

Signal creator
sourceraw docstring

signal->pixelsclj

(signal->pixels sig target)
(signal->pixels sig
                target
                {:keys [planar? signed? little-endian? bits channels coding]
                 :or {planar? true
                      little-endian? true
                      bits 8
                      signed? false
                      channels [0 1 2]
                      coding :none}})

Convert Signal to Pixels storing result into target (mutating it!).

Specification is the same as in [[pixels-signal]] functions.

Convert `Signal` to `Pixels` storing result into `target` (mutating it!).

Specification is the same as in [[pixels-signal]] functions.
sourceraw docstring

sum-wavesclj

(sum-waves & fs)

Create wave which is sum of all waves.

Create wave which is sum of all waves.
sourceraw docstring

wavecljmultimethod

Create waves from various oscilators

Parameters are:

  • oscilator name (see oscillators variable)
  • frequency
  • amplitude
  • phase (0-1)

Multimethod creates oscillator function accepting double (time) and resulting double from [-1.0 1.0] range.

To convert wave to Signal, call [[signal-from-wave]].

To add waves, call sum-waves.

Create waves from various oscilators

Parameters are:

* oscilator name (see `oscillators` variable)
* frequency
* amplitude
* phase (0-1)

Multimethod creates oscillator function accepting `double` (time) and resulting `double` from [-1.0 1.0] range.

To convert `wave` to Signal, call [[signal-from-wave]].

To add waves, call [[sum-waves]].
sourceraw docstring

wave->signalclj

(wave->signal f samplerate seconds)

Create Signal from wave. Parameters are: f - oscillator, samplerate and number of seconds.

Create Signal from wave. Parameters are: f - oscillator, samplerate and number of seconds.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close