Search in sources :

Example 1 with Status

use of com.jme3.audio.AudioSource.Status in project jmonkeyengine by jMonkeyEngine.

the class ALAudioRenderer method updateInDecoderThread.

public void updateInDecoderThread(float tpf) {
    if (audioDisabled) {
        return;
    }
    for (int i = 0; i < channels.length; i++) {
        AudioSource src = chanSrcs[i];
        if (src == null || !(src.getAudioData() instanceof AudioStream)) {
            continue;
        }
        int sourceId = channels[i];
        AudioStream stream = (AudioStream) src.getAudioData();
        Status oalStatus = convertStatus(al.alGetSourcei(sourceId, AL_SOURCE_STATE));
        Status jmeStatus = src.getStatus();
        // Keep filling data (even if we are stopped / paused)
        boolean buffersWereFilled = fillStreamingSource(sourceId, stream, src.isLooping());
        if (buffersWereFilled) {
            if (oalStatus == Status.Stopped && jmeStatus == Status.Playing) {
                // The source got stopped due to buffer starvation.
                // Start it again.
                logger.log(Level.WARNING, "Buffer starvation " + "occurred while playing stream");
                al.alSourcePlay(sourceId);
            } else {
                // Buffers were filled, stream continues to play.
                if (oalStatus == Status.Playing && jmeStatus == Status.Playing) {
                // Nothing to do.
                } else {
                    throw new AssertionError();
                }
            }
        }
    }
    // Delete any unused objects.
    objManager.deleteUnused(this);
}
Also used : Status(com.jme3.audio.AudioSource.Status)

Example 2 with Status

use of com.jme3.audio.AudioSource.Status in project jmonkeyengine by jMonkeyEngine.

the class ALAudioRenderer method updateInRenderThread.

public void updateInRenderThread(float tpf) {
    if (audioDisabled) {
        return;
    }
    for (int i = 0; i < channels.length; i++) {
        AudioSource src = chanSrcs[i];
        if (src == null) {
            continue;
        }
        int sourceId = channels[i];
        boolean boundSource = i == src.getChannel();
        boolean reclaimChannel = false;
        Status oalStatus = convertStatus(al.alGetSourcei(sourceId, AL_SOURCE_STATE));
        if (!boundSource) {
            // Handle it here.
            if (oalStatus == Status.Stopped) {
                // Instanced audio stopped playing. Reclaim channel.
                clearChannel(i);
                freeChannel(i);
            } else if (oalStatus == Status.Paused) {
                throw new AssertionError("Instanced audio cannot be paused");
            }
            continue;
        }
        Status jmeStatus = src.getStatus();
        // Check if we need to sync JME status with OAL status.
        if (oalStatus != jmeStatus) {
            if (oalStatus == Status.Stopped && jmeStatus == Status.Playing) {
                // Maybe we need to reclaim the channel.
                if (src.getAudioData() instanceof AudioStream) {
                    AudioStream stream = (AudioStream) src.getAudioData();
                    if (stream.isEOF() && !src.isLooping()) {
                        // Stream finished playing
                        reclaimChannel = true;
                    } else {
                    // Stream still has data. 
                    // Buffer starvation occured.
                    // Audio decoder thread will fill the data 
                    // and start the channel again.
                    }
                } else {
                    // Buffer finished playing.
                    if (src.isLooping()) {
                        // When a device is disconnected, all sources
                        // will enter the "stopped" state.
                        logger.warning("A looping sound has stopped playing");
                    }
                    reclaimChannel = true;
                }
                if (reclaimChannel) {
                    src.setStatus(Status.Stopped);
                    src.setChannel(-1);
                    clearChannel(i);
                    freeChannel(i);
                }
            } else {
                // This is only relevant for bound sources.
                throw new AssertionError("Unexpected sound status. " + "OAL: " + oalStatus + ", JME: " + jmeStatus);
            }
        } else {
            // Stopped channel was not cleared correctly.
            if (oalStatus == Status.Stopped) {
                throw new AssertionError("Channel " + i + " was not reclaimed");
            }
        }
    }
}
Also used : Status(com.jme3.audio.AudioSource.Status)

Example 3 with Status

use of com.jme3.audio.AudioSource.Status in project jmonkeyengine by jMonkeyEngine.

the class GLRenderer method updateShaderData.

