当前位置: 首页>>代码示例>>Java>>正文


Java FloatControl.setValue方法代码示例

本文整理汇总了Java中javax.sound.sampled.FloatControl.setValue方法的典型用法代码示例。如果您正苦于以下问题:Java FloatControl.setValue方法的具体用法?Java FloatControl.setValue怎么用?Java FloatControl.setValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.sound.sampled.FloatControl的用法示例。


在下文中一共展示了FloatControl.setValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start

import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
/**
 * Plays the clip with the specified volume.
 * @param volume the volume the play at
 * @param listener the line listener
 * @throws LineUnavailableException if a clip object is not available or
 *         if the line cannot be opened due to resource restrictions
 */
public void start(float volume, LineListener listener) throws LineUnavailableException {
	Clip clip = getClip();
	if (clip == null)
		return;

	// PulseAudio does not support Master Gain
	if (clip.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
		// set volume
		FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
		float dB = (float) (Math.log(volume) / Math.log(10.0) * 20.0);
		gainControl.setValue(dB);
	}

	if (listener != null)
		clip.addLineListener(listener);
	clip.setFramePosition(0);
	clip.start();
}
 
开发者ID:yugecin,项目名称:opsu-dance,代码行数:26,代码来源:MultiClip.java

示例2: play

import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
private void play(String wavPath, float db) {
    if (!dnd && db > -40) {
        ClassLoader classLoader = getClass().getClassLoader();
        try (AudioInputStream stream = AudioSystem.getAudioInputStream(classLoader.getResource(wavPath))) {
            Clip clip = AudioSystem.getClip();
            clip.open(stream);
            if (db != 0.0) {
                FloatControl gainControl =
                        (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
                gainControl.setValue(db);
            }
            clip.start();
        } catch (Exception e) {
            logger.error("Cannot start playing wav file: ", e);
        }
    }
}
 
开发者ID:Exslims,项目名称:MercuryTrade,代码行数:18,代码来源:SoundNotifier.java

示例3: playMainMusic

import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
public void playMainMusic() {
try {
	clip = (Clip)AudioSystem.getLine(new Line.Info(Clip.class));
       clip.open(AudioSystem.getAudioInputStream(new File("sounds/main.wav")));
       
       FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
       gainControl.setValue(-20.0f); // Muziek moet niet boven soundeffects uitkomen, dus 20dB zachter
       
       clip.start();
       clip.loop(Clip.LOOP_CONTINUOUSLY);
   }
   catch (Exception exc) {
       exc.printStackTrace(System.out);
   }
    }
 
开发者ID:niekBr,项目名称:Mario,代码行数:16,代码来源:Menu.java

示例4: invokeAction

import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
@Override
public void invokeAction(final PiAction action) throws RaspberryPiAppException {
    final String soundFile = baseSoundDirectory + action.getValue();
    LOGGER.debug("Playing sound file: '{}'", soundFile);

    try {
        final AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(
                new File(soundFile));
        final Clip clip = AudioSystem.getClip();
        clip.open(audioInputStream);

        // play at maximum volume
        final FloatControl gainControl =
                (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
        gainControl.setValue(gainControl.getMaximum());

        clip.start();

    } catch (Exception e) {
        throw new RaspberryPiAppException(e.getMessage(), e);
    }
}
 
开发者ID:justinhrobbins,项目名称:raspberry-pi-api,代码行数:23,代码来源:PlaySoundActionImpl.java

示例5: setVolume

import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
/**
 * Sets the volume.
 *
 * @param vol the volume
 */
private void setVolume(final int vol) {

    int volume = vol;
    if (volume < 0) {
        volume = MAX_VOLUME;
    }
    float gainDb = 0.0f;
    final FloatControl gain = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);

    if (volume == 0) {
        gainDb = gain.getMinimum();

    } else if (volume < MAX_VOLUME) {

  // The volume algorithm is subtractive: The implementation assumes that
        // the sound is already at maximum volume, so we avoid distortion by
        // making the amplitude values
        // The scaling factor for the volume would be 20 normally, but
        // it seems that 13 is better
        gainDb = (float) (Math.log10(MAX_VOLUME - volume) * 13.0);
    }
    gain.setValue(-gainDb);
}
 
开发者ID:wandora-team,项目名称:zmpp-wandora,代码行数:29,代码来源:DefaultSoundEffect.java

示例6: init

import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
private void init() {
	AudioFormat speexFormat = new AudioFormat(16000, 16, 1, true, false);
	DataLine.Info sourceLineInfo = new DataLine.Info(SourceDataLine.class, speexFormat, bufferSize);
	speexDecoder.init(1, 16000, 1, false);
	try {
		line = (SourceDataLine) AudioSystem.getLine(sourceLineInfo);
		line.open(speexFormat, bufferSize);

		volumeControl = (FloatControl) line.getControl(FloatControl.Type.MASTER_GAIN);
		minGainDB = volumeControl.getMinimum();
		ampGainDB = ((10.0f / 20.0f) * volumeControl.getMaximum()) - volumeControl.getMinimum();
		cste = Math.log(10.0) / 20;

		volumeControl.setValue((float) minGainDB);

		line.start();

	} catch (LineUnavailableException e) {
		App.logger.w("Failed to create voice player (type: " + type + " id: " + playerId + "):" , e);
		if (!exit)
			close(false);
	}
}
 
开发者ID:WegFetZ,项目名称:SoundCenterClient,代码行数:24,代码来源:VoicePlayer.java

示例7: start

import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
/**
 * Plays the clip with the specified volume.
 * @param volume the volume the play at
 * @param listener the line listener
 * @throws LineUnavailableException if a clip object is not available or
 *         if the line cannot be opened due to resource restrictions
 */
public void start(float volume, LineListener listener) throws LineUnavailableException {
	Clip clip = getClip();
	if (clip == null)
		return;

	// PulseAudio does not support Master Gain
	if (clip.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
		// set volume
		FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
		float dB = (float) (Math.log(volume) / Math.log(10.0) * 20.0);
		gainControl.setValue(Utils.clamp(dB, gainControl.getMinimum(), gainControl.getMaximum()));
	} else if (clip.isControlSupported(FloatControl.Type.VOLUME)) {
		// The docs don't mention what unit "volume" is supposed to be,
		// but for PulseAudio it seems to be amplitude
		FloatControl volumeControl = (FloatControl) clip.getControl(FloatControl.Type.VOLUME);
		float amplitude = (float) Math.sqrt(volume) * volumeControl.getMaximum();
		volumeControl.setValue(Utils.clamp(amplitude, volumeControl.getMinimum(), volumeControl.getMaximum()));
	}

	if (listener != null)
		clip.addLineListener(listener);
	clip.setFramePosition(0);
	clip.start();
}
 
开发者ID:itdelatrisu,项目名称:opsu,代码行数:32,代码来源:MultiClip.java

示例8: play

import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
/**
 * Plays the Clip. If the sound is off, the volume is set to the minimum.
 * @param name The name of the Clip to play.
 */
public void play(String name) {
	Clip c = get(name);
	
	if(c != null) {
		c.stop();
		c.flush();
		c.setFramePosition(0);
		
		if(!on) {
			FloatControl volume = (FloatControl)c.getControl(FloatControl.Type.MASTER_GAIN);
			volume.setValue(volume.getMinimum());
		}
		
		c.start();
	}
}
 
开发者ID:ra4king,项目名称:GameUtils,代码行数:21,代码来源:Sound.java

示例9: loop

import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
/**
 * Loops the Clip. If the sound is off, the volume is set to the minimum.
 * @param name The name of the Clip to loop.
 */
public void loop(String name) {
	Clip c = get(name);
	
	if(c != null) {
		c.stop();
		c.flush();
		c.setFramePosition(0);
		
		if(!on) {
			FloatControl volume = (FloatControl)c.getControl(FloatControl.Type.MASTER_GAIN);
			volume.setValue(volume.getMinimum());
		}
		
		c.loop(Clip.LOOP_CONTINUOUSLY);
	}
}
 
开发者ID:ra4king,项目名称:GameUtils,代码行数:21,代码来源:Sound.java

示例10: setSoundVolume

import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
/**
 * 
 * Automatically called on construction and game setting change to match clip volume to
 * user defined levels.
 * 
 * @param value
 * 		percentage to set music volume to
 * 
 */
private void setSoundVolume(int value) {
	if (value == 0) {
		soundOff = true;
		return;
	}
	
	soundOff = false;
	
	float decibelLevelOffset = SoundUtils.resolveDecibelOffsetFromPercentage(value);
	System.out.println("Decibel offset for sound: " + decibelLevelOffset);
	for (GameSoundEffect effect : GameSoundEffect.values() ) {
		Optional<Clip> clip = sounds.get(effect);
		if (clip.isPresent() ) {
			FloatControl gainControl = (FloatControl)
				clip.get().getControl(FloatControl.Type.MASTER_GAIN);
			gainControl.setValue(decibelLevelOffset);
		}
	}
}
 
开发者ID:ErikaRedmark,项目名称:monkey-shines-java-port,代码行数:29,代码来源:JavaDefaultSoundManager.java

示例11: setValue

import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
private void setValue(FloatControl.Type type, float v)
{
  if (hasControl(type))
  {
    FloatControl c = (FloatControl) getControl(type);
    if (v > c.getMaximum())
      v = c.getMaximum();
    else if (v < c.getMinimum()) v = c.getMinimum();
    c.setValue(v);
  }
  else
  {
    Minim.error(type.toString() + " is not supported.");
  }
}
 
开发者ID:JacobRoth,项目名称:romanov,代码行数:16,代码来源:Controller.java

示例12: setBalance

import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
final public void setBalance(int intPbalancePercentage) {

		if (this.objGclip != null && this.objGclip.isControlSupported(FloatControl.Type.PAN)) {
			try {
				final FloatControl objLbalanceFloatControl = (FloatControl) this.objGclip.getControl(FloatControl.Type.PAN);
				objLbalanceFloatControl.setValue(Math.max(-100, Math.min(intPbalancePercentage, 100)) / 100.0F);
			} catch (final Throwable objPthrowable) {
				Tools.err("Error while setting sound balance : ", Constants.strS_FILE_SOUND_NAME_A[this.bytGsoundFileIndex]);
			}
		}
	}
 
开发者ID:jugglemaster,项目名称:JuggleMasterPro,代码行数:12,代码来源:ExtendedClip.java

示例13: setVolume

import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
final public void setVolume(int intPvolumePercentage) {

		try {
			final float fltLvolume = this.getVolume(intPvolumePercentage);
			final FloatControl objLvolumeFloatControl = (FloatControl) this.objGclip.getControl(FloatControl.Type.MASTER_GAIN);
			objLvolumeFloatControl.setValue(fltLvolume);
		} catch (final Throwable objPthrowable) {
			Tools.err("Error while setting sound volume : ", Constants.strS_FILE_SOUND_NAME_A[this.bytGsoundFileIndex]);
		}
	}
 
开发者ID:jugglemaster,项目名称:JuggleMasterPro,代码行数:11,代码来源:ExtendedClip.java

示例14: main

import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
    boolean res = true;
    try {
        AudioInputStream ais = new AudioInputStream(
                new ByteArrayInputStream(new byte[2000]),
                new AudioFormat(8000.0f, 8, 1, false, false), 2000); //
        AudioFormat format = ais.getFormat();
        DataLine.Info info = new DataLine.Info(Clip.class, format,
                                               ((int) ais.getFrameLength()
                                                        * format
                                                       .getFrameSize()));
        Clip clip = (Clip) AudioSystem.getLine(info);
        clip.open();
        FloatControl rateControl = (FloatControl) clip.getControl(
                FloatControl.Type.SAMPLE_RATE);
        int c = 0;
        while (c++ < 10) {
            clip.stop();
            clip.setFramePosition(0);
            clip.start();
            for (float frq = 22000; frq < 44100; frq = frq + 100) {
                try {
                    Thread.currentThread().sleep(20);
                } catch (Exception e) {
                    break;
                }
                rateControl.setValue(frq);
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        res = ex.getMessage().indexOf(
                "This method should not have been invoked!") < 0;
    }
    if (res) {
        System.out.println("Test passed");
    } else {
        System.out.println("Test failed");
        throw new Exception("Test failed");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:42,代码来源:ClipOpenBug.java

示例15: setVolume

import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
@Override
public void setVolume(float volume) {
	
	FloatControl control = (FloatControl)this.controls.get("Master Gain");
	float min = control.getMinimum();
	float max = control.getMaximum();
	float oldVal = control.getValue();
	float newVal = volume < min ? min : (volume > max ? max : volume);
	control.setValue(newVal);
	this.trigger(AudioEvent.Type.VOLUME_CHANGED, oldVal, newVal);
}
 
开发者ID:RalleYTN,项目名称:SimpleAudio,代码行数:12,代码来源:AbstractAudio.java


注:本文中的javax.sound.sampled.FloatControl.setValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。