The sound sensor

Experiment with this program, record and explain your results. What conditions change the values that are read?

import lejos.nxt.*;

public class TestSound {

	public static void main(String[] args) 
	throws Exception {
		SoundSensor sound = new SoundSensor(SensorPort.S3); //**CREATE SENSOR**
		int value;
		int soft = sound.readValue(); // save softest sound
		int loud = sound.readValue();// save loudest sound
		
		// calibrate for what constitutes soft or loud sound until Right arrow is pressed
		while (!Button.RIGHT.isPressed()){
			value = sound.readValue(); // read the current sound level
			LCD.clear();
			LCD.drawString("Sound Sensor", 3, 3);
			LCD.drawString("Value", 3, 4);
			LCD.drawInt(value, 11, 4);
			LCD.drawString("Loud", 3, 5);
			LCD.drawString("Soft", 3, 6);
			Thread.sleep(500); // wait half a second
			
			if (value > loud)
				loud = value;  // remember the loudest value
			else if (value < soft)
				soft = value;  // remember the softest value
			
			LCD.drawInt(loud, 11, 5);
			LCD.drawInt(soft, 11, 6);
			LCD.refresh();
		}
		
		// now, evaluate sounds as being soft or loud
		while ( !Button.ESCAPE.isPressed()){
			int threshold = soft + ((loud - soft) / 2);
			value = sound.readValue();
			if ( value > threshold )
			{
				LCD.clear();
				LCD.drawString("LOUD", 3, 3);
			}
			else
			{
				LCD.clear();
				LCD.drawString("soft", 3, 3);
			}
			LCD.refresh();
			Thread.sleep(500);
		}
	}

}