adding unipolar LFOs and new method chaining

This commit is contained in:
2023-08-17 01:02:37 +02:00
parent c851e3e33f
commit 8541d0c3ef
2 changed files with 223 additions and 3 deletions

View File

@ -5,6 +5,7 @@ import { DrunkWalk } from "./Utils/Drunk";
import { LRUCache } from 'lru-cache'; import { LRUCache } from 'lru-cache';
import { scale } from "./Scales"; import { scale } from "./Scales";
import { Editor } from "./main"; import { Editor } from "./main";
import { Sound } from './Sound';
import { import {
superdough, superdough,
samples, samples,
@ -1035,7 +1036,7 @@ export class UserAPI {
gold() { gold() {
/** /**
* Essayer de générer des séquences tirées du truc de Puckette * Essayer de générer des séquences tirées du truc de Puckette
* Faire ça avec des lazy lists, ça ne devrait pas être trop difficle. * Faire ça avec des lazy lists, ça ne devrait pas être trop difficile.
* *
*/ */
} }
@ -1079,6 +1080,18 @@ export class UserAPI {
); );
} }
usine(freq: number = 1, offset: number = 0): number {
/**
* Returns a sine wave between 0 and 1.
*
* @param freq - The frequency of the sine wave
* @param offset - The offset of the sine wave
* @returns A sine wave between 0 and 1
* @see sine
*/
return (this.sine(freq, offset) + 1) / 2;
}
saw(freq: number = 1, offset: number = 0): number { saw(freq: number = 1, offset: number = 0): number {
/** /**
* Returns a saw wave between -1 and 1. * Returns a saw wave between -1 and 1.
@ -1094,6 +1107,18 @@ export class UserAPI {
return ((this.app.clock.ctx.currentTime * freq) % 1) * 2 - 1 + offset; return ((this.app.clock.ctx.currentTime * freq) % 1) * 2 - 1 + offset;
} }
usaw(freq: number = 1, offset: number = 0): number {
/**
* Returns a saw wave between 0 and 1.
*
* @param freq - The frequency of the saw wave
* @param offset - The offset of the saw wave
* @returns A saw wave between 0 and 1
* @see saw
*/
return (this.saw(freq, offset) + 1) / 2;
}
triangle(freq: number = 1, offset: number = 0): number { triangle(freq: number = 1, offset: number = 0): number {
/** /**
* Returns a triangle wave between -1 and 1. * Returns a triangle wave between -1 and 1.
@ -1107,6 +1132,18 @@ export class UserAPI {
return Math.abs(this.saw(freq, offset)) * 2 - 1; return Math.abs(this.saw(freq, offset)) * 2 - 1;
} }
utriangle(freq: number = 1, offset: number = 0): number {
/**
* Returns a triangle wave between 0 and 1.
*
* @param freq - The frequency of the triangle wave
* @param offset - The offset of the triangle wave
* @returns A triangle wave between 0 and 1
* @see triangle
*/
return (this.triangle(freq, offset) + 1) / 2;
}
square(freq: number = 1, offset: number = 0): number { square(freq: number = 1, offset: number = 0): number {
/** /**
* Returns a square wave between -1 and 1. * Returns a square wave between -1 and 1.
@ -1120,6 +1157,18 @@ export class UserAPI {
return this.saw(freq, offset) > 0 ? 1 : -1; return this.saw(freq, offset) > 0 ? 1 : -1;
} }
usquare(freq: number = 1, offset: number = 0): number {
/**
* Returns a square wave between 0 and 1.
*
* @param freq - The frequency of the square wave
* @param offset - The offset of the square wave
* @returns A square wave between 0 and 1
* @see square
*/
return (this.square(freq, offset) + 1) / 2;
}
noise(): number { noise(): number {
/** /**
* Returns a random value between -1 and 1. * Returns a random value between -1 and 1.
@ -1144,10 +1193,14 @@ export class UserAPI {
// Trivial functions // Trivial functions
// ============================================================= // =============================================================
sound = async (values: object, delay: number = 0.0) => { d = async (values: object, delay: number = 0.0) => {
superdough(values, delay); superdough(values, delay);
}; };
d = this.sound;
sound = (sound: string) => {
return new Sound(sound);
}
samples = samples; samples = samples;

167
src/Sound.ts Normal file
View File

@ -0,0 +1,167 @@
import {
superdough,
// @ts-ignore
} from "superdough";
export class Sound {
values: { [key: string]: any }
constructor(sound: string) {
this.values = { 's': sound }
}
unit = (value: number): this => {
this.values['unit'] = value
return this;
}
frequency = (value: number): this => {
this.values['frequency'] = value
return this;
}
nudge = (value: number): this => {
this.values['nudge'] = value
return this;
}
cut = (value: number): this => {
this.values['cut'] = value
return this;
}
loop = (value: number): this => {
this.values['loop'] = value
return this;
}
clip = (value: number): this => {
this.values['clip'] = value
return this;
}
n = (value: number): this => {
this.values['n'] = value
return this;
}
note = (value: number): this => {
this.values['note'] = value
return this;
}
speed = (value: number): this => {
this.values['speed'] = value
return this;
}
begin = (value: number): this => {
this.values['begin'] = value
return this;
}
end = (value: number): this => {
this.values['end'] = value
return this;
}
gain = (value: number): this => {
this.values['gain'] = value
return this;
}
cutoff = (value: number): this => {
this.values['cutoff'] = value
return this;
}
resonance = (value: number): this => {
this.values['resonance'] = value
return this;
}
hcutoff = (value: number): this => {
this.values['hcutoff'] = value
return this;
}
hresonance = (value: number): this => {
this.values['hresonance'] = value
return this;
}
bandf = (value: number): this => {
this.values['bandf'] = value
return this;
}
bandq = (value: number): this => {
this.values['bandq'] = value
return this;
}
coarse = (value: number): this => {
this.values['coarse'] = value
return this;
}
crush = (value: number): this => {
this.values['crush'] = value
return this;
}
shape = (value: number): this => {
this.values['shape'] = value
return this;
}
pan = (value: number): this => {
this.values['pan'] = value
return this;
}
vowel = (value: number): this => {
this.values['vowel'] = value
return this;
}
delay = (value: number): this => {
this.values['delay'] = value
return this;
}
delayfeedback = (value: number): this => {
this.values['delayfeedback'] = value
return this;
}
delaytime = (value: number): this => {
this.values['delaytime'] = value
return this;
}
orbit = (value: number): this => {
this.values['orbit'] = value
return this;
}
room = (value: number): this => {
this.values['room'] = value
return this;
}
size = (value: number): this => {
this.values['size'] = value
return this;
}
velocity = (value: number): this => {
this.values['velocity'] = value
return this;
}
out = (): object => {
return superdough(this.values, 0.0);
}
}