本文整理汇总了Java中javax.sound.sampled.Mixer.getLine方法的典型用法代码示例。如果您正苦于以下问题:Java Mixer.getLine方法的具体用法?Java Mixer.getLine怎么用?Java Mixer.getLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.sound.sampled.Mixer
的用法示例。
在下文中一共展示了Mixer.getLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doMixerClip
import javax.sound.sampled.Mixer; //导入方法依赖的package包/类
private static void doMixerClip(Mixer mixer, AudioFormat format) {
if (mixer==null) return;
try {
System.out.println("Clip from mixer "+mixer+":");
System.out.println(" "+mixer.getMixerInfo());
DataLine.Info info = new DataLine.Info(
Clip.class,
format);
if (mixer.isLineSupported(info)) {
Clip clip = (Clip) mixer.getLine(info);
doLine1(clip, format);
} else {
System.out.println(" - Line not supported");
}
} catch (Throwable t) {
System.out.println(" - Caught exception. Not failed.");
System.out.println(" - "+t.toString());
}
}
示例2: doMixerSDL
import javax.sound.sampled.Mixer; //导入方法依赖的package包/类
private static void doMixerSDL(Mixer mixer, AudioFormat format) {
if (mixer==null) return;
try {
System.out.println("SDL from mixer "+mixer+":");
DataLine.Info info = new DataLine.Info(
SourceDataLine.class,
format);
if (mixer.isLineSupported(info)) {
SourceDataLine sdl = (SourceDataLine) mixer.getLine(info);
doLine1(sdl, format);
doLine2(sdl, format);
} else {
System.out.println(" - Line not supported");
}
} catch (Throwable t) {
System.out.println(" - Caught exception. Not failed.");
System.out.println(" - "+t.toString());
}
}
示例3: doMixerTDL
import javax.sound.sampled.Mixer; //导入方法依赖的package包/类
private static void doMixerTDL(Mixer mixer, AudioFormat format) {
if (mixer==null) return;
try {
System.out.println("TDL from mixer "+mixer+":");
DataLine.Info info = new DataLine.Info(
TargetDataLine.class,
format);
if (mixer.isLineSupported(info)) {
TargetDataLine tdl = (TargetDataLine) mixer.getLine(info);
doLine1(tdl, format);
doLine2(tdl, format);
} else {
System.out.println(" - Line not supported");
}
} catch (Throwable t) {
System.out.println(" - Caught exception. Not failed.");
System.out.println(" - "+t.toString());
}
}
示例4: main
import javax.sound.sampled.Mixer; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
AbstractRcomArgs a=new AbstractRcomArgs();
UtilCli.parse(a, args, true);
File folder=new File("/home/rizsi/tmp/video");
byte[] data=UtilFile.loadFile(new File(folder, "remote.sw"));
AudioFormat format=ManualTestEchoCancel.getFormat();
final Mixer mixer = AudioSystem.getMixer(null);
DataLine.Info info2= new DataLine.Info(SourceDataLine.class, format);
SourceDataLine s=(SourceDataLine) mixer.getLine(info2);
s.open(format, framesamples*2);
s.start();
try(LoopInputStream lis=new LoopInputStream(data))
{
try(JitterResampler rs=new JitterResampler(a, 8000, framesamples, 2))
{
new FeedThread(lis, rs).start();
final byte[] buffer=new byte[framesamples*2];;
while(true)
{
rs.readOutput(buffer);
s.write(buffer, 0, buffer.length);
}
}
}
}
示例5: getAudioInfo
import javax.sound.sampled.Mixer; //导入方法依赖的package包/类
void getAudioInfo (){
Mixer.Info[] mixerInfos = AudioSystem.getMixerInfo();
log.info(mixerInfos.length + " mixers");
for ( int i = 0 ; i < mixerInfos.length ; i++ ){
Mixer mixer = AudioSystem.getMixer(mixerInfos[i]);
System.out.println("Mixer " + mixer);
// target data lines
Line.Info[] lineInfos = mixer.getTargetLineInfo();
System.out.println("\t" + lineInfos.length + " lineInfos");
for ( int j = 0 ; j < lineInfos.length ; j++ ){
if ( lineInfos[j] instanceof DataLine.Info ){
AudioFormat[] formats = ( (DataLine.Info)lineInfos[j] ).getFormats();
System.out.println("\t\t\t" + formats.length + " formats");
for ( int k = 0 ; k < formats.length ; k++ ){
System.out.println("\t\tFormat " + formats[k]);
}
}
Line line = null;
try{
line = mixer.getLine(lineInfos[j]);
System.out.println("\tLine " + line);
} catch ( LineUnavailableException e ){
e.printStackTrace();
}
}
}
}
示例6: doMixerClip
import javax.sound.sampled.Mixer; //导入方法依赖的package包/类
private static void doMixerClip(Mixer mixer) throws Exception {
boolean waitedEnough=false;
try {
DataLine.Info info = new DataLine.Info(Clip.class, format);
Clip clip = (Clip) mixer.getLine(info);
clip.open(format, soundData, 0, soundData.length);
// sanity
if (clip.getMicrosecondLength()/1000 < 9900) {
throw new Exception("clip's microsecond length should be at least 9900000, but it is "+clip.getMicrosecondLength());
}
long start = System.currentTimeMillis();
System.out.println(" ---------- start --------");
clip.start();
// give time to actually start it. ALSA implementation needs that...
Thread.sleep(300);
System.out.println("drain ... ");
clip.drain();
long elapsedTime = System.currentTimeMillis() - start;
System.out.println("close ... ");
clip.close();
System.out.println("... done");
System.out.println("Playback duration: "+elapsedTime+" milliseconds.");
waitedEnough = elapsedTime >= ((clip.getMicrosecondLength() / 1000) - TOLERANCE_MS);
} catch (Throwable t) {
System.out.println(" - Caught exception. Not failed.");
System.out.println(" - "+t.toString());
return;
}
if (!waitedEnough) {
throw new Exception("Drain did not wait long enough to play entire clip.");
}
successfulTests++;
}
示例7: doMixerClip
import javax.sound.sampled.Mixer; //导入方法依赖的package包/类
private static boolean doMixerClip(Mixer mixer, AudioFormat format) {
if (mixer==null) return false;
try {
System.out.println("Trying mixer "+mixer+":");
DataLine.Info info = new DataLine.Info(
Clip.class,
format,
(int) samplerate);
Clip clip = (Clip) mixer.getLine(info);
System.out.println(" - got clip: "+clip);
System.out.println(" - open with format "+format);
clip.open(format, buffer, 0, buffer.length);
System.out.println(" - playing...");
clip.start();
System.out.println(" - waiting while it's active...");
while (clip.isActive())
Thread.sleep(100);
System.out.println(" - waiting 100millis");
Thread.sleep(100);
System.out.println(" - drain1");
clip.drain();
System.out.println(" - drain2");
clip.drain();
System.out.println(" - stop");
clip.stop();
System.out.println(" - close");
clip.close();
System.out.println(" - closed");
} catch (Throwable t) {
System.out.println(" - Caught exception. Not failed.");
System.out.println(" - "+t.toString());
return false;
}
return true;
}
示例8: doMixerSDL
import javax.sound.sampled.Mixer; //导入方法依赖的package包/类
private static boolean doMixerSDL(Mixer mixer, AudioFormat format) {
if (mixer==null) return false;
try {
System.out.println("Trying mixer "+mixer+":");
DataLine.Info info = new DataLine.Info(
SourceDataLine.class,
format,
(int) samplerate);
SourceDataLine sdl = (SourceDataLine) mixer.getLine(info);
System.out.println(" - got sdl: "+sdl);
System.out.println(" - open with format "+format);
sdl.open(format);
System.out.println(" - start...");
sdl.start();
System.out.println(" - write...");
sdl.write(buffer, 0, buffer.length);
Thread.sleep(200);
System.out.println(" - drain...");
sdl.drain();
System.out.println(" - stop...");
sdl.stop();
System.out.println(" - close...");
sdl.close();
System.out.println(" - closed");
} catch (Throwable t) {
System.out.println(" - Caught exception. Not failed.");
System.out.println(" - "+t.toString());
return false;
}
return true;
}
示例9: main
import javax.sound.sampled.Mixer; //导入方法依赖的package包/类
public static void main(String argv[]) throws Exception {
boolean success = true;
Mixer.Info [] infos = AudioSystem.getMixerInfo();
for (int i=0; i<infos.length; i++) {
Mixer mixer = AudioSystem.getMixer(infos[i]);
System.out.println("Mixer is: " + mixer);
Line.Info [] target_line_infos = mixer.getTargetLineInfo();
for (int j = 0; j < target_line_infos.length; j++) {
try {
System.out.println("Trying to get:" + target_line_infos[j]);
mixer.getLine(target_line_infos[j]);
} catch (IllegalArgumentException iae) {
System.out.println("Unexpected IllegalArgumentException raised:");
iae.printStackTrace();
success = false;
} catch (LineUnavailableException lue) {
System.out.println("Unexpected LineUnavailableException raised:");
lue.printStackTrace();
success = false;
}
}
}
if (success) {
System.out.println("Test passed");
} else {
throw new Exception("Test FAILED");
}
}
示例10: Mic
import javax.sound.sampled.Mixer; //导入方法依赖的package包/类
public Mic(Mixer mixer, AudioFormat format, int frameSamples) throws LineUnavailableException {
super();
DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
t=(TargetDataLine) mixer.getLine(info);
t.open(format, frameSamples*2);
System.out.println("Bytebuffer t: "+t.getBufferSize());
}
示例11: main
import javax.sound.sampled.Mixer; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
AbstractRcomArgs a=new AbstractRcomArgs();
UtilCli.parse(a, args, true);
File folder=new File("/home/rizsi/tmp/video");
byte[] data=UtilFile.loadFile(new File(folder, "remote.sw"));
AudioFormat format=ManualTestEchoCancel.getFormat();
final Mixer mixer = AudioSystem.getMixer(null);
DataLine.Info info2= new DataLine.Info(SourceDataLine.class, format);
SourceDataLine s=(SourceDataLine) mixer.getLine(info2);
s.open(format, framesamples*2);
s.start();
try(LoopInputStream lis=new LoopInputStream(data))
{
try(SpeexResampler resampler=new SpeexResampler(a, framesamples, new ResampledReceiver(s)))
{
final byte[] buffer=new byte[framesamples*2];;
while(true)
{
UtilStream.readFully(buffer, lis, buffer.length);
feed(resampler, buffer);
}
}
// byte[] buffer=new byte[framesamples*2];
// while(true)
// {
// UtilStream.readFully(buffer, resampled, buffer.length);
// }
}
}
示例12: play
import javax.sound.sampled.Mixer; //导入方法依赖的package包/类
public static void play(Mixer mixer) {
int res = 0;
try {
println("Getting clip from mixer...");
source = (Clip) mixer.getLine(info);
println("Opening clip...");
source.open(audioFormat, audioData, 0, audioData.length);
println("Starting clip...");
source.loop(Clip.LOOP_CONTINUOUSLY);
println("Now open your ears:");
println("- if you hear a sine wave playing,");
println(" listen carefully if you can hear clicks.");
println(" If no, the bug is fixed.");
println("- if you don't hear anything, it's possible");
println(" that this mixer is not connected to an ");
println(" amplifier, or that its volume is set to 0");
key();
} catch (IllegalArgumentException iae) {
println("IllegalArgumentException: "+iae.getMessage());
println("Sound device cannot handle this audio format.");
println("ERROR: Test environment not correctly set up.");
if (source!=null) {
source.close();
source = null;
}
return;
} catch (LineUnavailableException lue) {
println("LineUnavailableException: "+lue.getMessage());
println("This is normal for some mixers.");
} catch (Exception e) {
println("Unexpected Exception: "+e.toString());
}
if (source != null) {
println("Stopping...");
source.stop();
println("Closing...");
source.close();
println("Closed.");
source = null;
}
}
示例13: main
import javax.sound.sampled.Mixer; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Mixer.Info[] mixers = AudioSystem.getMixerInfo();
int succMixers = 0;
println("Using formats: ");
for (int i = 0 ; i<formats.length; i++) {
println(""+(i+1)+". "+formats[i]);
}
for (int i=0; i<mixers.length; i++) {
boolean succ = false;
try {
Mixer mixer = AudioSystem.getMixer(mixers[i]);
println("Mixer "+mixer.getMixerInfo()+":");
if (mixer.isLineSupported(clipInfo)) {
println("Getting clip from mixer...");
Clip clip = (Clip) mixer.getLine(clipInfo);
succ = true;
test(clip);
}
if (mixer.isLineSupported(sdlInfo)) {
println("Getting source data line from mixer...");
SourceDataLine sdl = (SourceDataLine) mixer.getLine(sdlInfo);
succ = true;
test(sdl);
}
if (mixer.isLineSupported(tdlInfo)) {
println("Getting target data line from mixer...");
TargetDataLine tdl = (TargetDataLine) mixer.getLine(tdlInfo);
succ = true;
test(tdl);
}
} catch (Exception e) {
e.printStackTrace();
}
if (succ) {
succMixers++;
}
}
if (succMixers == 0) {
println("No mixers available! ");
println("Cannot run test. NOT FAILED");
}
else if (failed) {
throw new Exception("Test FAILED");
}
println("Test passed.");
}
示例14: play
import javax.sound.sampled.Mixer; //导入方法依赖的package包/类
public static void play(Mixer mixer) {
int res = 0;
try {
println("Getting SDL from mixer...");
source = (SourceDataLine) mixer.getLine(info);
println("Opening SDL...");
source.open(audioFormat);
println("Writing data to SDL...");
source.write(audioData, 0, audioData.length);
println("Starting SDL...");
source.start();
println("Now open your ears:");
println("You should have heard a short tone,");
println("followed by silence (no repeating tones).");
key();
source.write(audioData, 0, audioData.length);
println("Now you should have heard another short tone.");
println("If you did not hear a second tone, or more than 2 tones,");
println("the test is FAILED.");
println("otherwise, if you heard a total of 2 tones, the bug is fixed.");
key();
} catch (IllegalArgumentException iae) {
println("IllegalArgumentException: "+iae.getMessage());
println("Sound device cannot handle this audio format.");
println("ERROR: Test environment not correctly set up.");
if (source!=null) {
source.close();
source = null;
}
return;
} catch (LineUnavailableException lue) {
println("LineUnavailableException: "+lue.getMessage());
println("This is normal for some mixers.");
} catch (Exception e) {
println("Unexpected Exception: "+e.toString());
}
if (source != null) {
println("Stopping...");
source.stop();
println("Closing...");
source.close();
println("Closed.");
source = null;
}
}
示例15: play
import javax.sound.sampled.Mixer; //导入方法依赖的package包/类
public static void play(Mixer mixer) {
int res = 0;
try {
println("Getting SDL from mixer...");
source = (SourceDataLine) mixer.getLine(info);
println("Opening SDL...");
source.open(audioFormat);
println("Writing data to SDL...");
source.write(audioData, 0, audioData.length);
println("Starting SDL...");
source.start();
println("Now open your ears:");
println("- you should have heard a short tone,");
println(" followed by silence.");
println("- if after a while you hear repeated tones,");
println(" the bug is NOT fixed.");
println("- if the program remains silent after the ");
println(" initial tone, the bug is fixed.");
key();
} catch (IllegalArgumentException iae) {
println("IllegalArgumentException: "+iae.getMessage());
println("Sound device cannot handle this audio format.");
println("ERROR: Test environment not correctly set up.");
if (source!=null) {
source.close();
source = null;
}
return;
} catch (LineUnavailableException lue) {
println("LineUnavailableException: "+lue.getMessage());
println("This is normal for some mixers.");
} catch (Exception e) {
println("Unexpected Exception: "+e.toString());
}
if (source != null) {
println("Stopping...");
source.stop();
println("Closing...");
source.close();
println("Closed.");
source = null;
}
}