當前位置: 首頁>>代碼示例>>Java>>正文


Java FloatControl類代碼示例

本文整理匯總了Java中javax.sound.sampled.FloatControl的典型用法代碼示例。如果您正苦於以下問題:Java FloatControl類的具體用法?Java FloatControl怎麽用?Java FloatControl使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


FloatControl類屬於javax.sound.sampled包,在下文中一共展示了FloatControl類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: init

import javax.sound.sampled.FloatControl; //導入依賴的package包/類
private void init(AudioFormat baseFormat) throws LineUnavailableException {

		decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(), 16, baseFormat.getChannels(),
				baseFormat.getChannels() * 2, baseFormat.getSampleRate(), false);
		DataLine.Info info = new DataLine.Info(SourceDataLine.class, decodedFormat);
		line = (SourceDataLine) AudioSystem.getLine(info);
		line.open(decodedFormat);

		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;

		//for stations we want to set the initial volume to 0
		volumeControl.setValue((float) minGainDB);
		
		line.start();

		//App.logger.d("prefix + WebPlayer SourceDataLine started!", null);
	}
 
開發者ID:WegFetZ,項目名稱:SoundCenterClient,代碼行數:21,代碼來源:StationPlayer.java

示例2: setGain

import javax.sound.sampled.FloatControl; //導入依賴的package包/類
/**
 * Sets Gain value. Line should be opened before calling this method. Linear scale 0.0 <--> 1.0 Threshold Coef. : 1/2 to avoid saturation.
 * 
 * @param fGain
 */
public void setGain(float fGain) {
	
	// if (line != null)
	// System.out.println(((FloatControl)
	// line.getControl(FloatControl.Type.MASTER_GAIN)).getValue())
	
	// Set the value
	gain = fGain;
	
	// Better type
	if (line != null && line.isControlSupported(FloatControl.Type.MASTER_GAIN))
		( (FloatControl) line.getControl(FloatControl.Type.MASTER_GAIN) ).setValue((float) ( 20 * Math.log10(fGain <= 0.0 ? 0.0000 : fGain) ));
	// OR (Math.log(fGain == 0.0 ? 0.0000 : fGain) / Math.log(10.0))
	
	// if (line != null)
	// System.out.println(((FloatControl)
	// line.getControl(FloatControl.Type.MASTER_GAIN)).getValue())
}
 
開發者ID:goxr3plus,項目名稱:Java-Google-Speech-Recognizer,代碼行數:24,代碼來源:AudioPlayer.java

示例3: loadClip

import javax.sound.sampled.FloatControl; //導入依賴的package包/類
private void loadClip() {
	try {
		clip = AudioSystem.getClip();
		
		InputStream in = getClass().getClassLoader().getResourceAsStream(filePath);
		BufferedInputStream bufferedIn = new BufferedInputStream(in);
		AudioInputStream audioIn = AudioSystem.getAudioInputStream(bufferedIn);
		
		clip.open(audioIn);
		
		
		volume = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
	} catch (LineUnavailableException | UnsupportedAudioFileException | IOException e) {
		e.printStackTrace();
		System.exit(-1);
	}
}
 
開發者ID:ProjectK47,項目名稱:Mafia,代碼行數:18,代碼來源:AudioClip.java

示例4: 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

示例5: mute

import javax.sound.sampled.FloatControl; //導入依賴的package包/類
/**
* Mute the Clip (because destroying it, won't stop it)
*/
public void mute() {
	try {
		Clip c = getClip();
		if (c == null) {
			return;
		}
		float val = (float) (Math.log(Float.MIN_VALUE) / Math.log(10.0) * 20.0);
		if (val < -80.0f) {
			val = -80.0f;
		}
		((FloatControl) c.getControl(FloatControl.Type.MASTER_GAIN)).setValue(val);
	} catch (IllegalArgumentException ignored) {
	} catch (LineUnavailableException e) {
		e.printStackTrace();
	}
}
 
開發者ID:yugecin,項目名稱:opsu-dance,代碼行數:20,代碼來源:MultiClip.java

示例6: 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

示例7: PreloadedPlayback

import javax.sound.sampled.FloatControl; //導入依賴的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

示例8: StreamingPlayback

import javax.sound.sampled.FloatControl; //導入依賴的package包/類
/**
 * Creates a new {@code StreamingPlayback}. StreamingPlayback objects will
 * always be created by their associated StreamingAudio object.
 *
 * @param audio
 *            The {@code Audio} that created this {@code StreamingPlayback}.
 * @param audioInStream
 *            The {@code AudioInputStream} used by this
 *            {@code StreamingPlayback}.
 * @param instanceID
 *            The {@code instanceID} of this {@code StreamingPlayback}.
 */
