當前位置: 首頁>>代碼示例>>Java>>正文


Java AudioSystem.getMixer方法代碼示例

本文整理匯總了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");
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:25,代碼來源:DataLine_ArrayIndexOutOfBounds.java

示例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");
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:ClipFlushCrash.java

示例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);
			}
		}
	}
}
 
開發者ID:rizsi,項目名稱:rcom,代碼行數:26,代碼來源:JitterExample.java

示例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");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:BothEndiansAndSigns.java

示例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;
}
 
開發者ID:CognitiveModeling,項目名稱:BrainControl,代碼行數:13,代碼來源:Microphone.java

示例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);
//			}
		}
	}
 
開發者ID:rizsi,項目名稱:rcom,代碼行數:30,代碼來源:ResampleExample.java

示例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);
}
 
開發者ID:rizsi,項目名稱:rcom,代碼行數:31,代碼來源:ManualTestEchoCancel2.java

示例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;
    }
}
 
開發者ID:FreeCol,項目名稱:freecol,代碼行數:9,代碼來源:SoundPlayer.java

示例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");
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:29,代碼來源:ClipCloseLoss.java

示例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");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:31,代碼來源:UnexpectedIAE.java

示例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);
	}
 
開發者ID:rizsi,項目名稱:rcom,代碼行數:36,代碼來源:MeasureEchoLatency.java

示例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!");
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:38,代碼來源:DataLineInfoNegBufferSize.java

示例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");
}
 
開發者ID:rizsi,項目名稱:rcom,代碼行數:15,代碼來源:ListAudio.java

示例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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:28,代碼來源:Has16and32KHz.java

示例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");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:34,代碼來源:FrameSizeTest.java


注:本文中的javax.sound.sampled.AudioSystem.getMixer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。