Sound

File formats

  • AIFF is a fairly common answering-machine quality audio format.
    	An AIFF file (like an AU file) is simply a 
    	record of the wave forms sensed by a microphone
    	at a series of times t0,t1,... The duration 
    	between samples determines the accuracy of the
    	digital sound.  In other words, if you have an 
    	extremely accurate digitization of the sound, 
    	the rate of sampling (measured in Megahertz) will
    	be great (eg 33MHz), whereas a crude approximation 
    	will sample the wave less frequently (eg 8MHz).  
    	A less frequently sampled sound wave generates 
    	approximate data (squarish waves) in much the 
    	same way a pixelated file approximates an
    	image.
    
  • MIDI is a format that handles sounds differently
    	Midi files are control scripts for midi-devices--
    	traditionally things like keyboards.  These 
    	devices often understand how to play "samples"
    	(here I mean "blurbs" of music, sound, etc.), 
    	but they can also play notes according to wave 
    	form definitions.
    	We don't really have much equipment for authoring
    	Midi files, although some software and equipment
    	exists in the music department.  Midi files are
    	intriguing because they can compact extensive 
    	durations of music into very small files.
    

  • An AIFF file can be played with Netscape 3.0 and doesn't need a helper program.
  • Sound with Java
  • Converting AIFF to AU (aka NeXT/Sun)
  • Must convert in "12 bit" u-law mode of AU. The Mac shareware that I've succeeded with is called "SoundConverter", and is on the PowerMacs in the WebSoftware folder. It will convert AIFF to AU.
  • To check that your sound is okay, you can ftp it to the server in "Raw Data" mode, and execute the "file" command with the argument being the .au file's name:
    newmedia> file vader.au
       vader.au:       Sun/NeXT audio data: 8-bit ISDN u-law, mono, 8000 Hz	
    
  • Suppose we want to play a file in our applet

    	AudioClip snd;
    
    	public void init(){
    		snd = getAudioClip(getCodeBase(),"my.au");
    	}
    
    	public boolean keyDown(Event e, int key){
    	
    		if(key == 'a'){
    			snd.play();
    		}
    		return true;
    	}
    

  • Suppose we want a player control panel

    	
    	int play[] =  { 100,100,  110,110,  100,120 };
    		// a triangle
    	int stop[] =  { 120,100,  140,100,  140,120,  120,120 };  // a square
    
    	public  boolean mouseDown(Event e, int x, int y)P
    		if(y>100 && y<120){
    			if(x>100 && x<120) snd.play();
    			else if(x>120 && x<140) snd.stop();
    		}		
    		return true;
    	}
    		
    	public void paint(Graphics g){
    		Polygon p = new Polygon();
    		
    		for(int i=0;i
    	}
    
    (Move pointer within the applet bounds and hit 'a' key to play sound)