@Override public Control getControl (Control.Type control) { return dataLine.getControl(control); }
@Override public Control getControl (Control.Type control) { return dataLine.getControl(control); }
@Override public Control getControl (Control.Type control) { return dataLine.getControl(control); }
@Override public Control getControl (Control.Type control) { return dataLine.getControl(control); }
private void load(File file) { try { audioInputStream = AudioSystem.getAudioInputStream(file); audioFormat = audioInputStream.getFormat(); // mp3 decode if (audioFormat.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) { audioFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, audioFormat.getSampleRate(), 16, audioFormat.getChannels(), audioFormat.getChannels() * 2, audioFormat.getSampleRate(), false); audioInputStream = AudioSystem.getAudioInputStream(audioFormat, audioInputStream); } //output DataLine.Info dataLineInfo = new DataLine.Info( SourceDataLine.class, audioFormat, AudioSystem.NOT_SPECIFIED); sourceDataLine = (SourceDataLine) AudioSystem.getLine(dataLineInfo); sourceDataLine.open(audioFormat); volume = (FloatControl) sourceDataLine.getControl(FloatControl.Type.MASTER_GAIN); sourceDataLine.start(); } catch (Exception e) { log.error("Couldn't load file: " + file + ' ' + e); } }
private void initControls() { if (this.dataLine == null) { return; } // Check if panning is supported: // Create a new pan Control: this.panControl = this.dataLine.isControlSupported(FloatControl.Type.PAN) ? (FloatControl) this.dataLine.getControl(FloatControl.Type.PAN) : null; // Check if changing the volume is supported: // Create a new gain control: this.gainControl = this.dataLine.isControlSupported(FloatControl.Type.MASTER_GAIN) ? (FloatControl) this.dataLine.getControl(FloatControl.Type.MASTER_GAIN) : null; // Store it's initial gain to use as "maximum volume" later: this.setMasterGain(this.actualGain); }
/** * Sets the volume used to play the sound. * * @param volume volume to be set */ private void setVolume( final int volume ) { if ( audioLine.isControlSupported( FloatControl.Type.MASTER_GAIN ) ) { final FloatControl volumeControl = (FloatControl) audioLine.getControl( FloatControl.Type.MASTER_GAIN ); volumeControl.setValue( 20.0f * (float) Math.log10( volume / 100.0 ) ); } }
public void setGain(float gain) { this.gain = gain; if (isGainSupported()) { FloatControl gainControl = (FloatControl) sourceDataLine.getControl(FloatControl.Type.MASTER_GAIN); System.out.println(gainControl); gainControl.setValue(gain); } }
/** * Returns the line's MASTER_GAIN control's value. */ private float getLineGain() { if (m_line.isControlSupported(FloatControl.Type.MASTER_GAIN)) { /* Bound gain value by min and max declared by the control */ final FloatControl gainControl = (FloatControl)m_line.getControl(FloatControl.Type.MASTER_GAIN); return gainControl.getValue(); } else { s_logger.severe("Audio output line doesn not support volume control"); return 0.0f; } }
public void setVolume(float volume) { this.volume = volume; if (isVolumeSupported()) { FloatControl volumeControl = (FloatControl) sourceDataLine.getControl(FloatControl.Type.VOLUME); volumeControl.setValue(volume); } } }
public void mute() { if (audioLine == null) { isMuted = true; } else { //when requesting the same line you sometimes get different features isMuted = true; if (!audioLine.isControlSupported(BooleanControl.Type.MUTE)) return; BooleanControl control = (BooleanControl) audioLine.getControl(BooleanControl.Type.MUTE); control.setValue(true); } }
public void unMute() { if (audioLine == null) { isMuted = false; } else { isMuted = false; if (!audioLine.isControlSupported(BooleanControl.Type.MUTE)) return; BooleanControl control = (BooleanControl) audioLine.getControl(BooleanControl.Type.MUTE); control.setValue(false); } }
// Added two lines. DataLine.Info info = new DataLine.Info( SourceDataLine.class, audioFormat ); SourceDataLine dataLine = (SourceDataLine) AudioSystem.getLine( info ); dataLine.open(); // Adjust the volume on the output line. if( dataLine.isControlSupported( FloatControl.Type.MASTER_GAIN)) { // If inside this if, the Master_Gain must be supported. Yes? FloatControl volume = (FloatControl) dataLine.getControl(FloatControl.Type.MASTER_GAIN); // This line throws an exception. "Master_Gain not supported" volume.setValue( 100.0F ); }
private void setVolumeToAudio(int volume) { if (audio == null) return; if (audio.isControlSupported(FloatControl.Type.MASTER_GAIN)) { FloatControl volumeControl = (FloatControl) audio.getControl(FloatControl.Type.MASTER_GAIN); // Copied from: http://www.javadocexamples.com/java_source/com/limegroup/gnutella/gui/mp3/BasicPlayer.java.html#line.615 double minGainDB = volumeControl.getMinimum(); double ampGainDB = Math.min(.5*volumeControl.getMaximum(), 0) - volumeControl.getMinimum(); double cste = Math.log(10.0)/20; double valueDB = minGainDB + (1/cste)*Math.log(1+(Math.exp(cste*ampGainDB)-1)* (volume / 100f)); volumeControl.setValue((float)valueDB); } }
public void setMinVolume() { if (isVolumeSupported()) { FloatControl volumeControl = (FloatControl) sourceDataLine.getControl(FloatControl.Type.VOLUME); this.volume = volumeControl.getMinimum(); volumeControl.setValue(volume); } }
public void setMute(boolean mute) { if (sourceDataLine.isControlSupported(FloatControl.Type.VOLUME)) { FloatControl volumeControl = (FloatControl) sourceDataLine.getControl(FloatControl.Type.VOLUME); if (mute) { volumeControl.setValue(0f); } else { volumeControl.setValue(volume); } } }
public void setMaxGain() { if (isGainSupported()) { FloatControl gainControl = (FloatControl) sourceDataLine.getControl(FloatControl.Type.MASTER_GAIN); this.gain = gainControl.getMaximum(); gainControl.setValue(gain); } }
public void setMinGain() { if (isGainSupported()) { FloatControl gainControl = (FloatControl) sourceDataLine.getControl(FloatControl.Type.MASTER_GAIN); this.gain = gainControl.getMinimum(); gainControl.setValue(gain); } }
public void setMaxVolume() { if (isVolumeSupported()) { FloatControl volumeControl = (FloatControl) sourceDataLine.getControl(FloatControl.Type.VOLUME); this.volume = volumeControl.getMaximum(); volumeControl.setValue(volume); } }
private void setControlValue(FloatControl.Type type, float value) { FloatControl control = null; try { control = (FloatControl) line.getControl(type); } catch (Exception ex) { // Unsupported control type } if (control != null) { if (line.isActive()) { control.shift(control.getValue(), value, 50); } else { control.setValue(value); } } }