Gold Wk 3 Problem 3: Sounds good!

[50 points; filename hw3pr3.py]

Starting files to download

Starter files for this problem:

    Download pythonSoundsCGU.zip from this link.

Be sure to unzip that folder somewhere -- there is a file named hw3pr3.py from which to start.

Background on representing audio information

What is inside an audio file?

Depending on the format, the actual audio data might be encoded in many different ways. One of the most basic is known as pulse code modulation (PCM), in which the sound waves are sampled every so often and given values in the range -128 to 127 (if 1 byte per sound sample is used) or -32768 to 32767 (if there are 2 bytes for each sample). Wikipedia explains it here. The .wav file format encodes audio in basically this way, and the cross-platform program Audacity is an excellent tool for visualizing the individual PCM samples of an audio file. You don't need Audacity for this problem, but it runs on Windows and Macs and is fun to play around with if you'd like to. Audacity can also convert to .wav from .mp3 and many other formats. Last but not least, Audacity was created by an HMC alum, Dominic Mazzoni.

Starter files

Be sure to grab the zipped folder pythonSounds.zip (above) -- it has a starter hw3pr3.py file and you'll need its support file, csaudio.py, three sounds files spam.wav, swfaith.wav, and swnotry.wav, and a Mac sound-playing program named play, which is also available from the play website. You won't need to download it from there, however, since it's already in the pythonSounds.zip file.

Getting started with csaudio:

The Python functions changeSpeed and flipflop

In your hw3pr3.py file, you will find two more functions, named changeSpeed and flipflop.

Try those two out with the calls

>>> changeSpeed( 'swfaith.wav', 44100 )  # Alvin as Darth...

>>> flipflop( 'swfaith.wav' )  # split and switched...
Be sure to read over both of these functions and understand why they do what they do. Then you'll be ready to write your own sound-manipulating code!

Warning: you'll see commented-out lines at the bottom of each function that would otherwise return the full list of sound samples. These are very large lists -- if you return the list of raw sound data (these return statements are currently commented out...), then be sure to assign the result to a variable! By doing so, e.g., L = changeSpeed('swfaith.wav', 30000), IDLE will not try to print out all of the raw sound data. If you don't assign the call to a variable, IDLE will try to print out the raw sound data, it will be too big, and IDLE will hang or crash.

Thus, when using the return statements, the assignment to L is important, because these functions return a large list of sound data samples! You can always look at pieces of L with slicing, e.g., L[0:100].

Functions to write

Question 0: Slowing down...

Question 1: Sound reversal

Question 2: Whisper/shout mode

Question 3: A pure-tone generator

Hint: As a hint, a 440 hertz concert-tuning A with amplitude of 20,000 and running for 1 second (which is 22050 samples) would be formed by the cosine wave

[ 20000.0*math.cos( 2*math.pi*440.0*x/22050 ) for x in range(22050) ]



Question 4: Chords

Question 5: Your own effect(s)...



Submission

Simply submit your altered hw3pr3.py file in the usual way through the submission site.

----- History: r43 - 27 Sep 2010 - 00:59:19 - ZacharyDodds
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback