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


Java AudioSystem.getSourceDataLine方法代碼示例

本文整理匯總了Java中javax.sound.sampled.AudioSystem.getSourceDataLine方法的典型用法代碼示例。如果您正苦於以下問題:Java AudioSystem.getSourceDataLine方法的具體用法?Java AudioSystem.getSourceDataLine怎麽用?Java AudioSystem.getSourceDataLine使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.sound.sampled.AudioSystem的用法示例。


在下文中一共展示了AudioSystem.getSourceDataLine方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: restartSDL

import javax.sound.sampled.AudioSystem; //導入方法依賴的package包/類
public void restartSDL(){
	AudioFormat form = new AudioFormat(sys.getSampleRate(),16,2,true,false);

	bufptr=0;
	audioints = new int[(int)((sys.getSampleRate()/1000.0)*sys.getBufferSize())*2];
	if(scope!=null)
		scope.setAudio(audioints);
	audiobuffer = new byte[audioints.length*2];
	try {
		if(sdl!=null)
			sdl.close();
		sdl = AudioSystem.getSourceDataLine(form);
		sdl.open(form,audiobuffer.length*3);
		sdl.start();
	} catch (LineUnavailableException e) {
		e.printStackTrace();
	}
	
}
 
開發者ID:QuantumSoundings,項目名稱:BassNES,代碼行數:20,代碼來源:AudioInterface.java

示例2: start

import javax.sound.sampled.AudioSystem; //導入方法依賴的package包/類
@Override
public void start() {
    if (line != null) {
        LOG.debug("Sound already started");
        return;
    }
    LOG.debug("Start sound");
    try {
        line = AudioSystem.getSourceDataLine(FORMAT);
        line.open(FORMAT, BUFFER_SIZE);
    } catch (LineUnavailableException e) {
        throw new RuntimeException(e);
    }
    line.start();
    buffer = new byte[line.getBufferSize()];
    divider = (int) (Gameboy.TICKS_PER_SEC / FORMAT.getSampleRate());
}
 
開發者ID:trekawek,項目名稱:coffee-gb,代碼行數:18,代碼來源:AudioSystemSoundOutput.java

示例3: playGradient

import javax.sound.sampled.AudioSystem; //導入方法依賴的package包/類
public static void playGradient(double fstart,double fend,double duration,double volume,byte fadeend,byte wave) {
	byte[] freqdata = new byte[(int)(duration * SAMPLE_RATE)];
	
	// Generate the sound
	for(int i = 0; i < freqdata.length; i++) {
		freqdata[i] = (byte)generateValue(i, duration, fstart + (fend-fstart) * (i/(double)freqdata.length), volume, fadeend, wave);
	}
		
	// Play it
	try {
		final AudioFormat af = new AudioFormat(SAMPLE_RATE, 8, 1, true, true);
		SourceDataLine line = AudioSystem.getSourceDataLine(af);
		line.open(af, SAMPLE_RATE);
		line.start();
		line.write(freqdata, 0, freqdata.length);
	    line.drain();
	    line.close();
	}catch(LineUnavailableException e) {
		e.printStackTrace();
	}
}
 
開發者ID:vanyle,項目名稱:Explorium,代碼行數:22,代碼來源:SoundGenerator.java

示例4: playSound

import javax.sound.sampled.AudioSystem; //導入方法依賴的package包/類
/**
 * Play a sound at a given frequency freq during duration (in seconds) with volume as strenght
 * <br/><br/>
 * <code>SoundGenerator.playSound(440.0,1.0,0.5,SoundGenerator.FADE_LINEAR,SoundGenerator.WAVE_SIN);</code><br/>
 * Available fades : FADE_NONE, FADE_LINEAR, FADE_QUADRATIC<br/>
 * Available waves : WAVE_SIN, WAVE_SQUARE, WAVE_TRIANGLE, WAVE_SAWTOOTH<br/>
 */
public static void playSound(double freq,double duration,double volume,byte fade,byte wave){
	
	double[] soundData = generateSoundData(freq,duration,volume,fade,wave);
	byte[] freqdata = new byte[soundData.length];
	
	for(int i = 0;i < soundData.length;i++) {
		freqdata[i] = (byte)soundData[i];
	}
		
	// Play it
	try {
		final AudioFormat af = new AudioFormat(SAMPLE_RATE, 8, 1, true, true);
		SourceDataLine line = AudioSystem.getSourceDataLine(af);
		line.open(af, SAMPLE_RATE);
		line.start();
		line.write(freqdata, 0, freqdata.length);
	    line.drain();
	    line.close();
	}catch(LineUnavailableException e) {
		e.printStackTrace();
	}
}
 
開發者ID:vanyle,項目名稱:Explorium,代碼行數:30,代碼來源:SoundGenerator.java

示例5: isSoundcardInstalled

import javax.sound.sampled.AudioSystem; //導入方法依賴的package包/類
/**
 * Returns true if at least one soundcard is correctly installed
 * on the system.
 */
