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

📄 javasoundmixer.java

📁 JAVA3D矩陈的相关类
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        JSPositionalSample posSample = null;        if ((posSample = (JSPositionalSample)getSample(index)) == null)            return;        int   soundType = posSample.getSoundType();        if ( (soundType == AudioDevice3D.POINT_SOUND) ||             (soundType == AudioDevice3D.CONE_SOUND) ) {            posSample.setXformedPosition();        }        return;    }    /*          * Overriden method from AudioEngine3D.     */     public void setDirection(int index, Vector3d direction) {        if (debugFlag)            debugPrintln("JavaSoundMixer: setDirection for index " + index);        super.setDirection(index, direction);        JSDirectionalSample dirSample = null;        if ((dirSample = (JSDirectionalSample)getSample(index)) == null)            return;        int   soundType = dirSample.getSoundType();        if (soundType == AudioDevice3D.CONE_SOUND) {            dirSample.setXformedDirection();        }        return;    }     /*          * Overriden method from AudioEngine3D.     */     public void setReflectionCoefficient(float coefficient) {        super.setReflectionCoefficient(coefficient);        auralParams.reverbDirty |= JSAuralParameters.REFLECTION_COEFF_CHANGED;        return;    }    /*          * Overriden method from AudioEngine3D.     */     public void setReverbDelay(float reverbDelay) {        super.setReverbDelay(reverbDelay);        auralParams.reverbDirty |= JSAuralParameters.REVERB_DELAY_CHANGED;        return;    }    /*          * Overriden method from AudioEngine3D.     */     public void setReverbOrder(int reverbOrder) {        super.setReverbOrder(reverbOrder);        auralParams.reverbDirty |=  JSAuralParameters.REVERB_ORDER_CHANGED;        return;    }    /*     * QUESTION: if this is used, for now, exclusively, to start a Background     *    or any single sampled Sounds, why are there if-else cases to handle     *    Point and Cone sounds??     *     * For now background sounds are not reverberated     *      * Overriden method from AudioEngine3D.     */    public int   startSample(int index) {	// TODO: Rewrite this function        if (debugFlag)            debugPrintln("JavaSoundMixer: STARTSample for index " + index);        JSSample sample = null;        if ( ( (sample = (JSSample)getSample(index)) == null) ||             thread == null )             return JSSample.NULL_SAMPLE;        int   soundType = sample.getSoundType();        boolean muted = sample.getMuteFlag();        if (muted) {            if (debugFlag)                debugPrintln("                            MUTEd start");            thread.muteSample(sample);            if (soundType != AudioDevice3D.BACKGROUND_SOUND)                setFilter(index, false, Sound.NO_FILTER);        }        else {            sample.render(sample.getDirtyFlags(), getView(), auralParams);            this.scaleSampleRate(index, sample.rateRatio);            // filtering            if (soundType != AudioDevice3D.BACKGROUND_SOUND)                setFilter(index, sample.getFilterFlag(), sample.getFilterFreq());        }         boolean startSuccessful;        startSuccessful = thread.startSample(sample);	sample.channel.startSample(sample.getLoopCount(), sample.getGain(), 0);        if (!startSuccessful) {            if (internalErrors)                debugPrintln(                     "JavaSoundMixer: Internal Error startSample for index " +                    index + " failed");            return JSSample.NULL_SAMPLE;        }        else {            if (debugFlag)                debugPrintln("                startSample worked, " +                       "returning " + startSuccessful);            // NOTE: Set AuralParameters AFTER sound started             // Setting AuralParameters before you start sound doesn't work            if (!muted) {                if (auralParams.reverbDirty > 0) {                    if (debugFlag) {                        debugPrintln("startSample: reverb settings are:");                        debugPrintln("    coeff = "+                              auralParams.reflectionCoefficient +                              ", delay = " + auralParams.reverbDelay +                              ", order = " + auralParams.reverbOrder);                    }                    float delayTime = auralParams.reverbDelay * auralParams.rolloff;                    calcReverb(sample);                }                // NOTE: it apprears that reverb has to be reset in                // JavaSound engine when sound re-started??                // force reset of reverb parameters when sound is started                setReverb(sample);            }            return index;        }    }       /*          * Overriden method from AudioEngine3D.     */     public int   stopSample(int index) {	// TODO: Rewrite this function        if (debugFlag)            debugPrintln("JavaSoundMixer: STOPSample for index " + index);        JSSample sample = null;        if ((sample = (JSSample)getSample(index)) == null)            return -1;        int   dataType = sample.getDataType();        int   soundType = sample.getSoundType();        boolean stopSuccessful = true;        stopSuccessful = thread.stopSample(sample);	sample.channel.stopSample();        if (!stopSuccessful) {            if (internalErrors)                debugPrintln( "JavaSoundMixer: Internal Error stopSample(s) for index " +                    index + " failed");            return -1;        }        else {            // set fields in sample to reset for future start            sample.reset();            if (debugFlag)                debugPrintln("JavaSoundMixer: stopSample for index " +                       index + " worked, returning " + stopSuccessful);            return 0;        }    }    /*          * Overriden method from AudioEngine3D.     */     public void pauseSample(int index) {        if (debugFlag)            debugPrintln("JavaSoundMixer: PAUSESample for index " + index);        JSSample sample = null;        if ((sample = (JSSample)getSample(index)) == null)            return;        // check thread != null        thread.pauseSample(sample);    }    /*          * Overriden method from AudioEngine3D.     */     public void unpauseSample(int index) {        if (debugFlag)            debugPrintln("JavaSoundMixer: UNPAUSESample for index " + index);        JSSample sample = null;        if ((sample = (JSSample)getSample(index)) == null)            return;        thread.unpauseSample(sample);    }    /*          * Force thread to update sample.     * Overriden method from AudioEngine3D.     */     public void updateSample(int index) {        if (debugFlag)            debugPrintln("JavaSoundMixer: UPDATESample for index " + index);        JSSample sample = null;        if ( ( (sample = (JSSample)getSample(index)) == null) ||             thread == null )             return;        int   soundType = sample.getSoundType();        boolean muted = sample.getMuteFlag();        if (muted) {            if (soundType != AudioDevice3D.BACKGROUND_SOUND)                setFilter(index, false, Sound.NO_FILTER);            thread.muteSample(sample);            if (debugFlag)                debugPrintln("   Mute during update");        }        else {            // If reverb parameters changed resend to audio device            if (auralParams.reverbDirty > 0) {                if (debugFlag) {                    debugPrintln("updateSample: reverb settings are:");                    debugPrintln("    coeff = " +   auralParams.reflectionCoefficient+                        ", delay = " + auralParams.reverbDelay +                        ", order = " + auralParams.reverbOrder);                }                float delayTime = auralParams.reverbDelay * auralParams.rolloff;                calcReverb(sample);            }            // TODO: Only re-set reverb if values different            // For now force reset to ensure that reverb is currently correct            setReverb(sample);  // ensure reverb is current/correct            // TODO: For now sum left & rightGains for reverb gain            float reverbGain = 0.0f;             if (!muted && auralParams.reverbFlag) {                reverbGain = sample.getGain() * auralParams.reflectionCoefficient;             }            sample.render(sample.getDirtyFlags(), getView(), auralParams);            // filtering            if (soundType != AudioDevice3D.BACKGROUND_SOUND)                setFilter(index, sample.getFilterFlag(), sample.getFilterFreq());            thread.setSampleGain(sample, auralParams);            thread.setSampleRate(sample, auralParams);            thread.setSampleDelay(sample, auralParams);        }        return;    }    /*          * Overriden method from AudioEngine3D.     */     public void   muteSample(int index) {        JSSample sample = null;        if ((sample = (JSSample)getSample(index)) == null)            return;        if (debugFlag)            debugPrintln("JavaSoundMixer: muteSample");        sample.setMuteFlag(true);        thread.muteSample(sample);        return;    }    /*          * Overriden method from AudioEngine3D.     */     public void   unmuteSample(int index) {        JSSample sample = null;        if ((sample = (JSSample)getSample(index)) == null)            return;        if (debugFlag)            debugPrintln("JavaSoundMixer: unmuteSample");        sample.setMuteFlag(false);        // since while mute the reverb type and state was not updated...        // Reverb has to be recalculated when sound is unmuted .        auralParams.reverbDirty = 0xFFFF;  // force an update of reverb params        sample.setDirtyFlags(0xFFFF); // heavy weight forcing of gain/delay update        // TODO: force an update of ALL parameters that could have changed        // while muting disabled...        thread.unmuteSample(sample);        return;    }    /*          * Overriden method from AudioEngine3D.     */     public long  getSampleDuration(int index) {        JSSample sample = null;        if ((sample = (JSSample)getSample(index)) == null)            return Sample.DURATION_UNKNOWN;        long duration;        if (sample != null)            duration = sample.getDuration();        else            duration = Sample.DURATION_UNKNOWN;        if (debugFlag)             debugPrintln("                return duration " + duration);        return duration;    }    /*          * Overriden method from AudioEngine3D.     */     public int   getNumberOfChannelsUsed(int index) {        /*         * Calls same method with different signature containing the         * sample's mute flag passed as the 2nd parameter.         */         JSSample sample = null;        if ((sample = (JSSample)getSample(index)) == null)            return 0;        else             return getNumberOfChannelsUsed(index, sample.getMuteFlag());    }

⌨️ 快捷键说明

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