private Gain() {
super(FloatControl.Type.MASTER_GAIN,
Toolkit.linearToDB(0.0f),
Toolkit.linearToDB(2.0f),
Math.abs(Toolkit.linearToDB(1.0f)-Toolkit.linearToDB(0.0f))/128.0f,
-1,
0.0f,
"dB", "Minimum", "", "Maximum");
}
java类javax.sound.sampled.FloatControl的实例源码
DirectAudioDevice.java 文件源码
项目:openjdk-jdk10
阅读 27
收藏 0
点赞 0
评论 0
ClipOpenBug.java 文件源码
项目:openjdk-jdk10
阅读 20
收藏 0
点赞 0
评论 0
public static void main(String args[]) throws Exception {
boolean res = true;
try {
AudioInputStream ais = new AudioInputStream(
new ByteArrayInputStream(new byte[2000]),
new AudioFormat(8000.0f, 8, 1, false, false), 2000); //
AudioFormat format = ais.getFormat();
DataLine.Info info = new DataLine.Info(Clip.class, format,
((int) ais.getFrameLength()
* format
.getFrameSize()));
Clip clip = (Clip) AudioSystem.getLine(info);
clip.open();
FloatControl rateControl = (FloatControl) clip.getControl(
FloatControl.Type.SAMPLE_RATE);
int c = 0;
while (c++ < 10) {
clip.stop();
clip.setFramePosition(0);
clip.start();
for (float frq = 22000; frq < 44100; frq = frq + 100) {
try {
Thread.currentThread().sleep(20);
} catch (Exception e) {
break;
}
rateControl.setValue(frq);
}
}
} catch (Exception ex) {
ex.printStackTrace();
res = ex.getMessage().indexOf(
"This method should not have been invoked!") < 0;
}
if (res) {
System.out.println("Test passed");
} else {
System.out.println("Test failed");
throw new Exception("Test failed");
}
}
AbstractAudio.java 文件源码
项目:SimpleAudio
阅读 22
收藏 0
点赞 0
评论 0
@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);
}
AbstractAudio.java 文件源码
项目:SimpleAudio
阅读 23
收藏 0
点赞 0
评论 0
@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));
}
ApplicationMusicPlayer.java 文件源码
项目:Device-Mod-Apps
阅读 17
收藏 0
点赞 0
评论 0
public void play() {
if (clip != null) {
if (progress != null) {
progress.setMax((int) clip.getMicrosecondLength());
if (progressUpdateThread == null) {
progressUpdateThread = new Thread("Progressbar Update Thread") {
@Override
public void run() {
while (!Thread.interrupted()) {
progress.setProgress((int) clip.getMicrosecondPosition()); // /1000000
}
}
};
progressUpdateThread.start();
}
}
float volume = Minecraft.getMinecraft().gameSettings.getSoundLevel(SoundCategory.RECORDS);
FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
gainControl.setValue(20f * (float) Math.log10(volume));
Minecraft.getMinecraft().getSoundHandler().stopSounds();
if (isAlive()) {
clip.start();
} else {
start();
}
} else {
Minecraft mc = Minecraft.getMinecraft();
mc.getSoundHandler().stopSounds();
mc.getSoundHandler().playSound(listedSong.ps);
start();
}
}
StreamPlayer.java 文件源码
项目:java-stream-player
阅读 24
收藏 0
点赞 0
评论 0
/**
* Sets Pan value. Line should be opened before calling this method. Linear scale : -1.0 ... +1.0
*
* @param fPan
* the new pan
*/
public void setPan(double fPan) {
if (!hasControl(FloatControl.Type.PAN, panControl) || fPan < -1.0 || fPan > 1.0)
return;
logger.info(() -> "Pan : " + fPan);
panControl.setValue((float) fPan);
generateEvent(Status.PAN, getEncodedStreamPosition(), null);
}
StreamPlayer.java 文件源码
项目:java-stream-player
阅读 23
收藏 0
点赞 0
评论 0
/**
* Represents a control for the relative balance of a stereo signal between two stereo speakers. The valid range of values is -1.0 (left channel
* only) to 1.0 (right channel only). The default is 0.0 (centered).
*
* @param fBalance
* the new balance
*/
public void setBalance(float fBalance) {
if (hasControl(FloatControl.Type.BALANCE, balanceControl) && fBalance >= -1.0 && fBalance <= 1.0)
balanceControl.setValue(fBalance);
else
try {
throw new StreamPlayerException(StreamPlayerException.PlayerException.BALANCE_CONTROL_NOT_SUPPORTED);
} catch (StreamPlayerException ex) {
logger.log(Level.WARNING, ex.getMessage(), ex);
}
}
Sound.java 文件源码
项目:group-10
阅读 30
收藏 0
点赞 0
评论 0
public Sound(String dir) {
try {
URL url = getClass().getResource(dir);
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(url);
clip = AudioSystem.getClip();
clip.open(audioInputStream);
gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
} catch (Exception e) {
}
}
Sound.java 文件源码
项目:group-10
阅读 32
收藏 0
点赞 0
评论 0
public Sound(String dir) {
try {
URL url = getClass().getResource(dir);
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(url);
clip = AudioSystem.getClip();
clip.open(audioInputStream);
gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
} catch (Exception e) {
}
}
AudioPlayer.java 文件源码
项目:subsonic
阅读 28
收藏 0
点赞 0
评论 0
public AudioPlayer(InputStream in, Listener listener) throws Exception {
this.in = in;
this.listener = listener;
AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 44100.0F, 16, 2, 4, 44100.0F, true);
line = AudioSystem.getSourceDataLine(format);
line.open(format);
LOG.debug("Opened line " + line);
if (line.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
gainControl = (FloatControl) line.getControl(FloatControl.Type.MASTER_GAIN);
setGain(DEFAULT_GAIN);
}
new AudioDataWriter();
}