Skip to content

Commit

Permalink
refactor(dsp): update imports
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Sep 10, 2021
1 parent 7c9d6c3 commit 02f1cf7
Show file tree
Hide file tree
Showing 32 changed files with 70 additions and 57 deletions.
2 changes: 1 addition & 1 deletion packages/dsp/src/comp/mapg.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Fn2, Fn3, Fn4, Fn5, FnAny } from "@thi.ng/api";
import { illegalArity } from "@thi.ng/errors";
import { illegalArity } from "@thi.ng/errors/illegal-arity";
import type { IGen } from "../api";
import { AGen } from "../gen/agen";

Expand Down
2 changes: 1 addition & 1 deletion packages/dsp/src/fft/power.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { NumericArray } from "@thi.ng/api";
import { isNumber } from "@thi.ng/checks";
import { isNumber } from "@thi.ng/checks/is-number";
import type { ComplexArray } from "../api";
import { isComplex } from "../util/complex";

Expand Down
14 changes: 8 additions & 6 deletions packages/dsp/src/fft/window.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { FloatArray, Fn, FnU3, FnU4, NumericArray } from "@thi.ng/api";
import { isNumber } from "@thi.ng/checks";
import { PI, TAU } from "@thi.ng/math";
import { isNumber } from "@thi.ng/checks/is-number";
import { PI, TAU } from "@thi.ng/math/api";
import type { WindowFn } from "../api";

// https://en.wikipedia.org/wiki/Window_function
Expand Down Expand Up @@ -105,7 +105,9 @@ export const windowBlackmanNuttall = windowCosSum4(
-0.0106411
);

export const windowGauss = (a = 0.4): WindowFn => (i, n) => {
n /= 2;
return Math.exp(-0.5 * ((i - n) / (a * n)) ** 2);
};
export const windowGauss =
(a = 0.4): WindowFn =>
(i, n) => {
n /= 2;
return Math.exp(-0.5 * ((i - n) / (a * n)) ** 2);
};
2 changes: 1 addition & 1 deletion packages/dsp/src/gen/adsr.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IReset } from "@thi.ng/api";
import { clamp01 } from "@thi.ng/math";
import { clamp01 } from "@thi.ng/math/interval";
import type { IGen } from "../api";
import { add } from "./add";
import { AGen } from "./agen";
Expand Down
2 changes: 1 addition & 1 deletion packages/dsp/src/gen/cosine.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IReset } from "@thi.ng/api";
import { TAU } from "@thi.ng/math";
import { TAU } from "@thi.ng/math/api";
import { AGen } from "./agen";

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/dsp/src/gen/osc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isNumber } from "@thi.ng/checks";
import { isNumber } from "@thi.ng/checks/is-number";
import type { IGen, StatelessOscillator } from "../api";
import { sum } from "../comp/sum";
import { Add, add } from "./add";
Expand Down
3 changes: 2 additions & 1 deletion packages/dsp/src/gen/pink-noise.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { IReset, Tuple } from "@thi.ng/api";
import { IRandom, SYSTEM } from "@thi.ng/random";
import type { IRandom } from "@thi.ng/random";
import { SYSTEM } from "@thi.ng/random/system";
import { AGen } from "./agen";

type PNoiseCoeffs = Tuple<number, 5>;
Expand Down
2 changes: 1 addition & 1 deletion packages/dsp/src/gen/sincos.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IReset } from "@thi.ng/api";
import { TAU } from "@thi.ng/math";
import { TAU } from "@thi.ng/math/api";
import { AGen } from "./agen";

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/dsp/src/gen/white-noise.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { IReset } from "@thi.ng/api";
import { IRandom, SYSTEM } from "@thi.ng/random";
import type { IRandom } from "@thi.ng/random";
import { SYSTEM } from "@thi.ng/random/system";
import { AGen } from "./agen";

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/dsp/src/osc/cos.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TAU } from "@thi.ng/math";
import { TAU } from "@thi.ng/math/api";
import type { StatelessOscillator } from "../api";

export const cos: StatelessOscillator = (phase, freq, amp = 1, dc = 0) =>
Expand Down
2 changes: 1 addition & 1 deletion packages/dsp/src/osc/dsf.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TAU } from "@thi.ng/math";
import { TAU } from "@thi.ng/math/api";
import type { StatelessOscillator } from "../api";