public static boolean isSoundcardInstalled() {
    boolean result = false;
    try {
        Mixer.Info[] mixers = AudioSystem.getMixerInfo();
        if (mixers.length > 0) {
            result = AudioSystem.getSourceDataLine(null) != null;
        }
    } catch (Exception e) {
        System.err.println("Exception occured: "+e);
    }
    if (!result) {
        System.err.println("Soundcard does not exist or sound drivers not installed!");
        System.err.println("This test requires sound drivers for execution.");
    }
    return result;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:ExtraCharInSoundbank.java

示例6: isSoundcardInstalled

import javax.sound.sampled.AudioSystem; //導入方法依賴的package包/類
/**
 * Returns true if at least one soundcard is correctly installed
 * on the system.
 */
public static boolean isSoundcardInstalled() {
    boolean result = false;
    try {
        Mixer.Info[] mixers = AudioSystem.getMixerInfo();
        if (mixers.length > 0) {
            result = AudioSystem.getSourceDataLine(null) != null;
        }
    } catch (Exception e) {
        System.err.println("Exception occured: " + e);
    }
    if (!result) {
        System.err.println(
                "Soundcard does not exist or sound drivers not installed!");
        System.err.println(
                "This test requires sound drivers for execution.");
    }
    return result;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:FloatControlBug.java

示例7: isSoundcardInstalled

import javax.sound.sampled.AudioSystem; //導入方法依賴的package包/類
/**
* Returns true if at least one soundcard is correctly installed
* on the system.
*/
public static boolean isSoundcardInstalled() {
    boolean result = false;
    try {
        Mixer.Info[] mixers = AudioSystem.getMixerInfo();
        if (mixers.length > 0) {
            result = AudioSystem.getSourceDataLine(null) != null;
        }
    } catch (Exception e) {
        System.err.println("Exception occured: "+e);
    }
    if (!result) {
        System.err.println("Soundcard does not exist or sound drivers not installed!");
        System.err.println("This test requires sound drivers for execution.");
    }
    return result;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:ClipCloseLoss.java

示例8: AudioPlayer

import javax.sound.sampled.AudioSystem; //導入方法依賴的package包/類
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();
}
 
開發者ID:airsonic,項目名稱:airsonic,代碼行數:16,代碼來源:AudioPlayer.java

示例9: playSounds

import javax.sound.sampled.AudioSystem; //導入方法依賴的package包/類
/**
 * Same as playSound but plays several frequences at the same time<br/>
 * <code>
 * double[] freqs = {440.0,440*1.5}; <br/>
 * SoundGenerator.playSound(freqs,1.0,0.5,SoundGenerator.FADE_LINEAR,SoundGenerator.WAVE_SIN);
 * </code>
 * 
 */
public static void playSounds(double[] freqs,double duration,double volume,byte fade,byte wave) {
	if(freqs.length == 0) {
		System.err.println("No frequences to play !");
		return;
	}
	volume = volume / freqs.length; // ease volume to avoid overflow
	
	double[][] soundData = new double[freqs.length][];
	
	for(int i = 0;i < soundData.length;i++) {
		soundData[i] = generateSoundData(freqs[i],duration,volume,fade,wave);
	}
	byte[] freqdata = new byte[soundData[0].length];
	
	for(int i = 0;i < soundData[0].length;i++) {
		for(int j = 0;j < soundData.length;j++) {
			freqdata[i] += (byte)(soundData[j][i]);
		}
	}
		
	// Play it
	try {
		final AudioFormat af = new AudioFormat(SAMPLE_RATE, 8, 1, true, true);
		SourceDataLine line = AudioSystem.getSourceDataLine(af);
		line.open(af, SAMPLE_RATE);
		line.start();
		line.write(freqdata, 0, freqdata.length);
	    line.drain();
	    line.close();
	}catch(LineUnavailableException e) {
		e.printStackTrace();
	}
}
 
開發者ID:vanyle,項目名稱:Explorium,代碼行數:42,代碼來源:SoundGenerator.java

示例10: main

import javax.sound.sampled.AudioSystem; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    boolean failed = false;
    try {
        AudioFormat format = new AudioFormat(44100.0f, 16, 2, true, false);
        SourceDataLine sdl = AudioSystem.getSourceDataLine(format);
        try {
            sdl.open(format);
            sdl.start();
            sdl.write(new byte[16384], 0, 16384);
            Thread.sleep(1000);
            int intPos = sdl.getFramePosition();
            long longPos = sdl.getLongFramePosition();
            System.out.println("After 1 second: getFramePosition() = "+intPos);
            System.out.println("            getLongFramePosition() = "+longPos);
            if (intPos <= 0 || longPos <= 0) {
                failed = true;
                System.out.println("## FAILED: frame position did not advance, or negative!");
            }
            if (Math.abs(intPos - longPos) > 100) {
                failed = true;
                System.out.println("## FAILED: frame positions are not the same!");
            }
        } finally {
            sdl.close();
        }
    } catch (LineUnavailableException | IllegalArgumentException e) {
        System.out.println(e);
        System.out.println("Cannot execute test.");
        return;
    }
    if (failed) throw new RuntimeException("Test FAILED!");
    System.out.println("Test Passed.");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:34,代碼來源:LongFramePosition.java


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