-
-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
449ecfc
commit d69b3bc
Showing
4 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { clamp01 } from "@thi.ng/math/interval"; | ||
import type { IProc } from "./api.js"; | ||
import { Delay } from "./delay.js"; | ||
|
||
/** | ||
* Extension of {@link feedbackDelay} with additional filter/proc | ||
* possibility for the feedback itself (e.g. a low pass filter). | ||
* | ||
* @param n - delay length | ||
* @param filter - IProc applied to feedback | ||
* @param feedback - feedback factor (default: 0.5) | ||
*/ | ||
export const filterFeedbackDelay = ( | ||
n: number, | ||
filter: IProc<number, number>, | ||
feedback?: number | ||
) => new FilterFeedbackDelay(n, filter, feedback); | ||
|
||
export class FilterFeedbackDelay extends Delay<number> { | ||
constructor( | ||
n: number, | ||
public filter: IProc<number, number>, | ||
protected _feedback = 0.5 | ||
) { | ||
super(n, 0); | ||
this.setFeedback(_feedback); | ||
} | ||
|
||
next(x: number) { | ||
return super.next( | ||
x + this.filter.next(this._buf[this._rpos] * this._feedback) | ||
); | ||
} | ||
|
||
feedback() { | ||
return this._feedback; | ||
} | ||
|
||
setFeedback(feedback: number) { | ||
this._feedback = clamp01(feedback); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters