Änderungen: - Implementierung eines neuen AudioWorklet-Prozessors für realistische Motorgeräusche. - Erstellung der MotorSound-Klasse zur Verwaltung von motorgeräuschabhängigen Audioeffekten. - Integration des MotorSounds in die TaxiGame.vue, einschließlich der Initialisierung und Steuerung basierend auf der Geschwindigkeit des Taxis. - Anpassung der Audio-Parameter wie Lautstärke und Geschwindigkeit in Abhängigkeit von der Fahrzeuggeschwindigkeit. Diese Anpassungen verbessern die akustische Benutzererfahrung im Taxi-Minispiel erheblich und tragen zur Immersion bei.
44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
// AudioWorklet Processor für MotorSound
|
|
class MotorSoundProcessor extends AudioWorkletProcessor {
|
|
constructor() {
|
|
super();
|
|
this.data = null;
|
|
this.speed = 0.6;
|
|
this.currentFrame = 0;
|
|
|
|
this.port.onmessage = (e) => {
|
|
const { type, data, speed } = e.data;
|
|
switch (type) {
|
|
case 'init':
|
|
this.data = data;
|
|
this.speed = speed;
|
|
break;
|
|
case 'updateData':
|
|
this.data = data;
|
|
break;
|
|
case 'updateSpeed':
|
|
this.speed = speed;
|
|
break;
|
|
}
|
|
};
|
|
}
|
|
|
|
process(inputs, outputs, parameters) {
|
|
const output = outputs[0];
|
|
if (!this.data || this.data.length === 0) return true;
|
|
|
|
for (let channel = 0; channel < output.length; channel++) {
|
|
const outputChannel = output[channel];
|
|
for (let i = 0; i < outputChannel.length; i++) {
|
|
this.currentFrame += this.speed;
|
|
const index = Math.floor(this.currentFrame) % this.data.length;
|
|
outputChannel[i] = this.data[index];
|
|
}
|
|
}
|
|
this.currentFrame %= this.data.length;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
registerProcessor('motor-sound-processor', MotorSoundProcessor);
|