本文整理汇总了Java中javax.sound.sampled.AudioSystem.getMixer方法的典型用法代码示例。如果您正苦于以下问题:Java AudioSystem.getMixer方法的具体用法?Java AudioSystem.getMixer怎么用?Java AudioSystem.getMixer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.sound.sampled.AudioSystem
的用法示例。
在下文中一共展示了AudioSystem.getMixer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Mixer.Info[] infos = AudioSystem.getMixerInfo();
log("" + infos.length + " mixers detected");
for (int i=0; i<infos.length; i++) {
Mixer mixer = AudioSystem.getMixer(infos[i]);
log("Mixer " + (i+1) + ": " + infos[i]);
try {
mixer.open();
for (Scenario scenario: scenarios) {
testSDL(mixer, scenario);
testTDL(mixer, scenario);
}
mixer.close();
} catch (LineUnavailableException ex) {
log("LineUnavailableException: " + ex);
}
}
if (failed == 0) {
log("PASSED (" + total + " tests)");
} else {
log("FAILED (" + failed + " of " + total + " tests)");
throw new Exception("Test FAILED");
}
}
示例2: main
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
if (isSoundcardInstalled()) {
bais.mark(0);
run(null);
Mixer.Info[] infos = AudioSystem.getMixerInfo();
for (int i = 0; i<infos.length; i++) {
try {
Mixer m = AudioSystem.getMixer(infos[i]);
run(m);
} catch (Exception e) {
}
}
if (success > 0) {
out("No crash -> Test passed");
} else {
System.err.println("Test could not execute: please install an audio device");
}
}
}
示例3: main
import javax.sound.sampled.AudioSystem; //导入方法依赖的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);
}
}
}
}
示例4: main
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
out("4936397: Verify that there'll for a given endianness, there's also the little endian version");
out(" and the same for signed'ness for 8-bit formats");
Mixer.Info[] aInfos = AudioSystem.getMixerInfo();
for (int i = 0; i < aInfos.length; i++) {
try {
Mixer mixer = AudioSystem.getMixer(aInfos[i]);
out("Mixer "+aInfos[i]);
checkLines(mixer, mixer.getSourceLineInfo());
checkLines(mixer, mixer.getTargetLineInfo());
} catch (Exception e) {
out("Unexpected exception when getting a mixer: "+e);
}
}
if (testedFormats == 0) {
out("[No appropriate lines available] - cannot exercise this test.");
} else {
if (failed) {
throw new Exception("Test FAILED!");
}
out("Test passed");
}
}
示例5: enumerateMicrophones
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
public static HashMap<String, Line.Info> enumerateMicrophones() {
HashMap<String, Line.Info> mics = new HashMap<String, Line.Info>();
Mixer.Info[] mixerInfos = AudioSystem.getMixerInfo();
for (Mixer.Info info : mixerInfos) {
Mixer m = AudioSystem.getMixer(info);
Line.Info[] lineInfos = m.getTargetLineInfo();
if (lineInfos.length >= 1 && lineInfos[0].getLineClass().equals(TargetDataLine.class))
mics.put(info.getName(), lineInfos[0]);
}
return mics;
}
示例6: main
import javax.sound.sampled.AudioSystem; //导入方法依赖的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);
// }
}
}
示例7: run
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
private void run() throws Exception
{
byte[] alapzaj=UtilFile.loadFile(new File("/home/rizsi/tmp/video/remote.sw"));
AudioFormat format=getFormat();
final Mixer mixer = AudioSystem.getMixer(null);
m=new Mic(mixer, format, frameSamples);
Play p=new Play(mixer, format, frameSamples);
echo=new SpeexEchoCancel();
echo.setLog(true);
echo.setup(m, p, frameSamples);
echo.start();
p.start();
m.start();
RecordBoth r=new RecordBoth(echo, m);
p.setSample(alapzaj);
try(Scanner br=new Scanner(System.in))
{
System.out.println("Press ENTER to start training noise");
br.nextLine();
p.setSample(alapzaj);
System.out.println("Press ENTER to leave");
br.nextLine();
r.stop();
p.setSample(r.echoCancelled.toByteArray());
UtilFile.saveAsFile(new File("/tmp/rcancelled.sw"), r.echoCancelled.toByteArray());
br.nextLine();
}
System.exit(0);
}
示例8: setMixer
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
private void setMixer(MixerWrapper mw) {
try {
mixer = AudioSystem.getMixer(mw.getMixerInfo());
} catch (Exception e) {
logger.log(Level.WARNING, "Could not set mixer", e);
mixer = null;
}
}
示例9: main
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
if (isSoundcardInstalled()) {
bais.mark(0);
Mixer.Info[] infos = AudioSystem.getMixerInfo();
for (int sleep = 0; sleep < 100; ++sleep) {
run(null, sleep);
for (int i = 0; i < infos.length; i++) {
try {
Mixer m = AudioSystem.getMixer(infos[i]);
run(m, sleep);
} catch (Exception e) {
}
}
}
out("Waiting 1 second to dispose of all threads");
Thread.sleep(1000);
if (getClipThreadCount() > 0) {
out("Unused clip threads exist! Causes test failure");
failed = true;
}
if (failed) throw new Exception("Test FAILED!");
if (success > 0) {
out("Test passed.");
} else {
System.err.println("Test could not execute: please install an audio device");
}
}
}
示例10: main
import javax.sound.sampled.AudioSystem; //导入方法依赖的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");
}
}
示例11: run
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
private void run() throws Exception
{
int frameSize=256;
AudioFormat format=ManualTestEchoCancel.getFormat();
final Mixer mixer = AudioSystem.getMixer(null);
m=new Mic2(mixer, format, ManualTestEchoCancel.frameSamples);
MeasurePower mp=new MeasurePower(frameSize, m);
mp.start();
Play p=new Play2(mixer, format, ManualTestEchoCancel.frameSamples);
p.start();
m.start();
byte[] sample=new byte[320000];
ByteBuffer s=ByteBuffer.wrap(sample);
s.order(ByteOrder.nativeOrder());
for(int i=0;i<500;++i)
{
s.putShort((short)(32000*Math.sin(0.3*i)));
}
try(Scanner br=new Scanner(System.in))
{
System.out.println("Press ENTER to start sample");
br.nextLine();
while(true)
{
Thread.sleep(1000);
p.setSample(sample);
Thread.sleep(1000);
p.setSample(null);
p.setLogged(false);
}
// br.nextLine();
}
// System.exit(0);
}
示例12: main
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
if (isSoundcardInstalled()) {
int res=0;
int count = 0;
Mixer.Info[] infos = AudioSystem.getMixerInfo();
for (int i = -1; i<infos.length; i++) {
try {
Mixer m;
if (i == -1) {
m = null;
} else {
m = AudioSystem.getMixer(infos[i]);
}
int r = run(m, AudioSystem.NOT_SPECIFIED);
// only continue if successful
if (r == 0) {
count++;
r = run(m, -2);
if (r == 1) {
// only fail if IAE was thrown
System.out.println("#FAILED: using -2 for buffer size does not work!");
res = 1;
}
}
} catch (Exception e) {
}
}
if (res!=1) {
System.out.println("Test passed");
} else {
if (count == 0) {
System.err.println("Test could not execute -- no suitable mixers installed. NOT failed");
}
throw new Exception("Test FAILED!");
}
}
}
示例13: commandline
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
public static void commandline(String[] subArgs) {
final Mixer mixer = AudioSystem.getMixer(null);
System.out.println("Listing audio channels...");
for(Info info: mixer.getTargetLineInfo())
{
DataLine.Info di=(DataLine.Info) info;
System.out.println("Line: "+di);
for(AudioFormat f: di.getFormats())
{
System.out.println("Supported format: "+f);
}
}
System.out.println("Listing audio channels DONE");
}
示例14: main
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
boolean res=true;
Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();
System.out.println(mixerInfo.length+" mixers on system.");
if (mixerInfo.length == 0) {
System.out.println("Cannot execute test. Not Failed!");
} else {
for (int i = 0; i < mixerInfo.length; i++) {
Mixer mixer = AudioSystem.getMixer(mixerInfo[i]);
System.out.println();
System.out.println(mixer+":");
showMixerLines(mixer.getSourceLineInfo());
showMixerLines(mixer.getTargetLineInfo());
}
res=ok16 && ok32;
}
if (res) {
System.out.println("Test passed");
} else {
System.out.println("Test failed");
throw new Exception("Test failed");
}
//ystem.exit(res?0:1);
}
示例15: main
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
boolean res=true;
Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();
for (int i = 0; i < mixerInfo.length; i++) {
Mixer mixer = AudioSystem.getMixer(mixerInfo[i]);
System.out.println(mixer);
Line.Info[] lineinfo = mixer.getSourceLineInfo();
for (int j = 0; j < lineinfo.length; j++) {
System.out.println(" " + lineinfo[j]);
try {
AudioFormat[] formats = ((DataLine.Info)lineinfo[j]).getFormats();
for (int k = 0; k < formats.length; k++) {
if ( (formats[k].getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED)
|| formats[k].getEncoding().equals(AudioFormat.Encoding.PCM_UNSIGNED))
&& (formats[k].getFrameSize() != AudioSystem.NOT_SPECIFIED)
&& ((formats[k].getSampleSizeInBits() == 16) || (formats[k].getSampleSizeInBits() == 8))
&& ((((formats[k].getSampleSizeInBits() + 7) / 8) * formats[k].getChannels()) != formats[k].getFrameSize())) {
System.out.println(" # " + formats[k] + ", getFrameSize() wrongly returns"+ formats[k].getFrameSize());
res=false;
}
}
} catch (ClassCastException e) {
}
}
}
if (res) {
System.out.println("Test passed");
} else {
System.out.println("Test failed");
throw new Exception("Test failed");
}
}