Example usage for javax.media.j3d PointSound setInitialGain

List of usage examples for javax.media.j3d PointSound setInitialGain

Introduction

In this page you can find the example usage for javax.media.j3d PointSound setInitialGain.

Prototype

public void setInitialGain(float amplitude) 

Source Link

Document

Set the overall gain scale factor applied to data associated with this source to increase or decrease its overall amplitude.

Usage

From source file:SimpleSounds.java

/**
 * Add a sound to the transform group. This takes a point sound object and
 * loads into it a sounds from a given file. The edge of the sound's extent
 * is also defined in a parameter.//from w  ww.  j  a v  a  2  s  . com
 * 
 * @param tg
 *            TransformGroup that the sound is to be added to
 * @param sound
 *            PointSound to be used
 * @param soundFile
 *            String that is the name of the sound file to be loaded
 * @param edge
 *            float that represents the sound's maximum extent
 */
protected void addObjectSound(TransformGroup tg, PointSound sound, String soundFile, float edge) {
    //First we get the current transform so that we can
    //position the sound in the same place
    Transform3D objXfm = new Transform3D();
    Vector3f objPosition = new Vector3f();
    tg.getTransform(objXfm);
    objXfm.get(objPosition);
    //Create the media container to load the sound
    MediaContainer soundContainer = new MediaContainer(soundFile);
    //Use the loaded data in the sound
    sound.setSoundData(soundContainer);
    sound.setInitialGain(1.0f);
    //Set the position to that of the given transform
    sound.setPosition(new Point3f(objPosition));
    //Allow use to switch the sound on and off
    sound.setCapability(PointSound.ALLOW_ENABLE_READ);
    sound.setCapability(PointSound.ALLOW_ENABLE_WRITE);
    sound.setSchedulingBounds(bounds);
    //Set it off to start with
    sound.setEnable(false);
    //Set it to loop forever
    sound.setLoop(BackgroundSound.INFINITE_LOOPS);
    //Use the edge value to set to extent of the sound
    Point2f[] attenuation = { new Point2f(0.0f, 1.0f), new Point2f(edge, 0.1f) };
    sound.setDistanceGain(attenuation);
    //Add the sound to the transform group
    tg.addChild(sound);
}

From source file:KeyNavigateTest.java

protected void setSoundAttributes(Sound sound, boolean bCollide) {
    sound.setCapability(Sound.ALLOW_ENABLE_WRITE);
    sound.setCapability(Sound.ALLOW_ENABLE_READ);

    sound.setSchedulingBounds(getSoundSchedulingBounds(bCollide));
    sound.setEnable(getSoundInitialEnable(bCollide));
    sound.setLoop(getSoundLoop(bCollide));
    sound.setPriority(getSoundPriority(bCollide));
    sound.setInitialGain(getSoundInitialGain(bCollide));

    sound.setContinuousEnable(getSoundContinuousEnable(bCollide));
    sound.setReleaseEnable(bCollide);/*from ww  w. ja va2 s. c  o  m*/

    if (sound instanceof PointSound) {
        PointSound pointSound = (PointSound) sound;
        pointSound.setInitialGain(getSoundInitialGain(bCollide));

        Point2f[] gainArray = getSoundDistanceGain(bCollide);

        if (gainArray != null)
            pointSound.setDistanceGain(gainArray);
    }
}