本文整理汇总了Java中javax.sound.sampled.FloatControl.getMaximum方法的典型用法代码示例。如果您正苦于以下问题:Java FloatControl.getMaximum方法的具体用法?Java FloatControl.getMaximum怎么用?Java FloatControl.getMaximum使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.sound.sampled.FloatControl
的用法示例。
在下文中一共展示了FloatControl.getMaximum方法的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);
}
示例2: 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;
line.start();
//App.logger.d("prefix + WebPlayer SourceDataLine started!", null);
}
示例3: init
import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
private void init() {
AudioFormat speexFormat = new AudioFormat(16000, 16, 1, true, false);
DataLine.Info sourceLineInfo = new DataLine.Info(SourceDataLine.class, speexFormat, bufferSize);
speexDecoder.init(1, 16000, 1, false);
try {
line = (SourceDataLine) AudioSystem.getLine(sourceLineInfo);
line.open(speexFormat, bufferSize);
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;
volumeControl.setValue((float) minGainDB);
line.start();
} catch (LineUnavailableException e) {
App.logger.w("Failed to create voice player (type: " + type + " id: " + playerId + "):" , e);
if (!exit)
close(false);
}
}
示例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(Utils.clamp(dB, gainControl.getMinimum(), gainControl.getMaximum()));
} else if (clip.isControlSupported(FloatControl.Type.VOLUME)) {
// The docs don't mention what unit "volume" is supposed to be,
// but for PulseAudio it seems to be amplitude
FloatControl volumeControl = (FloatControl) clip.getControl(FloatControl.Type.VOLUME);
float amplitude = (float) Math.sqrt(volume) * volumeControl.getMaximum();
volumeControl.setValue(Utils.clamp(amplitude, volumeControl.getMinimum(), volumeControl.getMaximum()));
}
if (listener != null)
clip.addLineListener(listener);
clip.setFramePosition(0);
clip.start();
}
示例5: setValue
import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
private void setValue(FloatControl.Type type, float v)
{
if (hasControl(type))
{
FloatControl c = (FloatControl) getControl(type);
if (v > c.getMaximum())
v = c.getMaximum();
else if (v < c.getMinimum()) v = c.getMinimum();
c.setValue(v);
}
else
{
Minim.error(type.toString() + " is not supported.");
}
}
示例6: getVolume
import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
final public float getVolume(int intPvolumePercentage) throws Throwable {
if (this.objGclip != null && this.objGclip.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
final FloatControl objLvolumeFloatControl = (FloatControl) this.objGclip.getControl(FloatControl.Type.MASTER_GAIN);
final float fltLrange = (objLvolumeFloatControl.getMaximum() - objLvolumeFloatControl.getMinimum()) * 1.2F;
return Math.min(fltLrange * Math.max(0, intPvolumePercentage) / 100.0F + objLvolumeFloatControl.getMinimum(),
objLvolumeFloatControl.getMaximum());
}
throw new Throwable();
}
示例7: setVolume
import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
@Override
public void setVolume(float volume) {
FloatControl control = (FloatControl)this.controls.get("Master Gain");
float min = control.getMinimum();
float max = control.getMaximum();
float oldVal = control.getValue();
float newVal = volume < min ? min : (volume > max ? max : volume);
control.setValue(newVal);
this.trigger(AudioEvent.Type.VOLUME_CHANGED, oldVal, newVal);
}
示例8: setBalance
import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
@Override
public void setBalance(float balance) {
FloatControl balanceControl = (FloatControl)this.controls.get("Balance");
float max = balanceControl.getMaximum();
float min = balanceControl.getMinimum();
balanceControl.setValue(balance < min ? min : (balance > max ? max : balance));
}
示例9: increaseSound
import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
public static void increaseSound() {
if (isTreadAlive()) {
try {
gain = (FloatControl) radioPLayer.line.getControl(FloatControl.Type.MASTER_GAIN);
if (gain.getValue() < (gain.getMaximum() - 2.0F)) {
gain.setValue(gain.getValue() + 1.0F);
}
} catch (NullPointerException e) {
System.out.println("Sound System was still warming up");
}
}
}
示例10: writeDataToLine
import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
private void writeDataToLine() throws LineUnavailableException {
playing = true;
line = AudioSystem.getSourceDataLine(format);
if (line == null) {
return;
}
line.open();
line.start();
for (int i = 0; i < data.length && playing; i += BUFFER_SIZE) {
if (line.isControlSupported(Type.MASTER_GAIN)) {
final FloatControl gainControl = (FloatControl)line.getControl(Type.MASTER_GAIN);
final float minimum = gainControl.getMinimum();
final float maximum = gainControl.getMaximum();
final float actualGain = Math.max(minimum, Math.min(maximum, gain));
gainControl.setValue(actualGain);
}
if (i + BUFFER_SIZE > data.length) {
i = data.length - BUFFER_SIZE;
}
line.write(data, i, BUFFER_SIZE);
}
line.drain();
}
示例11: setPanning
import javax.sound.sampled.FloatControl; //导入方法依赖的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);
}
}
示例12: rawplay
import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
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();
}
}
示例13: updateVolume
import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
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;
}
示例14: setGain
import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
/**
* 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();
}
}
示例15: playSound
import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
/**
* Starts playing a generated tone in a loop <br>
* <br>
* See also {@link #genTone()}
*/
void playSound() {
try (SourceDataLine line = getSourceDataLine()) {
if (line != null) {
isPlaying.set(true);
line.open(mAudioFormat, generatedSnd[currentTone].length);
// decrease volume
FloatControl control = (FloatControl) line
.getControl(FloatControl.Type.MASTER_GAIN);
// set to 3/5 of maximum dB
float newValue = control.getMaximum()
- (2 *(control.getMaximum() - control.getMinimum()) / 5);
control.setValue(newValue);
line.start();
// loop playing
while (isPlaying.get() && !Thread.currentThread().isInterrupted()) {
line.write(generatedSnd[currentTone], 0,
generatedSnd[currentTone].length);
}
}
} catch (LineUnavailableException e) {
e.printStackTrace();
}
}