/**
Expand Down
28 changes: 16 additions & 12 deletions packages/dsp/src/osc/mix.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mix as _mix } from "@thi.ng/math";
import { mix as _mix } from "@thi.ng/math/mix";
import type { StatelessOscillator } from "../api";

/**
Expand All @@ -11,11 +11,13 @@ import type { StatelessOscillator } from "../api";
* @param osc1
* @param osc2
*/
export const mixOsc = (
osc1: StatelessOscillator,
osc2: StatelessOscillator
): StatelessOscillator => (phase, freq, amp = 1, dc = 0, t = 0.5) =>
_mix(osc1(phase, freq, amp, dc), osc2(phase, freq, amp, dc), t);
export const mixOsc =
(
osc1: StatelessOscillator,
osc2: StatelessOscillator
): StatelessOscillator =>
(phase, freq, amp = 1, dc = 0, t = 0.5) =>
_mix(osc1(phase, freq, amp, dc), osc2(phase, freq, amp, dc), t);

/**
* Similar to {@link mixOsc}, but with `mix` arg ([0..1] range)
Expand All @@ -25,9 +27,11 @@ export const mixOsc = (
* @param osc2
* @param mix
*/
export const mixOscHOF = (
osc1: StatelessOscillator,
osc2: StatelessOscillator,
mix = 0.5
): StatelessOscillator => (phase, freq, amp = 1, dc = 0) =>
_mix(osc1(phase, freq, amp, dc), osc2(phase, freq, amp, dc), mix);
export const mixOscHOF =
(
osc1: StatelessOscillator,
osc2: StatelessOscillator,
mix = 0.5
): StatelessOscillator =>
(phase, freq, amp = 1, dc = 0) =>
_mix(osc1(phase, freq, amp, dc), osc2(phase, freq, amp, dc), mix);
2 changes: 1 addition & 1 deletion packages/dsp/src/osc/parabolic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fract } from "@thi.ng/math";
import { fract } from "@thi.ng/math/prec";
import type { StatelessOscillator } from "../api";

/**
Expand Down
12 changes: 5 additions & 7 deletions packages/dsp/src/osc/rect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fract } from "@thi.ng/math";
import { fract } from "@thi.ng/math/prec";
import type { StatelessOscillator } from "../api";

export const rect: StatelessOscillator = (
Expand All @@ -15,9 +15,7 @@ export const rect: StatelessOscillator = (
*
* @param duty
*/
export const rectHOF = (duty = 0.5): StatelessOscillator => (
phase,
freq,
amp,
dc
) => rect(phase, freq, amp, dc, duty);
export const rectHOF =
(duty = 0.5): StatelessOscillator =>
(phase, freq, amp, dc) =>
rect(phase, freq, amp, dc, duty);
2 changes: 1 addition & 1 deletion packages/dsp/src/osc/saw.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fract } from "@thi.ng/math";
import { fract } from "@thi.ng/math/prec";
import type { StatelessOscillator } from "../api";

export const saw: StatelessOscillator = (phase, freq, amp = 1, dc = 0) =>
Expand Down
2 changes: 1 addition & 1 deletion packages/dsp/src/osc/sin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TAU } from "@thi.ng/math";
import { TAU } from "@thi.ng/math/api";
import type { StatelessOscillator } from "../api";

export const sin: StatelessOscillator = (phase, freq, amp = 1, dc = 0) =>
Expand Down
2 changes: 1 addition & 1 deletion packages/dsp/src/osc/tri.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fract } from "@thi.ng/math";
import { fract } from "@thi.ng/math/prec";
import type { StatelessOscillator } from "../api";

export const tri: StatelessOscillator = (phase, freq, amp = 1, dc = 0) =>
Expand Down
3 changes: 2 additions & 1 deletion packages/dsp/src/osc/wavetable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Fn3, NumericArray } from "@thi.ng/api";
import { fract, mix as _mix } from "@thi.ng/math";
import { mix as _mix } from "@thi.ng/math/mix";
import { fract } from "@thi.ng/math/prec";
import type { StatelessOscillator } from "../api";

export const wavetable = (
Expand Down
3 changes: 2 additions & 1 deletion packages/dsp/src/proc/allpass.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { IReset } from "@thi.ng/api";
import { clamp05, PI, QUARTER_PI } from "@thi.ng/math";
import { PI, QUARTER_PI } from "@thi.ng/math/api";
import { clamp05 } from "@thi.ng/math/interval";
import { AProc } from "./aproc";

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/dsp/src/proc/aproc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IXform } from "@thi.ng/transducers";
import { map } from "@thi.ng/transducers";
import { map } from "@thi.ng/transducers/xform/map";
import type { IProc, IProc2 } from "../api";