protected StreamingPlayback(Audio audio, AudioInputStream audioInStream,
		long instanceID) {

	super(audio, instanceID);
	this.audioInStream = audioInStream;

	AudioFormat audioFormat = audioInStream.getFormat();
	DataLine.Info info = new DataLine.Info(SourceDataLine.class,
			audioFormat);
	try {
		line = (SourceDataLine) AudioSystem.getLine(info);
		if (line != null) {
			line.open(audioFormat);
		}
		if (line.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
			volCtrl = (FloatControl) line
					.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();
	}
}
 
開發者ID:cmholton,項目名稱:QwickSound,代碼行數:38,代碼來源:StreamingPlayback.java

示例9: 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

示例10: SoundClip

import javax.sound.sampled.FloatControl; //導入依賴的package包/類
public SoundClip(String path) {
	try {
		InputStream audioSrc = getClass().getResourceAsStream(path);
		InputStream bufferedIn = new BufferedInputStream(audioSrc);
		AudioInputStream ais = AudioSystem.getAudioInputStream(bufferedIn);
		AudioFormat baseFormat = ais.getFormat();
		AudioFormat decodeFormat = new AudioFormat(
				AudioFormat.Encoding.PCM_SIGNED,
				baseFormat.getSampleRate(), 16, baseFormat.getChannels(),
				baseFormat.getChannels() * 2, baseFormat.getSampleRate(),
				false);
		AudioInputStream dais = AudioSystem.getAudioInputStream(decodeFormat, ais);
		
		clip = AudioSystem.getClip();
		clip.open(dais);
		
		gainControl = (FloatControl)clip.getControl(FloatControl.Type.MASTER_GAIN);
		
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:dawings1,項目名稱:Side-Quest-City,代碼行數:23,代碼來源:SoundClip.java

示例11: setPlayer

import javax.sound.sampled.FloatControl; //導入依賴的package包/類
public void setPlayer(Wavefile af) throws Exception{
	clip = af.getClip();
       clip.open();
       fullLength = clip.getFrameLength();
       endPoint = fullLength;
       gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
       playing = false;
       clip.addLineListener(new LineListener(){
		@Override
		public void update(LineEvent arg0) {
			while(playing){
				int tempframe = clip.getFramePosition();
				MakamBoxAnalysis.positionSlide.setValue(tempframe);
				if (stopbutton!=null&&tempframe == fullLength){
					stopbutton.doClick();
				} else if(stopbutton!=null && tempframe>=endPoint){
					playAgain();
				} else if (tempframe == fullLength){
					stop();
				}
			}
		}
       });
}
 
開發者ID:miracatici,項目名稱:MakamBox,代碼行數:25,代碼來源:Player.java

示例12: 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

示例13: VNSound

import javax.sound.sampled.FloatControl; //導入依賴的package包/類
/**
 * Constructor that starts off the VNSound tool with a sound at a certain volume. Will not loop.
 * 
 * @param file - the file path and name of the audio to play
 * @param volume - volume to play the file at
 */
public VNSound(File file, float volume) {
	try {
           audio = AudioSystem.getAudioInputStream(file); 
           clip = AudioSystem.getClip();
           clip.open(audio);
           volumeControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
           setVolume(volume);
           clip.start();
       }
       catch(UnsupportedAudioFileException uae) {
           System.out.println(uae);
       }
       catch(IOException ioe) {
           System.out.println(ioe);
       }
       catch(LineUnavailableException lua) {
           System.out.println(lua);
       }
}
 
開發者ID:BradleyCai,項目名稱:VN-RW,代碼行數:26,代碼來源:VNSound.java

示例14: open

import javax.sound.sampled.FloatControl; //導入依賴的package包/類
/**
 * Opens a new sound and replaces the old one. If object is set to loop the sound (isLoop = true) then it will loop
 * 
 * @param file - the file path and name of the audio to play
 */
public void open(File file) {
	try {
		clip.stop();
           clip.close();
           audio = AudioSystem.getAudioInputStream(file);
           clip.open(audio);
		volumeControl = (FloatControl)clip.getControl(FloatControl.Type.MASTER_GAIN);
           clip.start();
           if(isLoop)
           	clip.loop(Clip.LOOP_CONTINUOUSLY);
           else
           	clip.loop(0);
       }
       catch(UnsupportedAudioFileException uae) {
           System.out.println(uae);
       }
       catch(IOException ioe) {
           System.out.println(ioe);
           System.out.println(file);
       }
       catch(LineUnavailableException lua) {
           System.out.println(lua);
       }
}
 
開發者ID:BradleyCai,項目名稱:VN-RW,代碼行數:30,代碼來源:VNSound.java

示例15: 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


注:本文中的javax.sound.sampled.FloatControl類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。