Presentation is loading. Please wait.

# Georgia Institute of Technology Introduction to Processing Digital Sounds.

## Presentation on theme: "Georgia Institute of Technology Introduction to Processing Digital Sounds."— Presentation transcript:

Georgia Institute of Technology Introduction to Processing Digital Sounds

Georgia Institute of Technology How does Hearing Work? The outer ear “catches” sounds The eardrum vibrates The inner ear translates the vibrations to nerve impulses for the brain to interpret

Georgia Institute of Technology Volume and Pitch Our perception of volume is related (logarithmically) to changes in amplitude – If the amplitude doubles, it’s about a 3 decibel (dB) change. – A decibel is a ratio between two intensities: 10 * log 10 (I 1 /I 2 ) – As an absolute measure, it’s in comparison to threshold of audibility 0 dB can’t be heard. Normal speech is 60 dB. A shout is about 80 dB Our perception of pitch is related (logarithmically) to changes in frequency – Higher frequencies are perceived as higher pitches – We can hear between 5 Hz and 20,000 Hz (20 kHz) – A above middle C is 440 Hz

Georgia Institute of Technology Digitizing Sound In calculus you learn to estimate a curve by creating rectangles We can do the same to estimate the sound curve – Analog-to-digital conversion (ADC) will give us the amplitude at an instant as a number: a sample – How many samples do we need?

Georgia Institute of Technology Nyquist Theorem We need twice as many samples as the maximum frequency in order to represent (and recreate, later) the original sound. The number of samples recorded per second is the sampling rate – If we capture 8000 samples per second, the highest frequency we can capture is 4000 Hz That’s how phones work – If we capture more than 44,000 samples per second, we capture everything that we can hear (max 22,000 Hz) CD quality is 44,100 samples per second

Georgia Institute of Technology Why Digitize Sound? High fidelity – Reproduced sound is very similar to the original Perfect reproduction – Sounds the same every time Easy to transmit – Download as data Easier to manipulate on a computer – Even though there are billions of bits

Georgia Institute of Technology Playing a Sound We can create a Sound object just as we created a Picture object – Get a file name and save a reference to it String fileName = FileChooser.pickAFile(); – Pick a file that ends in.wav – Create the sound object by asking the class to create a new Sound object and initialize it by reading data from the given file name Sound sound1 = new Sound(fileName); – Play the Sound sound1.play();

Georgia Institute of Technology Sound Basics new Sound(fileName) – Will create a new Sound object from the data in the file with the passed file name soundObj.play() – Will start the sound playing soundObj.explore(); – Will open a sound explorer on the object soundObj.blockingPlay() – Will play the sound and wait to return until the sound is finished soundObj.write(String fileName) – Will write out the sound to the file

Georgia Institute of Technology Play and Explore a Sound Sound Explorer Type here

Georgia Institute of Technology The Sound Explorer Not all of the sound is shown when you explore a sound – Skips values to fit in the window You can zoom in – To see all sample values You can zoom out – To fit the sound in the window again

Georgia Institute of Technology Getting the Sound Sample Values A Sound has many values in it – Numbers that represent the sound at that time in the sample You can get an array of SoundSample objects – SoundSample[] sampleArray = sound1.getSamples();

Georgia Institute of Technology Changing the Value of a Sound Sample You can set the value of a SoundSample – sample.setValue(value); – This will change the value in the Sound object as well So how would you change the value to the original value * 2? SoundSample sample = sampleArray[0]; sample.setValue(sample.getValue() * 2);

Georgia Institute of Technology Increase Volume with For-Each Loop public void increaseVolume() { SoundSample[] sampleArray = this.getSamples(); int value = 0; // value at sample // loop through SoundSample objects for (SoundSample sample : sampleArray) { value = sample.getValue(); // get the value sample.setValue(value * 2); // set the value }

Georgia Institute of Technology Memory versus Disk When we read from a file we read from disk into memory – Computers only do calculations on memory We change the values in memory The file on the disk hasn’t changed To save our new sound we need to write a file to the disk – soundObj.write(fileName);

Georgia Institute of Technology Normalize Sounds Make the whole sound as loud as possible – How loud can it be? The max positive value is 32767.0 The max negative value is -32768.0 – First we need to find the largest value (positive or negative) in the current sound Create a variable to hold the max – And set it to the first value in the array And loop through the array and if the absolute value of the current value is greater – Store that one instead

Georgia Institute of Technology Find the Largest Value in an Array Start with the first value in the array – The one at index 0 int max = valueArray[0]; Loop through the rest of the items in the array – Compare the absolute value of the value at current index in the array to the absolute value of the largest If it is bigger store it in max for (int i = 1; i < valueArray.length; i++) { if (Math.abs(valueArray[i]) > Math.abs(max)) max = valueArray[i]; }

Georgia Institute of Technology Find the Largest Value in an Array int max = first element max = valueArray[0] = 2000; for (int i = 1; i < valueArray.length; i++) { if (Math.abs(valueArray[i]) > Math.abs(max) max = valueArray[i]; } 2000 | 1000 | -2344 | 100 | 3300

Georgia Institute of Technology Find the Largest Value in an Array What is the value of max each time through the loop? ivaluemax 2000 110002000 2-2344 3100-2344 43300 2000 | 1000 | -2344 | 100 | 3300 0 1 2 3 4

Georgia Institute of Technology Normalize Sound - Continued After we find the maximum value – Determine the factor that we can multiply all values by And not go over the maximum allowed value double multiplier = 32767.0 / max; – Call the method changeVolume with the multiplier Test with String file = FileChooser.getMediaPath(“double preamble.wav”); Sound soundObj = new Sound(file); soundObj.explore(); soundObj.normalize(); soundObj.explore();

The Sound class The Sound class is provided in your bookClasses directory. Bring it up in Dr. Java and run JavaDoc on it to see all of the functionality it has – blendSounds – Echo – Modify frequency – Reverse – Splice – And much more ….

Download ppt "Georgia Institute of Technology Introduction to Processing Digital Sounds."

Similar presentations

Ads by Google