feat: All intrinsic audio effects

This commit is contained in:
unanmed 2025-01-15 21:53:54 +08:00
parent 5efa60a0de
commit 307bf8a10d
2 changed files with 43 additions and 10 deletions

View File

@ -83,7 +83,11 @@ export class StereoEffect extends AudioEffect {
* @param y y坐标 * @param y y坐标
* @param z z坐标 * @param z z坐标
*/ */
setOrientation(x: number, y: number, z: number) {} setOrientation(x: number, y: number, z: number) {
this.output.orientationX.value = x;
this.output.orientationY.value = y;
this.output.orientationZ.value = z;
}
/** /**
* x正方形水平向右y正方形垂直于地面向上z正方向垂直屏幕远离用户 * x正方形水平向右y正方形垂直于地面向上z正方向垂直屏幕远离用户
@ -91,7 +95,11 @@ export class StereoEffect extends AudioEffect {
* @param y y坐标 * @param y y坐标
* @param z z坐标 * @param z z坐标
*/ */
setPosition(x: number, y: number, z: number) {} setPosition(x: number, y: number, z: number) {
this.output.positionX.value = x;
this.output.positionY.value = y;
this.output.positionZ.value = z;
}
end(): void {} end(): void {}
@ -113,12 +121,16 @@ export class VolumeEffect extends AudioEffect {
* *
* @param volume * @param volume
*/ */
setVolume(volume: number) {} setVolume(volume: number) {
this.output.gain.value = volume;
}
/** /**
* *
*/ */
getVolume(): number {} getVolume(): number {
return this.output.gain.value;
}
end(): void {} end(): void {}
@ -148,16 +160,22 @@ export class ChannelVolumeEffect extends AudioEffect {
/** /**
* *
* @param channel * @param channel 0-5
* @param volume * @param volume
*/ */
setVolume(channel: number, volume: number) {} setVolume(channel: number, volume: number) {
if (!this.gain[channel]) return;
this.gain[channel].gain.value = volume;
}
/** /**
* * 0-5
* @param channel * @param channel
*/ */
getVolume(channel: number): number {} getVolume(channel: number): number {
if (!this.gain[channel]) return 0;
return this.gain[channel].gain.value;
}
end(): void {} end(): void {}
@ -179,12 +197,16 @@ export class DelayEffect extends AudioEffect {
* *
* @param delay * @param delay
*/ */
setDelay(delay: number) {} setDelay(delay: number) {
this.output.delayTime.value = delay;
}
/** /**
* *
*/ */
getDelay() {} getDelay() {
return this.output.delayTime.value;
}
end(): void {} end(): void {}

View File

@ -8,6 +8,7 @@ import {
import { import {
AudioEffect, AudioEffect,
ChannelVolumeEffect, ChannelVolumeEffect,
DelayEffect,
EchoEffect, EchoEffect,
IAudioOutput, IAudioOutput,
StereoEffect, StereoEffect,
@ -138,6 +139,16 @@ export class AudioPlayer extends EventEmitter<AudioPlayerEvent> {
return new ChannelVolumeEffect(this.ac); return new ChannelVolumeEffect(this.ac);
} }
/**
*
* |-----------|
* Input ----> | DelayNode | ----> Output
* |-----------|
*/
createDelay() {
return new DelayEffect(this.ac);
}
/** /**
* *
* ```txt * ```txt