Skip to content

Commit

Permalink
Expose delay from IguaAudio
Browse files Browse the repository at this point in the history
  • Loading branch information
hubol committed Jan 24, 2024
1 parent 59301b0 commit 8ed5ead
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src/igua/igua-audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class IguaAudioImpl {
private readonly _sfxGainNode: GainNode;
private readonly _jukeboxGainNode: GainNode;

private readonly _sfxDelayFeedbackNode: GainNode;

readonly jukebox: AsshatJukebox;

constructor(private readonly _context: AudioContext) {
Expand All @@ -18,12 +20,21 @@ class IguaAudioImpl {
this._globalGainNode = new GainNode(_context);
this._globalGainNode.connect(this._context.destination);

this._sfxDelayFeedbackNode = new GainNode(_context, { gain: 0 });
const delay = new DelayNode(_context, { delayTime: 0.3 });
delay.connect(this._sfxDelayFeedbackNode);
this._sfxDelayFeedbackNode.connect(delay);
delay.connect(this._context.destination);

this._sfxGainNode = new GainNode(_context);
this._sfxGainNode.connect(this._globalGainNode);
this._sfxGainNode.connect(this._sfxDelayFeedbackNode);

this._jukeboxGainNode = new GainNode(_context);
this._jukeboxGainNode.connect(this._globalGainNode);

this._jukeboxGainNode.gain.value = 0.2;

this.jukebox = new AsshatJukebox(this._jukeboxGainNode);
}

Expand All @@ -34,6 +45,10 @@ class IguaAudioImpl {
return new Sound(audio, this._sfxGainNode);
}

set sfxDelayFeedback(value: Unit) {
this._sfxDelayFeedbackNode.gain.value = value;
}

set globalGain(value: Unit) {
this._globalGainNode.gain.value = value;
}
Expand Down
7 changes: 4 additions & 3 deletions src/igua/scenes/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { createDebugPanel } from "../../lib/game-engine/debug/debug-panel";
import { approachLinear } from "../../lib/math/number";
import { SceneLocal } from "../core/scene-local";
import { show } from "../cutscene/show";
import { Jukebox } from "../igua-audio";
import { IguaAudio, Jukebox } from "../igua-audio";
import { Mzk } from "../../assets/music";

const TailTextures = Tx.Iguana.Tail.split({ width: 28, trimFrame: true });
Expand Down Expand Up @@ -92,10 +92,11 @@ export function SceneTest() {
}
if (Key.justWentDown('ArrowUp')) {
WarningToast.show('A sound', 'A sound was just played!');
Sfx.BallBounce.with.rate(Rng.float(0.5, 2)).play();
Sfx.ArrowKnock.with.rate(Rng.float(0.5, 2)).play();
}
if (Key.justWentDown('Space')) {
Sfx.PorkRollEggAndCheese.with.rate(Rng.float(0.5, 2)).playInstance().linearRamp('rate', Rng.float(0.5, 2), Rng.float(1, 3));
IguaAudio.sfxDelayFeedback = Rng.float(0.1, 0.9);
Sfx.BallonPop.with.rate(Rng.float(0.5, 2)).playInstance().linearRamp('rate', Rng.float(0.5, 2), Rng.float(1, 3));
throw new EscapeTickerAndExecute(() =>
sceneStack.push(SceneTest, { useGameplay: false }));
}
Expand Down

0 comments on commit 8ed5ead

Please sign in to comment.