Simple Voice Chat

Simple Voice Chat

36M Downloads

Doppler Effect

braxtonhall opened this issue ยท 3 comments

commented

Considering the audio output is built on top of OpenAL, which automatically calculates the Doppler Effect, it would be simple to add the Doppler effect just by adding a player's current velocity in addition to their position.

ALSpeaker::setPositionSync might look something like this

    protected void setPositionSync(@Nullable Vec3 soundPos, @Nullable Vec3 soundVel) {
        if (soundPos != null && soundVel != null) {
            Player player = mc.player;

            Vec3 position = player.getEyePosition();
            Vec3 look = player.getLookAngle();
            Vec3 up = player.getUpVector(1F);
            Vec3 vel = player.getDeltaMovement();
            AL11.alListener3f(AL11.AL_POSITION, (float) position.x, (float) position.y, (float) position.z);
            SoundManager.checkAlError();
            AL11.alListenerfv(AL11.AL_ORIENTATION, new float[]{(float) look.x, (float) look.y, (float) look.z, (float) up.x, (float) up.y, (float) up.z});
            SoundManager.checkAlError();
            AL11.alListener3f(AL11.AL_VELOCITY, (float) vel.x, (float) vel.y, (float) vel.z);
            SoundManager.checkAlError();
            AL11.alSource3f(source, AL11.AL_POSITION, (float) soundPos.x, (float) soundPos.y, (float) soundPos.z);
            SoundManager.checkAlError();
            AL11.alSource3f(source, AL11.AL_VELOCITY, (float) soundVel.x, (float) soundVel.y, (float) soundVel.z);
            SoundManager.checkAlError();
        } else {
            // ...
        }
    }

To make the doppler effect slightly more noticeable, say on horseback on in a minecart, ALSpeaker::openSync may inclue

AL11.alDopplerFactor(2F);
SoundManager.checkAlError();

I have been using this on my own fork after about 15 minutes of editing and testing, but to be honest it is not pretty at the moment. I'd love to see this officially supported!

commented

I deliberately decided against the doppler effect, since it doesn't fit into the game and also not in the voicechat.

commented

Oh! Are you against making this a config? I could put a PR together with a config defaulting to OFF

commented

I would consider putting it into Sound Physics Remastered.