Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sounds in Jython 16 bit samples : -32,768 and 32,767

Similar presentations


Presentation on theme: "Sounds in Jython 16 bit samples : -32,768 and 32,767"— Presentation transcript:

1 Sounds in Jython 16 bit samples : -32,768 and 32,767
Sound object holds all samples file = pickAFile() sound = makeSound( file ) SoundSample objects store a single sample Two ways of playing sounds play (sound ) #spawns process to play sound blockingPlay( sound ) #no spawning Slides available at: courses.cs.vt.edu/~cs1004/cs4hs/

2 Sound Samples Samples retrieved either as:
collection/array of SoundSample objects #collection____________________________________ for sample in getSamples( sound): setSampleValue( sample, getSampleValue(sample)*2) #array_______________________________________ samples = getSamples( sound) for s in range(0, getNumSamples(sound)): half = getSampleValue( samples[s] ) / 2 setSampleValue( samples[s], half ) single SoundSample objects sample = getSampleObjectAt( sound, 100 )

3 Normalize a Sound Normalizing sounds involves making them as loud as possible def driver(): file = pickAFile() sound = makeSound( file ) blockingPlay( sound ) normalize( sound ) blockingPlay( sound ) def normalize( source ): large = 0 for snd in getSamples(source): large = max(large, abs(getSample(snd)) ) scaler = / large loud = scaler*getSample(snd) setSample(snd, loud) Code available at: courses.cs.vt.edu/~cs1004/cs4hs/ 32767 -32767

4 Reverse a sound In late 1969 a rumor started circulating that Paul McCartney of the Beatles had died in 1966 and had been replaced by a double. To support this urban legend many reported that if one played the song "Revolution 9" from the white album backwards one could hear "Turn me on, dead man". Reverse the last 15 seconds of the song "Revolution 9" from the white album:  rev9.wav Modify the normalize code by adding a reverse() function that swaps all the samples in a sound, (first & last, second & next-to-last, etc.). Extra-credit: do not modify the original sound.

5 Fade Outs Create a new sound from copies of a sound, where the copies fade out with a delay between the copies: def fadeOut( snd1, delay, num ) : s1rate = getSamplingRate(snd1) ends1 = getLength( snd1 ) snd2 = makeEmptySound( ends1 * (num + 1) + num * int(delay * s1rate) ) ends2 = getLength( snd2 ) fadeAmplitude = 1.0 posn2 = 0 for echoCount in range( 0, num + 1 ) : for posn1 in range( 0, ends1-1 ) : values1 = getSampleValueAt( snd1, posn1) * fadeAmplitude setSampleValueAt( snd2, posn2, values1 ) posn2 = posn2 + 1 if (echoCount < num): for pause in range(0, int(s1rate * delay)): setSampleValueAt( snd2, posn2, 0 ) fadeAmplitude = fadeAmplitude * # each fade is 60% of previous return snd2 Code available at: courses.cs.vt.edu/~cs1004/cs4hs/

6 Blending Sounds Creates a new sound from existing sounds.
Corresponding samples from the sounds are blended together. Blending involves adding percentages (50%) of each sample together. Lab/class activity: download a reading of the Gettysburg address and an instrumental recording of God Bless America and create a blending of the two, (i.e. sound mix).

7 ALVIN! Lurch? Sounds can be speeded up or slowed down by under-sampling or over-sampling. Here is a famous line from the classic Paul Newman movie "Cool Hand Luke" as spoken by the inimitable character actor Strother Martin:  FailureToCommunicate.wav Code a function to speed up the sound by creating a new sound half as long as the original using every other sample from the original. Code a function to slow down the sound by creating a new sound twice as long as the original using every sample from the original twice.

8 Interpolation Under-sampling or over-sampling are just specific instances of linear interpolation (the same as nearest neighbor in image scaling). Given a length (sampling) factor, e.g., 0.80, 1.15, return a new sound of the new length and sampling using linear interpolation. Linear Interpolation: x For any new sound sample s the corresponding sample x from the original sound = s / (length of new sound) * length of original sound

9 Sound Projects Simple Telephony
Given sound clips for each spoken digit, combine them to speak any given number. Sound Steganography Hide a message inside a sound file Mozart’s Dice Game Create a waltz by pasting together pre-composed minuet & trio clips.


Download ppt "Sounds in Jython 16 bit samples : -32,768 and 32,767"

Similar presentations


Ads by Google