/**
Expand Down
5 changes: 3 additions & 2 deletions packages/dsp/src/proc/biquad.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { IReset } from "@thi.ng/api";
import { unsupported } from "@thi.ng/errors";
import { clamp05, PI, SQRT2, SQRT2_2 } from "@thi.ng/math";
import { unsupported } from "@thi.ng/errors/unsupported";
import { PI, SQRT2, SQRT2_2 } from "@thi.ng/math/api";
import { clamp05 } from "@thi.ng/math/interval";
import type { BiquadType, FilterConfig, IFilter } from "../api";
import { dbMag } from "../util/convert";
import { AProc } from "./aproc";
Expand Down
4 changes: 2 additions & 2 deletions packages/dsp/src/proc/delay.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Fn0, IClear, ILength, IReset } from "@thi.ng/api";
import { isFunction } from "@thi.ng/checks";
import { wrap } from "@thi.ng/math";
import { isFunction } from "@thi.ng/checks/is-function";
import { wrap } from "@thi.ng/math/interval";
import { AProc } from "./aproc";

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/dsp/src/proc/feedback-delay.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { clamp01 } from "@thi.ng/math";
import { clamp01 } from "@thi.ng/math/interval";
import { Delay } from "./delay";

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/dsp/src/proc/foldback.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { foldback as _foldback } from "@thi.ng/math";
import { foldback as _foldback } from "@thi.ng/math/interval";
import { AProc } from "./aproc";

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/dsp/src/proc/mix.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { clamp01 } from "@thi.ng/math";
import { clamp01 } from "@thi.ng/math/interval";
import { AProc2 } from "./aproc";

export class Mix extends AProc2<number, number, number> {
Expand Down
6 changes: 4 additions & 2 deletions packages/dsp/src/proc/onepole.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { IClear, IReset } from "@thi.ng/api";
import { clamp05, TAU } from "@thi.ng/math";
import { TAU } from "@thi.ng/math/api";
import { clamp05 } from "@thi.ng/math/interval";
import type { FilterConfig, IFilter, OnepoleType } from "../api";
import { AProc } from "./aproc";

Expand All @@ -12,7 +13,8 @@ export const onepoleHP = (fc: number) => new OnePole("hp", fc);
*/
export class OnePole
extends AProc<number, number>
implements IClear, IFilter, IReset {
implements IClear, IFilter, IReset
{
protected _a0!: number;
protected _b1!: number;

Expand Down
3 changes: 2 additions & 1 deletion packages/dsp/src/proc/svf.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { IReset } from "@thi.ng/api";
import { clamp05, PI } from "@thi.ng/math";
import { PI } from "@thi.ng/math/api";
import { clamp05 } from "@thi.ng/math/interval";
import type { SVFType } from "../api";
import { AProc } from "./aproc";

Expand Down
2 changes: 1 addition & 1 deletion packages/dsp/src/proc/waveshaper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Fn2 } from "@thi.ng/api";
import { PI } from "@thi.ng/math";
import { PI } from "@thi.ng/math/api";
import { AProc } from "./aproc";

export type WaveShaperFn = Fn2<number, number, number>;
Expand Down
2 changes: 1 addition & 1 deletion packages/dsp/src/util/anti-alias.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { FnN2 } from "@thi.ng/api";
import { HALF_PI } from "@thi.ng/math";
import { HALF_PI } from "@thi.ng/math/api";

/**
* Reference:
Expand Down
2 changes: 1 addition & 1 deletion packages/dsp/src/util/complex.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { NumericArray } from "@thi.ng/api";
import { isNumber } from "@thi.ng/checks";
import { isNumber } from "@thi.ng/checks/is-number";
import type { ComplexArray } from "../api";

export const isComplex = (
Expand Down
2 changes: 1 addition & 1 deletion packages/dsp/src/util/convert.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { FnN, FnN2 } from "@thi.ng/api";
import { TAU } from "@thi.ng/math";
import { TAU } from "@thi.ng/math/api";

/**
* Returns frequency `f` normalized to sample rate `fs`:
Expand Down
3 changes: 2 additions & 1 deletion packages/dsp/src/util/filter-response.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { FnU3, NumericArray } from "@thi.ng/api";
import { cossin, TAU } from "@thi.ng/math";
import { cossin } from "@thi.ng/math/angle";
import { TAU } from "@thi.ng/math/api";
import type { FilterConfig, FilterResponse } from "../api";
import { line } from "../gen/line";
import { magDb } from "./convert";
Expand Down

0 comments on commit 02f1cf7

Please sign in to comment.