public void updateShaderData(Shader shader) {
    int id = shader.getId();
    boolean needRegister = false;
    if (id == -1) {
        // create program
        id = gl.glCreateProgram();
        if (id == 0) {
            throw new RendererException("Invalid ID (" + id + ") received when trying to create shader program.");
        }
        shader.setId(id);
        needRegister = true;
    }
    // If using GLSL 1.5, we bind the outputs for the user
    // For versions 3.3 and up, user should use layout qualifiers instead.
    boolean bindFragDataRequired = false;
    for (ShaderSource source : shader.getSources()) {
        if (source.isUpdateNeeded()) {
            updateShaderSourceData(source);
        }
        if (source.getType() == ShaderType.Fragment && source.getLanguage().equals("GLSL150")) {
            bindFragDataRequired = true;
        }
        gl.glAttachShader(id, source.getId());
    }
    if (bindFragDataRequired) {
        // Check if GLSL version is 1.5 for shader
        gl3.glBindFragDataLocation(id, 0, "outFragColor");
        // For MRT
        for (int i = 0; i < limits.get(Limits.FrameBufferMrtAttachments); i++) {
            gl3.glBindFragDataLocation(id, i, "outFragData[" + i + "]");
        }
    }
    // Link shaders to program
    gl.glLinkProgram(id);
    // Check link status
    gl.glGetProgram(id, GL.GL_LINK_STATUS, intBuf1);
    boolean linkOK = intBuf1.get(0) == GL.GL_TRUE;
    String infoLog = null;
    if (VALIDATE_SHADER || !linkOK) {
        gl.glGetProgram(id, GL.GL_INFO_LOG_LENGTH, intBuf1);
        int length = intBuf1.get(0);
        if (length > 3) {
            // get infos
            infoLog = gl.glGetProgramInfoLog(id, length);
        }
    }
    if (linkOK) {
        if (infoLog != null) {
            logger.log(Level.WARNING, "Shader linked successfully. Linker warnings: \n{0}", infoLog);
        } else {
            logger.fine("Shader linked successfully.");
        }
        shader.clearUpdateNeeded();
        if (needRegister) {
            // Register shader for clean up if it was created in this method.
            objManager.registerObject(shader);
            statistics.onNewShader();
        } else {
            // OpenGL spec: uniform locations may change after re-link
            resetUniformLocations(shader);
        }
    } else {
        if (infoLog != null) {
            throw new RendererException("Shader failed to link, shader:" + shader + "\n" + infoLog);
        } else {
            throw new RendererException("Shader failed to link, shader:" + shader + "\ninfo: <not provided>");
        }
    }
}
Also used : ShaderSource(com.jme3.shader.Shader.ShaderSource)

Example 4 with Status

use of com.jme3.audio.AudioSource.Status in project jmonkeyengine by jMonkeyEngine.

the class OSVR method initialize.

@Override
public boolean initialize() {
    logger.config("Initialize OSVR system.");
    hmdPose.setAutoSynch(false);
    context = OsvrClientKitLibrary.osvrClientInit(defaultJString, 0);
    VRinput = new OSVRInput(environment);
    initSuccess = context != null && VRinput.init();
    if (initSuccess) {
        PointerByReference grabDisplay = new PointerByReference();
        byte retval = OsvrDisplayLibrary.osvrClientGetDisplay(context, grabDisplay);
        if (retval != 0) {
            System.out.println("OSVR Get Display Error: " + retval);
            initSuccess = false;
            return false;
        }
        displayConfig = new OSVR_DisplayConfig(grabDisplay.getValue());
        System.out.println("Waiting for the display to fully start up, including receiving initial pose update...");
        int i = 400;
        while (OsvrDisplayLibrary.osvrClientCheckDisplayStartup(displayConfig) != 0) {
            if (i-- < 0) {
                System.out.println("Couldn't get display startup update in time, continuing anyway...");
                break;
            }
            OsvrClientKitLibrary.osvrClientUpdate(context);
            try {
                Thread.sleep(5);
            } catch (Exception e) {
            }
        }
        System.out.println("OK, display startup status is good!");
    }
    return initSuccess;
}
Also used : PointerByReference(com.sun.jna.ptr.PointerByReference) OSVR_DisplayConfig(com.jme3.system.osvr.osvrdisplay.OsvrDisplayLibrary.OSVR_DisplayConfig)

Aggregations

Status (com.jme3.audio.AudioSource.Status)2 ShaderSource (com.jme3.shader.Shader.ShaderSource)1 OSVR_DisplayConfig (com.jme3.system.osvr.osvrdisplay.OsvrDisplayLibrary.OSVR_DisplayConfig)1 PointerByReference (com.sun.jna.ptr.PointerByReference)1