All pastes #405394 Raw Edit

Someone

public java v1 · immutable
·published 2007-03-21 18:33 UTC
rendered paste body
import apcslib.*;import chn.util.*;import javax.swing.*;import java.awt.*;import java.applet.*;import javax.sound.sampled.*; import java.io.*; import javax.sound.midi.*; import javax.sound.midi.MidiDevice.*;public class Sound extends Applet {  	Sequencer background = null;//	Sequencer midiSound;	Clip[] sounds;		public Sound()	{		sounds = new Clip[5];		sounds[0] = load(1);		sounds[1] = load(2);		sounds[2] = load(3);		sounds[4] = load(5);		this.loadMidi();			}	public void test(int track){   	//loadSound(track);   		if (track  != 4) {   			sounds[track-1].start();   		}   		else if (track == 4){   			background.start();   		}	}	private void loadMidi(){		Sequence sequence = MidiSystem.getSequence(new File("C:\\Documents and Settings\\crussell_m\\Desktop\\Pong\\sound\\jolene.mid"));     	background = MidiSystem.getSequencer();		background.open();		background.setSequence(sequence);    	background.setLoopCount(javax.sound.midi.Sequencer.LOOP_CONTINUOUSLY);    	//=background;    	//background.setLoopCount(10000);    	//background.start()	}	public Clip load(int track){		AudioInputStream stream = null;		Clip clip;		try {			if(track == 1){    	   		stream = AudioSystem.getAudioInputStream(new File("C:\\Documents and Settings\\crussell_m\\Desktop\\Pong\\Pong\\sound\\dead.au"));	    		}    		if(track == 2){    			stream = AudioSystem.getAudioInputStream(new File("C:\\Documents and Settings\\crussell_m\\Desktop\\Pong\\sound\\fire.wav"));    		}    		if(track == 3){    	   		stream = AudioSystem.getAudioInputStream(new File("C:\\Documents and Settings\\crussell_m\\Desktop\\Pong\\sound\\game2.wav"));		    	}        	if(track == 5){  	       		stream = AudioSystem.getAudioInputStream(new File("C:\\Documents and Settings\\crussell_m\\Desktop\\Pong\\sound\\nosoup.wav"));	        	}	 //       AudioInputStream stream = AudioSystem.getAudioInputStream(new File("ding"));            // From URL        //stream = AudioSystem.getAudioInputStream(new URL("http://hostname/audiofile"));            // At present, ALAW and ULAW encodings must be converted        // to PCM_SIGNED before it can be played             if(stream != null){        	       		AudioFormat format = stream.getFormat();        	if (format.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) {	            format = new AudioFormat(                    AudioFormat.Encoding.PCM_SIGNED,                    format.getSampleRate(),                    format.getSampleSizeInBits()*2,                    format.getChannels(),                    format.getFrameSize()*2,                    format.getFrameRate(),                    true);        // big endian    	        stream = AudioSystem.getAudioInputStream(format, stream);        	}         // Create the clip        	DataLine.Info info = new DataLine.Info(            Clip.class, stream.getFormat(), ((int)stream.getFrameLength()*format.getFrameSize()));        	clip = (Clip) AudioSystem.getLine(info);    	        // This method does not return until the audio file is completely loaded        	clip.open(stream);    		System.out.println("Clip is: " + clip);    		//clip.start();    	}        // Start playing    //} catch (MalformedURLException e) {    //} catch (IOException e) {    //} catch (LineUnavailableException e) { 	   }  	   catch (Exception e) {	    	System.out.println("Problem with sound loading \n"+ e);   	 		e.printStackTrace();  		}	  		return clip;			}    private  void loadSound(int track)   {   /*		Clip clip;   		AudioInputStream stream = null;		try {        // From file        if(track == 1){    	   stream = AudioSystem.getAudioInputStream(new File("C:\\Documents and Settings\\crussell_m\\Desktop\\Pong\\Pong\\sound\\dead.au"));    	}    	if(track == 2){    		  stream = AudioSystem.getAudioInputStream(new File("C:\\Documents and Settings\\crussell_m\\Desktop\\Pong\\sound\\fire.wav"));    	}    	if(track == 3){    	   stream = AudioSystem.getAudioInputStream(new File("C:\\Documents and Settings\\crussell_m\\Desktop\\Pong\\sound\\game2.wav"));		    	}        if(track == 5){  	       stream = AudioSystem.getAudioInputStream(new File("C:\\Documents and Settings\\crussell_m\\Desktop\\Pong\\sound\\nosoup.wav"));	        } //       AudioInputStream stream = AudioSystem.getAudioInputStream(new File("ding"));            // From URL        //stream = AudioSystem.getAudioInputStream(new URL("http://hostname/audiofile"));            // At present, ALAW and ULAW encodings must be converted        // to PCM_SIGNED before it can be played             if(stream != null){        	        AudioFormat format = stream.getFormat();        if (format.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) {            format = new AudioFormat(                    AudioFormat.Encoding.PCM_SIGNED,                    format.getSampleRate(),                    format.getSampleSizeInBits()*2,                    format.getChannels(),                    format.getFrameSize()*2,                    format.getFrameRate(),                    true);        // big endian            stream = AudioSystem.getAudioInputStream(format, stream);        }         // Create the clip        DataLine.Info info = new DataLine.Info(            Clip.class, stream.getFormat(), ((int)stream.getFrameLength()*format.getFrameSize()));        clip = (Clip) AudioSystem.getLine(info);    	        // This method does not return until the audio file is completely loaded        clip.open(stream);    	System.out.println("Clip is: " + clip);    	clip.start();    	}        // Start playing        if(track == 4){        	    				Sequence sequence = MidiSystem.getSequence(new File("C:\\Documents and Settings\\crussell_m\\Desktop\\Pong\\sound\\jolene.mid"));    		      	background = MidiSystem.getSequencer();        			background.open();        			background.setSequence(sequence);        			background.setLoopCount(javax.sound.midi.Sequencer.LOOP_CONTINUOUSLY);        			//background.setLoopCount(10000);        			background.start();    	}    //} catch (MalformedURLException e) {    //} catch (IOException e) {    //} catch (LineUnavailableException e) {    } catch (Exception e) {    	System.out.println("Problem with sound loading \n"+ e);    	e.printStackTrace();    }		System.out.println("sound is loaded");	}	public void stop(){		background.stop();*/	}}