Java Code Examples for javax.sound.sampled.FloatControl#getMinimum()
The following examples show how to use
javax.sound.sampled.FloatControl#getMinimum() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VoicePlay.java From oim-fx with MIT License | 6 votes |
public void playVoice(byte[] bytes, float value) { if (null != playLine) { FloatControl control = (FloatControl) playLine.getControl(FloatControl.Type.MASTER_GAIN); float size = 0; float minimum = control.getMinimum(); float maximum = control.getMaximum(); float all = maximum - minimum; if (value <= 0) { size = minimum; } else if (value >= 100) { size = maximum; } else { float i = all / 100F; size = (i * value) + minimum; } control.setValue(size);// newVal - the value of volume slider playLine.write(bytes, 0, bytes.length); } }
Example 2
Source File: DefaultSoundEffect.java From petscii-bbs with Mozilla Public License 2.0 | 5 votes |
/** * 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); }
Example 3
Source File: ClipSFXModule.java From mochadoom with GNU General Public License v3.0 | 5 votes |
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); } }
Example 4
Source File: LWaveSound.java From RipplePower with Apache License 2.0 | 5 votes |
private void rawplay(AudioFormat trgFormat, AudioInputStream ain, float volume) throws IOException, LineUnavailableException { byte[] data = new byte[8192]; try { clip = getLine(ain, trgFormat); if (clip == null) { return; } Control.Type vol1 = FloatControl.Type.VOLUME, vol2 = FloatControl.Type.MASTER_GAIN; FloatControl c = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); float min = c.getMinimum(); float v = volume * (c.getMaximum() - min) / 100f + min; if (this.clip.isControlSupported(vol1)) { FloatControl volumeControl = (FloatControl) this.clip.getControl(vol1); volumeControl.setValue(v); } else if (this.clip.isControlSupported(vol2)) { FloatControl gainControl = (FloatControl) this.clip.getControl(vol2); gainControl.setValue(v); } clip.start(); int nBytesRead = 0; while (isRunning && (nBytesRead != -1)) { nBytesRead = ain.read(data, 0, data.length); if (nBytesRead != -1) { clip.write(data, 0, nBytesRead); } } } finally { clip.drain(); clip.stop(); clip.close(); ain.close(); } }
Example 5
Source File: JoggStreamer.java From RipplePower with Apache License 2.0 | 5 votes |
public void updateVolume(int percent) { if (out != null && out.isOpen()) { try { FloatControl c = (FloatControl) out.getControl(FloatControl.Type.MASTER_GAIN); float min = c.getMinimum(); float v = percent * (c.getMaximum() - min) / 100f + min; c.setValue(v); } catch (IllegalArgumentException e) { } } volume = percent; }
Example 6
Source File: OggClip.java From desktopclient-java with GNU General Public License v3.0 | 5 votes |
/** * Attempt to set the global gain (volume ish) for the play back. If the * control is not supported this method has no effect. 1.0 will set maximum * gain, 0.0 minimum gain * * @param gain The gain value */ private void setGain(float gain) { if (gain != -1) { if ((gain < 0) || (gain > 1)) { throw new IllegalArgumentException("Volume must be between 0.0 and 1.0"); } } this.gain = gain; if (outputLine == null) { return; } try { FloatControl control = (FloatControl) outputLine.getControl(FloatControl.Type.MASTER_GAIN); if (gain == -1) { control.setValue(0); } else { float max = control.getMaximum(); float min = control.getMinimum(); // negative values all seem to be zero? float range = max - min; control.setValue(min + (range * gain)); } } catch (IllegalArgumentException e) { // gain not supported e.printStackTrace(); } }
Example 7
Source File: JavaMixer.java From Spark with Apache License 2.0 | 5 votes |
public FloatControlBoundedRangeModel(FloatControl control) { this.control = control; float range = 100; float steps = range / 100; factor = range / steps; int min = (int) (control.getMinimum() * factor); int max = (int) (control.getMaximum() * factor); int value = (int) (control.getValue() * factor); setRangeProperties(value, 0, min, max, false); }