Normalizing Sounds – Java Multimedia

Before normalizing sounds, lets have a look at following factors

  • Overall shape of the sound waveform is dependent on many samples
  • If we multiply all the samples by the same multiplier, we only effect our sense of volume (intensity), not the sound itself

Making sound as louder as possible is known as normalizing sounds.  Though it is a hard job but possible. Here are the steps involved normalizing sound.

  • Find the largest sample in the sound
  • Maximum positive value allowed is 32767
  • Multiply all the samples by same multiplier
  • Find the multiplier by computing (multiplier = 32,767/largest)
  • Multiply all the sample by the multiplier

Check out the code given below :

public void normalize() {
	int largest = 0;
	SoundSample[] sampleArray = this.getSamples();
	SoundSample sample = null;
	int value = 0;

	// loop comparing the absolute value of the current value
	// to the current largest
	for (int i = 0; i < sampleArray.length; i++) { sample = sampleArray[i]; value = Math.abs(sample.getValue()); if (value > largest)
			largest = value;
	}

	// now calculate the multiplier to multiply by
	double multiplier = 32767.0 / largest;

	/*
	 * loop through all the samples and multiply by the multiplier
	 */
	for (int i = 0; i < sampleArray.length; i++) {
		sample = sampleArray[i];
		sample.setValue((int) (sample.getValue() * multiplier));
	}
}

Check out the video and see the sound wave generated.

No Responses