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


Java Clip.getControl方法代码示例

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


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

示例1: start

import javax.sound.sampled.Clip; //导入方法依赖的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.Clip; //导入方法依赖的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: PreloadedPlayback

import javax.sound.sampled.Clip; //导入方法依赖的package包/类
/**
 * Creates a new {@code PreloadedPlayback}. PreloadedPlayback objects will
 * always be created by their associated PreloadedAudio object.
 * <p>
 * IMPLEMENTATION NOTE: Originally, the fetching of a new {@code Line} was
 * done in the {@code run} method, however testing revealed that latency is
 * decreased if a {@code Line} is acquired ahead of time, here in the
 * constructor.
 * 
 * @param audio
 *            The {@code Audio} that created this {@code PreloadedPlayback}.
 * @param audioFormat
 *            Specifies the particular arrangement of audio data.
 * @param audioBytes
 *            Holds the audio data from which a {@code Clip} will be
 *            created.
 * @param instanceID
 *            The {@code instanceID} of this {@code PreloadedPlayback}.
 */
protected PreloadedPlayback(Audio audio, AudioFormat audioFormat,
		byte[] audioBytes, long instanceID) {
	super(audio, instanceID);
	DataLine.Info info = new DataLine.Info(Clip.class, audioFormat);
	try {
		clip = (Clip) AudioSystem.getLine(info);
		clip.open(audioFormat, audioBytes, 0, audioBytes.length);
		if (clip.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
			volCtrl = (FloatControl) clip
					.getControl(FloatControl.Type.MASTER_GAIN);
		} else {
			logger.warning("Master-Gain control is not supported."
					+ " Volume will be fixed at the default level.");
		}
	} catch (LineUnavailableException ex) {
		ex.printStackTrace();
	}
	clip.addLineListener(this);
}
 
开发者ID:cmholton,项目名称:QwickSound,代码行数:39,代码来源:PreloadedPlayback.java

示例4: playMainMusic

import javax.sound.sampled.Clip; //导入方法依赖的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

示例5: invokeAction

import javax.sound.sampled.Clip; //导入方法依赖的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

示例6: main

import javax.sound.sampled.Clip; //导入方法依赖的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

示例7: playSound

import javax.sound.sampled.Clip; //导入方法依赖的package包/类
private void playSound(String fileName){
    try{
        File soundFile = new File(fileName);
        AudioInputStream ais = AudioSystem.getAudioInputStream(soundFile);
        AudioFormat format = ais.getFormat();
        DataLine.Info info = new DataLine.Info(Clip.class, format);
        Clip clip = (Clip) AudioSystem.getLine(info);
        clip.open(ais);
        FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
        gainControl.setValue(-10);
        clip.start();
    }catch(Exception e){
        e.printStackTrace();
    }
}
 
开发者ID:BossLetsPlays,项目名称:Firestorm,代码行数:16,代码来源:MusicPlayer.java

示例8: setPanning

import javax.sound.sampled.Clip; //导入方法依赖的package包/类
public void setPanning(int chan,int sep){
Clip c=channels[chan];

if (c.isControlSupported(Type.PAN)){
	FloatControl bc=(FloatControl) c.getControl(Type.PAN);
	// Q: how does Doom's sep map to stereo panning?
	// A: Apparently it's 0-255 L-R.
	float pan= bc.getMinimum()+(bc.getMaximum()-bc.getMinimum())*(float)sep/ISoundDriver.PANNING_STEPS;
	bc.setValue(pan);
	}
}
 
开发者ID:AXDOOMER,项目名称:mochadoom,代码行数:12,代码来源:ClipSFXModule.java

示例9: setVolume

import javax.sound.sampled.Clip; //导入方法依赖的package包/类
/**
 * 音量を設定
 * @param vol 新しい設定音量 (1.0が default )
 */
public void setVolume(double vol) {
	volume = vol;

	Set<String> set = clipMap.keySet();
	for(String name: set) {
		try {
			Clip clip = clipMap.get(name);
			FloatControl ctrl = (FloatControl)clip.getControl(FloatControl.Type.MASTER_GAIN);
			ctrl.setValue((float)Math.log10(volume) * 20);
		} catch (Exception e) {}
	}
}
 
开发者ID:PoochyEXE,项目名称:nullpomino,代码行数:17,代码来源:WaveEngine.java

示例10: getGainControl

import javax.sound.sampled.Clip; //导入方法依赖的package包/类
private static FloatControl getGainControl(Clip clip) {
    return (FloatControl) (clip.getControl(FloatControl.Type
            .MASTER_GAIN));
}
 
开发者ID:battlecode,项目名称:battlecode-client-2016,代码行数:5,代码来源:GameSoundBank.java


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