This commit is contained in:
2025-09-30 12:21:27 +02:00
parent 07e54ddeab
commit 2b7e09d9c9
3842 changed files with 283556 additions and 109 deletions

View File

@ -22,6 +22,17 @@ export class BytebeatGenerator {
this.duration = options.duration ?? 10
}
updateOptions(options: Partial<BytebeatOptions>): void {
if (options.sampleRate !== undefined) {
this.sampleRate = options.sampleRate
this.audioBuffer = null
}
if (options.duration !== undefined) {
this.duration = options.duration
this.audioBuffer = null
}
}
setFormula(formula: string): void {
this.formula = formula
try {
@ -106,6 +117,25 @@ export class BytebeatGenerator {
}
}
onLoopEnd(callback: () => void): void {
if (this.sourceNode && !this.sourceNode.loop) {
this.sourceNode.onended = callback
}
}
setLooping(loop: boolean): void {
this.isLooping = loop
}
scheduleNextTrack(callback: () => void): void {
if (this.audioContext && this.sourceNode) {
this.sourceNode.loop = false
this.sourceNode.onended = () => {
callback()
}
}
}
pause(): void {
if (this.sourceNode && this.audioContext) {
this.pauseTime = this.audioContext.currentTime - this.startTime

View File

@ -4,6 +4,7 @@ export class EffectsChain {
private audioContext: AudioContext
private inputNode: GainNode
private outputNode: GainNode
private masterGainNode: GainNode
private delayNode: DelayNode
private delayFeedbackNode: GainNode
@ -20,6 +21,7 @@ export class EffectsChain {
this.audioContext = audioContext
this.inputNode = audioContext.createGain()
this.masterGainNode = audioContext.createGain()
this.outputNode = audioContext.createGain()
this.delayNode = audioContext.createDelay(2.0)
@ -57,7 +59,8 @@ export class EffectsChain {
this.reverbDryNode.connect(this.tbdNode)
this.reverbWetNode.connect(this.tbdNode)
this.tbdNode.connect(this.outputNode)
this.tbdNode.connect(this.masterGainNode)
this.masterGainNode.connect(this.outputNode)
}
private generateImpulseResponse(): void {
@ -86,6 +89,10 @@ export class EffectsChain {
const delayAmount = Math.min(values.delayTime / 1000, 0.5)
this.delayWetNode.gain.value = delayAmount
this.delayDryNode.gain.value = 1 - delayAmount
if (values.masterVolume !== undefined) {
this.masterGainNode.gain.value = values.masterVolume / 100
}
}
getInputNode(): AudioNode {
@ -99,6 +106,7 @@ export class EffectsChain {
dispose(): void {
this.inputNode.disconnect()
this.outputNode.disconnect()
this.masterGainNode.disconnect()
this.delayNode.disconnect()
this.delayFeedbackNode.disconnect()
this.delayWetNode.disconnect()