gpt4 book ai didi

audio - OpenAL 3D 音效

转载 作者:行者123 更新时间:2023-12-02 22:34:34 29 4
gpt4 key购买 nike

在我的 3D 游戏中,我目前有通过工厂类“声音”工作的声音。我正在通过我的相机类初始化 OpenAL,加载时它将存储其位置、方向和速度的全局 float 缓冲区

private static FloatBuffer listenerPosition = BufferUtils.createFloatBuffer( 3 ).put( new float[] { X(), Y(), Z() } );
private static FloatBuffer listenerOrientation = BufferUtils.createFloatBuffer( 6 ).put (new float[] { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f } );
private static FloatBuffer listenerVelocity = BufferUtils.createFloatBuffer( 3 ).put (new float[] { Velocity.x, Velocity.y, Velocity.z } );

然后在相机移动或旋转时的每个刻度上,它会使用代码更新这些
listenerVelocity.put(0, Velocity.x);
listenerVelocity.put(1, Velocity.y);
listenerVelocity.put(2, Velocity.z);

alListener( AL_POSITION, listenerPosition );
alListener( AL_ORIENTATION, listenerOrientation );
alListener( AL_VELOCITY, listenerVelocity );

这是我认为不让 OpenAL 知道我想要的声音的类,尽管我正在向它提供它所需要的所有信息,据我所知。
private int ID;

public Sound(String name) {
try {
ID = alGenBuffers();
WaveData data = WaveData.create(new BufferedInputStream(new FileInputStream("res/Sound/"+name+".wav")));
alBufferData(ID, data.format, data.data, data.samplerate);
data.dispose();
} catch (FileNotFoundException e) {
JOptionPane.showMessageDialog(null, "Could not find \"" + name + "\"", "IO Exception", JOptionPane.ERROR_MESSAGE);
Display.destroy();
System.exit(1);
}
}

public void play(float x, float y, float z) {
playSound(ID, new Vector3f(x,y,z));
}

private static void playSound(int buffer, Vector3f pos) {
while(alGetSourcei(Sources.get(currentsource), AL10.AL_SOURCE_STATE) == AL_PLAYING) {
currentsource++;
currentsource %= 10; //there are only 10 sources
}
alSourcei(Sources.get(currentsource), AL_BUFFER, buffer );
alSourcef(Sources.get(currentsource), AL_PITCH, 1.0f );
alSourcef(Sources.get(currentsource), AL_GAIN, 1.0f );
alSourcei(Sources.get(currentsource), AL_LOOPING, AL_FALSE);
alSourcef(Sources.get(currentsource), AL_REFERENCE_DISTANCE, 0);
alSourcef(Sources.get(currentsource), AL_MAX_DISTANCE, 100);

alSourcePlay(Sources.get(currentsource));
}

public static boolean hasLoaded(){return loaded;}

我怀疑是 playSound 方法,有没有更好的方法来找到非播放源?是否有任何我没有给出的属性会导致声音没有任何 3D 属性?

最佳答案

您应该查看音频文件 channel ,因为 openAL 仅对 应用衰减。单声道 .

关于audio - OpenAL 3D 音效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17328421/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com