📄 jsthread.java
字号:
", " + rightGain); if (dataType == JSAuralParameters.STREAMING_AUDIO_DATA || dataType == JSAuralParameters.BUFFERED_AUDIO_DATA ) { thread.setSampleGain(sample, leftGain); if ( (soundType == AudioDevice3D.CONE_SOUND) || (soundType == AudioDevice3D.POINT_SOUND) ) { thread.setSampleGain( ((JSPositionalSample)sample).getSecondIndex(), rightGain); thread.setSampleGain( ((JSPositionalSample)sample).getReverbIndex(), reverbGain); } } // TODO: JavaSound does not support MIDI song panning yet else if (dataType == JSAuralParameters.STREAMING_MIDI_DATA || dataType == JSAuralParameters.BUFFERED_MIDI_DATA) { // Stereo samples not used for Midi Song playback thread.setSampleGain(sample, (leftGain+rightGain) ); ****** // -1.0 far left, 0.0 center, 1.0 far right position = (leftGain - rightGain) / (leftGain + rightGain); JSMidi.setSamplePan(sample, position); if ( (soundType == AudioDevice3D.CONE_SOUND) || (soundType == AudioDevice3D.POINT_SOUND) ) { JSMidi.setSampleGain( ((JSPositionalSample)sample).getSecondIndex(), rightGain); JSMidi.setSampleGain( ((JSPositionalSample)sample).getReverbIndex(), reverbGain); } ****** } else { if (debugFlag) debugPrint( "JSThread: Internal Error setSampleGain dataType " + dataType + " invalid"); return; } ***** // force specific gain // go ahead and set gain immediately this.setSampleGain(sample, scaleFactor); rampGain = false; // disable ramping of gain******/ } void setSampleDelay(JSSample sample, JSAuralParameters attribs) { /****** // take fields as already set in sample and updates delay // called after sample.render performed // adjust by attrib rolloff float delayTime = attribs.reverbDelay * attribs.rolloff; leftDelay = (int)(sample.leftDelay * attribs.rolloff); rightDelay = (int)(sample.rightDelay * attribs.rolloff);leftDelay, rightDelay int dataType = sample.getDataType(); int soundType = sample.getSoundType(); if (debugFlag) debugPrint("setStereoDelay for sample "+sample+" " + leftDelay + ", " + rightDelay); if (dataType == JSAuralParameters.STREAMING_AUDIO_DATA) { if ( (soundType == AudioDevice3D.CONE_SOUND) || (soundType == AudioDevice3D.POINT_SOUND) ) { JSStream.setSampleDelay( sample, leftDelay); JSStream.setSampleDelay( ((JSPositionalSample)sample).getSecondIndex(), rightDelay); } else JSStream.setSampleDelay(sample, 0); } else if (dataType == JSAuralParameters.BUFFERED_AUDIO_DATA) { if ( (soundType == AudioDevice3D.CONE_SOUND) || (soundType == AudioDevice3D.POINT_SOUND) ) { JSClip.setSampleDelay( sample, leftDelay); JSClip.setSampleDelay( ((JSPositionalSample)sample).getSecondIndex(), rightDelay); } else JSClip.setSampleDelay(sample, 0); } else if (dataType == JSAuralParameters.STREAMING_MIDI_DATA || dataType == JSAuralParameters.BUFFERED_MIDI_DATA) { ******** if ( (soundType == AudioDevice3D.CONE_SOUND) || (soundType == AudioDevice3D.POINT_SOUND) ) { JSMidi.setSampleDelay( sample, leftDelay); JSMidi.setSampleDelay( ((JSPositionalSample)sample).getSecondIndex(), rightDelay); } else ******** JSMidi.setSampleDelay(sample, 0); } else { if (debugFlag) debugPrint( "JSThread: Internal Error setSampleDelay dataType " + dataType + " invalid"); return; }******/ } void setTargetGain(JSSample sample, float scaleFactor) {/**********// TODO: implement this // current gain is used as starting scalefactor for ramp// TEMPORARY: for now just set gain this.setSampleGain(sample, scaleFactor); rampGain = false; rampGain = true; targetGain = scaleFactor; runMonitor(RUN, 0, null);**********/ } void setRate(JSSample sample, float rateScaleFactor) { // force specific rate // go ahead and set rate immediately // take fields as already set in sample and updates rate // called after sample.render performed this.setSampleRate(sample, rateScaleFactor); // disables rate from being gradually increased or decreased // don't set global thread flat rampRate false just because // one sample's rate is set to a specific value. sample.setRampRateFlag(false); } void setTargetRate(JSSample sample, float rateScaleFactor) { // make gradual change in rate factors up or down to target rate sample.setRampRateFlag(true); sample.setTargetRateRatio(rateScaleFactor); rampRate = true; runMonitor(RUN, 0, null); }// TODO: should have methods for delay and pan as well void setSampleGain(JSSample sample, float gain) {/***********// QUESTION: What needs to be synchronized??? if (debugFlag) debugPrint("JSThread.setSampleGain for sample "+sample+" " + gain ); int dataType = sample.getDataType(); int soundType = sample.getSoundType(); boolean muted = sample.getMuteFlag();// TODO: if (dataType == JSAuralParameters.STREAMING_AUDIO_DATA){ com.sun.j3d.audio.J3DHaeStream.setSampleGain(index, gain); } else if (dataType == JSAuralParameters.BUFFERED_AUDIO_DATA) { com.sun.j3d.audio.J3DHaeClip.setSampleGain(index, gain); } else { // dataType==JSAuralParameters.STREAMING_MIDI_DATA // dataType==JSAuralParameters.BUFFERED_MIDI_DATA com.sun.j3d.audio.J3DHaeMidi.setSampleGain(index, gain); }***************/ } void setSampleRate(JSSample sample, float scaleFactor) {/*********// QUESTION: What needs to be synchronized??? // TODO: use sample.rateRatio?? if (debugFlag) debugPrint("JSThread.setSampleRate sample " + sample + ", scale factor = " + scaleFactor); int dataType = sample.getDataType(); int soundType = sample.getSoundType();// TODO: if (dataType == JSAuralParameters.STREAMING_AUDIO_DATA) { com.sun.j3d.audio.J3DHaeStream.scaleSampleRate(index, scaleFactor); if ( (soundType == AudioDevice3D.CONE_SOUND) || (soundType == AudioDevice3D.POINT_SOUND) ) { com.sun.j3d.audio.J3DHaeStream.scaleSampleRate( ((JSPositionalSample)sample).getSecondIndex(), scaleFactor); com.sun.j3d.audio.J3DHaeStream.scaleSampleRate( ((JSPositionalSample)sample).getReverbIndex(), scaleFactor); } } else if (dataType == JSAuralParameters.BUFFERED_AUDIO_DATA) { com.sun.j3d.audio.J3DHaeClip.scaleSampleRate(index, scaleFactor); if ( (soundType == AudioDevice3D.CONE_SOUND) || (soundType == AudioDevice3D.POINT_SOUND) ) { com.sun.j3d.audio.J3DHaeClip.scaleSampleRate( ((JSPositionalSample)sample).getSecondIndex(), scaleFactor); com.sun.j3d.audio.J3DHaeClip.scaleSampleRate( ((JSPositionalSample)sample).getReverbIndex(), scaleFactor); } } else if (dataType == JSAuralParameters.STREAMING_MIDI_DATA || dataType == JSAuralParameters.BUFFERED_MIDI_DATA) { com.sun.j3d.audio.J3DHaeMidi.scaleSampleRate(index, scaleFactor); // TODO: MIDI only supported for Background sounds }***********/ sample.setCurrentRateRatio(scaleFactor); } boolean startSample(JSSample sample) {/**********// QUESTION: should this have a return values - error - or not?? int returnValue = 0; AuralParameters attribs = audioEngine.getAuralParameters(); int soundType = sample.getSoundType(); boolean muted = sample.getMuteFlag(); int dataType = sample.getDataType(); int loopCount = sample.getLoopCount(); float leftGain = sample.leftGain; float rightGain = sample.rightGain; int leftDelay = (int)(sample.leftDelay * attribs.rolloff); int rightDelay = (int)(sample.rightDelay * attribs.rolloff); if (dataType == JSAuralParameters.STREAMING_AUDIO_DATA) { if (soundType == AudioDevice3D.BACKGROUND_SOUND) { returnValue = JSStream.startSample(sample, loopCount, leftGain); if (debugFlag) debugPrint("JSThread " + "start stream backgroundSound with gain " + leftGain); } else { // soundType is POINT_SOUND or CONE_SOUND // start up main left and right channels for spatial rendered sound returnValue = JSStream.startSamples(sample, ((JSPositionalSample)sample).getSecondIndex(), loopCount, leftGain, rightGain, leftDelay, rightDelay); // // start up reverb channel w/out delay even if reverb not on now // float reverbGain = 0.0f; if (!muted && auralParams.reverbFlag) { reverbGain = sample.getGain() * attribs.reflectionCoefficient; } int reverbRtrnVal = JSStream.startSample( ((JSPositionalSample)sample).getReverbIndex(), loopCount, reverbGain); if (debugFlag) debugPrint("JSThread " + "start stream positionalSound with gain "+ leftGain + ", " + rightGain); } } else if (dataType == JSAuralParameters.BUFFERED_AUDIO_DATA) { if (soundType == AudioDevice3D.BACKGROUND_SOUND) { returnValue = JSClip.startSample(sample, loopCount, leftGain ); if (debugFlag) debugPrint("JSThread " + "start buffer backgroundSound with gain " + leftGain); } else { // soundType is POINT_SOUND or CONE_SOUND // start up main left and right channels for spatial rendered sound returnValue = JSClip.startSamples(sample, ((JSPositionalSample)sample).getSecondIndex(), loopCount, leftGain, rightGain, leftDelay, rightDelay); // // start up reverb channel w/out delay even if reverb not on now // float reverbGain = 0.0f; if (!muted && auralParams.reverbFlag) { reverbGain = sample.getGain() * attribs.reflectionCoefficient; } int reverbRtrnVal = JSClip.startSample( ((JSPositionalSample)sample).getReverbIndex(), loopCount, reverbGain); if (debugFlag) debugPrint("JSThread " + "start stream positionalSound with gain " + leftGain + ", " + rightGain); } } else if (dataType == JSAuralParameters.STREAMING_MIDI_DATA || dataType == JSAuralParameters.BUFFERED_MIDI_DATA) { if (soundType == AudioDevice3D.BACKGROUND_SOUND) { returnValue = JSMidi.startSample(sample, loopCount, leftGain);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -