Sounds in Jython - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

Sounds in Jython

Description:

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 – PowerPoint PPT presentation

Number of Views:113
Avg rating:3.0/5.0
Slides: 10
Provided by: r006
Category:
Tags: jython | long | sound | sounds

less

Transcript and Presenter's Notes

Title: Sounds in Jython


1
Sounds in Jython
  • 16 bit samples -32,768 and 32,767
  • Sound object holds all samplesfile
    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 atcourses.cs.vt.edu/cs1004/cs4
hs/
2
Sound Samples
  • Samples retrieved either as
  • collection/array of SoundSample
    objectscollection______________________________
    ______for sample in getSamples( sound)
    setSampleValue( sample, getSampleValue(sample)2)
    array_______________________________________s
    amples getSamples( sound)for s in range(0,
    getNumSamples(sound)) half getSampleValue(
    sampless ) / 2 setSampleValue( sampless,
    half )
  • single SoundSample objectssample
    getSampleObjectAt( sound, 100 )

3
Normalize a Sound
  • Normalizing sounds involves making them as loud
    as possibledef 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 32767.0 / large
  • for snd in getSamples(source)
  • loud scalergetSample(snd)
  • setSample(snd, loud)

Code available atcourses.cs.vt.edu/cs1004/cs4hs
/
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 lt num)
for pause in range(0, int(s1rate delay))
setSampleValueAt( snd2, posn2, 0 )
posn2 posn2 1 fadeAmplitude
fadeAmplitude 0.6 each fade is 60 of
previous return snd2
Code available atcourses.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
  • http//www.cs.uic.edu/i101/projects/proj4.html
  • Mozarts Dice Game
  • Create a waltz by pasting together pre-composed
    minuet trio clips.
  • http//www.cs.cornell.edu/courses/cs1110/2008fa/as
    signments/a6/a6.html
Write a Comment
User Comments (0)
About PowerShow.com