OpenAL Loading Two声音会冻结Java



所以我目前使用OpenAL加载声音,但是当我加载超过一个单一的声音与我的库它冻结一切。下面是当前与加载声音相关的代码。

public static int loadALBuffer(String path) throws FileNotFoundException {
        int result;
        IntBuffer buffer = BufferUtils.createIntBuffer(1);
        // Load wav data into a buffers.
        AL10.alGenBuffers(buffer);
        if ((result = AL10.alGetError()) != AL10.AL_NO_ERROR) {
            throw new OpenALException(getALErrorString(result));
        }
        WaveData waveFile = WaveData.create(new BufferedInputStream(new FileInputStream(path)));
        if (waveFile != null) {
            AL10.alBufferData(buffer.get(0), waveFile.format, waveFile.data,
                    waveFile.samplerate);
            waveFile.dispose();
        } else {
            throw new RuntimeException("No such file: " + path);
        }
        // Do another error check and return.
        if ((result = AL10.alGetError()) != AL10.AL_NO_ERROR) {
            throw new OpenALException(getALErrorString(result));
        }
        return buffer.get(0);
    }

public static int getLoadedALBuffer(String path) throws FileNotFoundException {
        int count = 0;
        for (Iterator<String> i = loadedFiles.iterator(); i.hasNext(); count++) {
            if (i.equals(path)) {
                return buffers.get(count).intValue();
            }
        }
        int buffer = loadALBuffer(path);
        buffers.add(new Integer(buffer));
        loadedFiles.add(path);
        return buffer;
    }

public static int loadALSample(String path, boolean loop) throws FileNotFoundException {
        IntBuffer source = BufferUtils.createIntBuffer(1);
        int buffer;
        int result;

        buffer = getLoadedALBuffer(path);
        AL10.alGenSources(source);
        if ((result = AL10.alGetError()) != AL10.AL_NO_ERROR)
            throw new OpenALException(getALErrorString(result));
        AL10.alSourcei(source.get(0), AL10.AL_BUFFER, buffer);
        AL10.alSourcef(source.get(0), AL10.AL_PITCH, 1.0f);
        AL10.alSourcef(source.get(0), AL10.AL_GAIN, 1.0f);
        AL10.alSource(source.get(0), AL10.AL_POSITION, sourcePos);
        AL10.alSource(source.get(0), AL10.AL_VELOCITY, sourceVel);
        AL10.alSourcei(source.get(0), AL10.AL_LOOPING, (loop ? AL10.AL_TRUE: AL10.AL_FALSE));
        sources.add(new Integer(source.get(0)));
        return source.get(0);
    }

和主类代码:

static int testSound;
static int testSoun;

//to add a sound call manager.loadALSample("path",is this looping) and add the variable. 
    public static void loadALData(SoundManager manager) throws FileNotFoundException {
        //test = manager.loadALSample("test.wav", false);
        testSound = SoundManager.loadALSample("res/sounds/test1.wav", false);
        testSoun= SoundManager.loadALSample("res/sounds/test2.wav", false);
        SoundManager.killALLoadedData();
    }
如果你需要更多的信息,请告诉我。这很难调试,我有错误检查,第一个声音加载正常,然后当第二个声音加载时,它只是冻结。

发生这种情况是因为我在加载每个示例后没有清除已加载的文件,这导致Java在尝试加载数据时锁定。

最新更新