⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 javasoundmixer.java

📁 JAVA3D矩陈的相关类
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * $RCSfile: JavaSoundMixer.java,v $ * * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistribution of source code must retain the above copyright *   notice, this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright *   notice, this list of conditions and the following disclaimer in *   the documentation and/or other materials provided with the *   distribution. * * Neither the name of Sun Microsystems, Inc. or the names of * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * This software is provided "AS IS," without a warranty of any * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed, licensed or * intended for use in the design, construction, operation or * maintenance of any nuclear facility. * * $Revision: 1.4 $ * $Date: 2007/02/09 17:20:04 $ * $State: Exp $ *//* * Audio device driver using Java Sound Mixer Engine. * * IMPLEMENTATION NOTE: The JavaSoundMixer is incomplete and really needs * to be rewritten. */package com.sun.j3d.audioengines.javasound;import java.net.URL;import java.io.InputStream;import javax.vecmath.*;import javax.media.j3d.*;import com.sun.j3d.audioengines.*;import java.util.ArrayList;import java.lang.Thread;/** * The JavaSoundMixer Class defines an audio output device that accesses * JavaSound functionality stream data. */public class JavaSoundMixer extends AudioEngine3DL2 {    // Debug print flags and methods    static final boolean debugFlag = false;    static final boolean internalErrors = false;     void debugPrint(String message) {        if (debugFlag)            System.out.println(message);    }     void debugPrintln(String message) {        if (debugFlag)            System.out.println(message);    }    // Determines method to call for added or setting sound into ArrayList    static final int ADD_TO_LIST = 1;    static final int SET_INTO_LIST = 2;    // current Aural Parameters = Aural Attributes from core + JavaSound    // specific fields, including reverberation parameters.    JSAuralParameters auralParams = null;    // thread for dynamically changing audio parameters such as volume    // and sample rate.    JSThread thread = null;    /*     * new fields in extended class     */      protected         float deviceGain = 1.0f;    protected static  final int   NOT_PAUSED      = 0;    protected static  final int   PAUSE_PENDING   = 1;    protected static  final int   PAUSED          = 2;    protected static  final int   RESUME_PENDING  = 3;    protected         int         pause           = NOT_PAUSED;    /*     * Construct a new JavaSoundMixer with the specified P.E.     * @param physicalEnvironment the physical environment object where we     * want access to this device.     */      public JavaSoundMixer(PhysicalEnvironment physicalEnvironment ) {        super(physicalEnvironment);        thread = new JSThread(Thread.currentThread().getThreadGroup(), this);    }    /**     * Query total number of channels available for sound rendering     * for this audio device.     * Overridden method from AudioEngine.     * @return number of maximum voices play simultaneously on JavaSound Mixer.     */      public int getTotalChannels() {        if (thread != null)            return thread.getTotalChannels();        else            return 32;    }     /**     * Code to initialize the device     * New interface to mixer/engine specific methods      * @return flag: true is initialized sucessfully, false if error     */    public boolean initialize() {        if (thread == null) {            return false;        }        // init JavaSound dynamic thread        thread.initialize();        auralParams = new JSAuralParameters();        if (debugFlag)            debugPrintln("JavaSoundMixer: JSStream.initialize returned true");        return true;    }    /**     * Code to close the device.     * New interface to mixer/engine specific methods      * @return flag: true is closed sucessfully, false if error     */    public boolean close() {        if (thread == null)            return false;        if (thread.close()) {            if (debugFlag)                debugPrintln("JavaSoundMixer: JSStream.close returned true");            return true;        }        else {            if (debugFlag)                debugPrintln("JavaSoundMixer: JSStream.close returned false");            return false;        }    }    /**     * Code to load sound data into a channel of device mixer.     * Load sound as one or mores sample into the Java Sound Mixer:     *   a) as either a STREAM or CLIP based on whether cached is enabled     *   b) positional and directional sounds use three samples per     *      sound     * Overriden method from AudioEngine3D.     *     * Sound type determines if this is a Background, Point or Cone     * sound source and thus the JSXxxxSample object type     * Call JSXxxxxSample.loadSample()     * If no error     *     Get the next free index in the samples list.     *     Store a reference to JSXxxxSample object in samples list.     * @return index to the sample in samples list.     */    public int prepareSound(int soundType, MediaContainer soundData) {        int   index = JSSample.NULL_SAMPLE;        int   methodType = ADD_TO_LIST;        if (soundData == null)            return JSSample.NULL_SAMPLE;        synchronized(samples) {            // for now force to just add to end of samples list            int samplesSize = samples.size();            index = samplesSize;            samples.ensureCapacity(index+1);            boolean error = false;            if (soundType == AudioDevice3D.CONE_SOUND) {                if (debugFlag)                    debugPrintln("JavaSoundMixer.prepareSound type=CONE");                JSDirectionalSample dirSample = new JSDirectionalSample();                error = dirSample.load(soundData);                if (error)                    return JSSample.NULL_SAMPLE;                if (methodType == SET_INTO_LIST)                    samples.set(index, dirSample);                else                    samples.add(index, dirSample);                /*                 * Since no error occurred while loading, save all the                 * characterstics for the sound in the sample.                 */                dirSample.setDirtyFlags(0xFFFF);                dirSample.setSoundType(soundType);                dirSample.setSoundData(soundData);            }            else if (soundType == AudioDevice3D.POINT_SOUND) {                if (debugFlag)                    debugPrintln("JavaSoundMixer.prepareSound type=POINT");                JSPositionalSample posSample = new JSPositionalSample();                error = posSample.load(soundData);                if (error)                    return JSSample.NULL_SAMPLE;                if (methodType == SET_INTO_LIST)                    samples.set(index, posSample);                else                    samples.add(index, posSample);                posSample.setDirtyFlags(0xFFFF);                posSample.setSoundType(soundType);                posSample.setSoundData(soundData);            }            else {  // soundType == AudioDevice3D.BACKGROUND_SOUND                if (debugFlag)                    debugPrintln("JavaSoundMixer.prepareSound type=BACKGROUND");                JSSample sample = null;                sample = new JSSample();                error = sample.load(soundData);                if (error)                    return JSSample.NULL_SAMPLE;                if (methodType == SET_INTO_LIST)                    samples.set(index, sample);                else                    samples.add(index, sample);                sample.setDirtyFlags(0xFFFF);                sample.setSoundType(soundType);                sample.setSoundData(soundData);            }        }                if (debugFlag)  {            debugPrint("               prepareSound type = "+soundType);            debugPrintln("JavaSoundMixer.prepareSound returned "+index);        }        return index;    }    /**     * Clears the fields associated with sample data for this sound.     * Overriden method from AudioEngine3D.     */      public void clearSound(int index) {        // TODO: call JSXXXX clear method        JSSample sample = null;        if ( (sample = (JSSample)getSample(index)) == null)            return;        sample.clear();        synchronized(samples) {            samples.set(index, null);        }    }    /**     * Save a reference to the local to virtual world coordinate space     * Overriden method from AudioEngine3D.     */    public void  setVworldXfrm(int index, Transform3D trans) {        if (debugFlag)            debugPrintln("JavaSoundMixer: setVworldXfrm for index " + index);        super.setVworldXfrm(index, trans);        if (debugFlag) {            double[] matrix = new double[16];            trans.get(matrix);            debugPrintln("JavaSoundMixer     column-major transform ");            debugPrintln("JavaSoundMixer         " + matrix[0]+", "+matrix[1]+                         ", "+matrix[2]+", "+matrix[3]);            debugPrintln("JavaSoundMixer         " + matrix[4]+", "+matrix[5]+                         ", "+matrix[6]+", "+matrix[7]);            debugPrintln("JavaSoundMixer         " + matrix[8]+", "+matrix[9]+                         ", "+matrix[10]+", "+matrix[11]);            debugPrintln("JavaSoundMixer         " + matrix[12]+", "+matrix[13]+                         ", "+matrix[14]+", "+matrix[15]);        }        JSSample sample = null;        if ((sample = (JSSample)getSample(index)) == null)            return;        int   soundType = sample.getSoundType();        if (soundType == AudioDevice3D.CONE_SOUND) {            JSDirectionalSample dirSample = null;            if ((dirSample = (JSDirectionalSample)getSample(index)) == null)                return;            dirSample.setXformedDirection();            dirSample.setXformedPosition();            // flag that VirtualWorld transform set            dirSample.setVWrldXfrmFlag(true);        }        else if (soundType == AudioDevice3D.POINT_SOUND) {            JSPositionalSample posSample = null;            if ((posSample = (JSPositionalSample)getSample(index)) == null)                return;            posSample.setXformedPosition();            // flag that VirtualWorld transform set            posSample.setVWrldXfrmFlag(true);        }        return;    }    /*     * Overriden method from AudioEngine3D.     */    public void   setPosition(int index, Point3d position) {        if (debugFlag)            debugPrintln("JavaSoundMixer: setPosition for index " + index);        super.setPosition(index, position);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -