/** Returns Pan value. */ public float getPan() { if (hasPanControl()) { return m_panControl.getValue(); } else { return 0.0F; } }
/** * 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 */ public void setVolume(float gain) { // **** CAMBIADO GAIN POR VOLUME **** if (gain != -1.0f) { if (gain > 1.0f) { gain = 1.0f; } else if (gain < 0.0f) { gain = 0.0f; } } this.gain = gain; if (outputLine == null) { return; } try { FloatControl control = (FloatControl) outputLine.getControl(FloatControl.Type.MASTER_GAIN); if (gain == -1) { control.setValue(0.0f); } 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)); Log.log5( String.format( "Current volume: %.2f, Range: %.2f, Max: %.2f, Min: %.2f", control.getValue(), range, max, min)); } } catch (IllegalArgumentException e) { // gain not supported e.printStackTrace(); } }
/** Returns Gain value. */ public float getGainValue() { if (hasGainControl()) { return m_gainControl.getValue(); } else { return 0.0F; } }
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); }
public void run() { File soundFile = new File(this.filename); if (!soundFile.exists()) { System.err.println("nicht gefunden: " + filename); return; } AudioInputStream audioInputStream = null; try { audioInputStream = AudioSystem.getAudioInputStream(soundFile); } catch (UnsupportedAudioFileException e1) { e1.printStackTrace(); return; } catch (IOException e1) { e1.printStackTrace(); return; } AudioFormat format = audioInputStream.getFormat(); SourceDataLine auline = null; DataLine.Info info = new DataLine.Info(SourceDataLine.class, format); try { auline = (SourceDataLine) AudioSystem.getLine(info); auline.open(format); } catch (LineUnavailableException e) { e.printStackTrace(); return; } catch (Exception e) { e.printStackTrace(); return; } FloatControl rate = (FloatControl) auline.getControl(FloatControl.Type.SAMPLE_RATE); rate.setValue(rate.getValue() * 5f); auline.start(); int nBytesRead = 0; byte[] abData = new byte[EXTERNAL_BUFFER_SIZE]; try { while (nBytesRead != -1) { nBytesRead = audioInputStream.read(abData, 0, abData.length); if (nBytesRead >= 0) auline.write(abData, 0, nBytesRead); } } catch (IOException e) { e.printStackTrace(); return; } finally { auline.drain(); auline.close(); } }
private void fade(FloatControl control, double to) { //noinspection SynchronizationOnLocalVariableOrMethodParameter synchronized (control) { int steps = FADE_DURATION / FADE_STEP_DURATION; to = (to <= 0.0) ? 0.0001 : ((to > 1.0) ? 1.0 : to); float currDB = control.getValue(); float toDB = getDb(to); float diffStep = (toDB - currDB) / (float) steps; for (int i = 0; i < steps; i++) { currDB += diffStep; currDB = (Math.abs(currDB - toDB) < Math.abs(diffStep * 1.5)) ? toDB : currDB; control.setValue(currDB); try { Thread.sleep(FADE_STEP_DURATION); } catch (Exception ignored) { ignored.printStackTrace(); } } } }
public float getVolume() { FloatControl control = (FloatControl) c.getControl(FloatControl.Type.MASTER_GAIN); float val = control.getValue(); return (float) ((val + 40) / 3); }
// Возвращает текущую громкость (число от 0 до 1) public float getVolume() { float v = volumeC.getValue(); float min = volumeC.getMinimum(); float max = volumeC.getMaximum(); return (v - min) / (max - min); }
/** getVol() - returns the current overall volume as a float of between -40.0f and 6.020f */ public float getVol() { return volCtrl.getValue(); }
public int getValue() { return (int) (control.getValue() * getScaleFactor()); }