This commit is contained in:
parent
39b0160064
commit
2347ecd201
71 changed files with 3779 additions and 1586 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { appConfig } from '../config';
|
||||
import type { GardenAudioEngineConfig } from '../config';
|
||||
import { clamp } from '../utils/clamp';
|
||||
import { GardenAudioConfig, GardenAudioVibeProfile } from './garden-audio-config';
|
||||
|
||||
|
|
@ -14,7 +14,10 @@ export class GardenAudioGraph {
|
|||
private delayOutput: GainNode | null = null;
|
||||
private hasUnlocked = false;
|
||||
|
||||
public constructor(private readonly config: GardenAudioConfig) {}
|
||||
public constructor(
|
||||
private readonly config: GardenAudioConfig,
|
||||
private readonly engineConfig: GardenAudioEngineConfig
|
||||
) {}
|
||||
|
||||
public ensureContext(canCreate: boolean): AudioContext | null {
|
||||
if (this.context) {
|
||||
|
|
@ -62,8 +65,8 @@ export class GardenAudioGraph {
|
|||
|
||||
const buffer = this.context.createBuffer(
|
||||
1,
|
||||
appConfig.audioEngine.graph.unlockBufferLength,
|
||||
appConfig.audioEngine.graph.unlockSampleRate
|
||||
this.engineConfig.graph.unlockBufferLength,
|
||||
this.engineConfig.graph.unlockSampleRate
|
||||
);
|
||||
const source = this.context.createBufferSource();
|
||||
source.buffer = buffer;
|
||||
|
|
@ -92,7 +95,7 @@ export class GardenAudioGraph {
|
|||
this.delayNode.delayTime.setTargetAtTime(
|
||||
this.config.delay.timeSeconds * profile.delayTimeMultiplier,
|
||||
this.context.currentTime,
|
||||
appConfig.audioEngine.graph.delayTimeRampSeconds
|
||||
this.engineConfig.graph.delayTimeRampSeconds
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -105,22 +108,22 @@ export class GardenAudioGraph {
|
|||
this.delayNode.delayTime.setTargetAtTime(
|
||||
this.config.delay.timeSeconds * profile.delayTimeMultiplier,
|
||||
now,
|
||||
appConfig.audioEngine.graph.delayTimeRampSeconds
|
||||
this.engineConfig.graph.delayTimeRampSeconds
|
||||
);
|
||||
this.delayFeedback.gain.setTargetAtTime(
|
||||
clamp(
|
||||
this.config.delay.feedback +
|
||||
activity * appConfig.audioEngine.graph.delayActivityFeedbackWeight,
|
||||
appConfig.audioEngine.graph.delayFeedbackMin,
|
||||
appConfig.audioEngine.graph.delayFeedbackMax
|
||||
activity * this.engineConfig.graph.delayActivityFeedbackWeight,
|
||||
this.engineConfig.graph.delayFeedbackMin,
|
||||
this.engineConfig.graph.delayFeedbackMax
|
||||
),
|
||||
now,
|
||||
this.config.updateRampSeconds
|
||||
);
|
||||
this.delayOutput.gain.setTargetAtTime(
|
||||
this.config.delay.wetGain *
|
||||
(appConfig.audioEngine.graph.delayOutputBase +
|
||||
activity * appConfig.audioEngine.graph.delayOutputActivityWeight),
|
||||
(this.engineConfig.graph.delayOutputBase +
|
||||
activity * this.engineConfig.graph.delayOutputActivityWeight),
|
||||
now,
|
||||
this.config.updateRampSeconds
|
||||
);
|
||||
|
|
@ -134,9 +137,9 @@ export class GardenAudioGraph {
|
|||
|
||||
if (this.masterGain && context.state !== 'closed') {
|
||||
this.masterGain.gain.setTargetAtTime(
|
||||
appConfig.audioEngine.graph.closeGain,
|
||||
this.engineConfig.graph.closeGain,
|
||||
context.currentTime,
|
||||
appConfig.audioEngine.graph.closeRampSeconds
|
||||
this.engineConfig.graph.closeRampSeconds
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -171,7 +174,7 @@ export class GardenAudioGraph {
|
|||
|
||||
private createBuses(context: AudioContext, masterGain: GainNode): void {
|
||||
this.eventBus = context.createGain();
|
||||
this.eventBus.gain.value = appConfig.audioEngine.graph.eventBusGain;
|
||||
this.eventBus.gain.value = this.engineConfig.graph.eventBusGain;
|
||||
this.eventBus.connect(masterGain);
|
||||
}
|
||||
|
||||
|
|
@ -181,9 +184,9 @@ export class GardenAudioGraph {
|
|||
|
||||
for (let index = 0; index < data.length; index++) {
|
||||
data[index] =
|
||||
appConfig.audioEngine.graph.noiseMin +
|
||||
this.engineConfig.graph.noiseMin +
|
||||
Math.random() *
|
||||
(appConfig.audioEngine.graph.noiseMax - appConfig.audioEngine.graph.noiseMin);
|
||||
(this.engineConfig.graph.noiseMax - this.engineConfig.graph.noiseMin);
|
||||
}
|
||||
|
||||
return buffer;
|
||||
|
|
|
|||
Loading…
Reference in a new issue