from sound to music csc 161: the art of programming prof. henry kautz 11/16/2009
TRANSCRIPT
![Page 1: From Sound to Music CSC 161: The Art of Programming Prof. Henry Kautz 11/16/2009](https://reader030.vdocuments.net/reader030/viewer/2022032701/56649c865503460f9493cc81/html5/thumbnails/1.jpg)
From Sound to Music
CSC 161: The Art of ProgrammingProf. Henry Kautz
11/16/2009
![Page 2: From Sound to Music CSC 161: The Art of Programming Prof. Henry Kautz 11/16/2009](https://reader030.vdocuments.net/reader030/viewer/2022032701/56649c865503460f9493cc81/html5/thumbnails/2.jpg)
2
Last ClassWorking with sound files
Example file sound.py import wave import arrayfrom math import sin, pi
![Page 3: From Sound to Music CSC 161: The Art of Programming Prof. Henry Kautz 11/16/2009](https://reader030.vdocuments.net/reader030/viewer/2022032701/56649c865503460f9493cc81/html5/thumbnails/3.jpg)
3
Fast
![Page 4: From Sound to Music CSC 161: The Art of Programming Prof. Henry Kautz 11/16/2009](https://reader030.vdocuments.net/reader030/viewer/2022032701/56649c865503460f9493cc81/html5/thumbnails/4.jpg)
4
Slow
![Page 5: From Sound to Music CSC 161: The Art of Programming Prof. Henry Kautz 11/16/2009](https://reader030.vdocuments.net/reader030/viewer/2022032701/56649c865503460f9493cc81/html5/thumbnails/5.jpg)
5
ConceptsSound
FrequencyAmplitudeSampling Rate
WAV fileHeaderFrames
Sound dataRaw file contents: string of bytesArray: sequence of 16 bit (or other size) numbers
![Page 6: From Sound to Music CSC 161: The Art of Programming Prof. Henry Kautz 11/16/2009](https://reader030.vdocuments.net/reader030/viewer/2022032701/56649c865503460f9493cc81/html5/thumbnails/6.jpg)
6
Common Ways to Manipulate Sound Waves
Speed up
Slow down
Combine
Add echo
Reverse ?!
![Page 7: From Sound to Music CSC 161: The Art of Programming Prof. Henry Kautz 11/16/2009](https://reader030.vdocuments.net/reader030/viewer/2022032701/56649c865503460f9493cc81/html5/thumbnails/7.jpg)
7
Secret Message
![Page 8: From Sound to Music CSC 161: The Art of Programming Prof. Henry Kautz 11/16/2009](https://reader030.vdocuments.net/reader030/viewer/2022032701/56649c865503460f9493cc81/html5/thumbnails/8.jpg)
8
Programming AssignmentAdd the following two functions to sound.py:
backwards( ) should read the names of input and output WAV files, and create a backwards version of the input file in the output file.Apply backwards( ) to secretMessage.wav
combine( ) should read the names of two input WAV files and one output file. The output file should have the length of the shorter of the
two input files, and contain the combination of the two input files.
Each sample in the output is the sum of the two corresponding samples in the inputs, divided by 2.
Use combine( ) to combine declaration.wav and BornToRun.wav
![Page 9: From Sound to Music CSC 161: The Art of Programming Prof. Henry Kautz 11/16/2009](https://reader030.vdocuments.net/reader030/viewer/2022032701/56649c865503460f9493cc81/html5/thumbnails/9.jpg)
9
Part II (Optional, Extra Credit)
Implement the following functions:amplify( ): Scale the amplitude of the samples in a
file so that the absolute value of the largest (loudest) samples is 32767. Note that samples may be positive or negative, and
that your function will have to scan through all the frames first to discover the largest sample absolute value, in order to determine the scaling factor.
soften( ): Cut the maximum amplitude of a file in half.
echo( ): Add an echo effect to a file.This is done by merging in a softer version of the file
with itself delayed by a half second or so
![Page 10: From Sound to Music CSC 161: The Art of Programming Prof. Henry Kautz 11/16/2009](https://reader030.vdocuments.net/reader030/viewer/2022032701/56649c865503460f9493cc81/html5/thumbnails/10.jpg)
10
Two Roads to Computer Music
![Page 11: From Sound to Music CSC 161: The Art of Programming Prof. Henry Kautz 11/16/2009](https://reader030.vdocuments.net/reader030/viewer/2022032701/56649c865503460f9493cc81/html5/thumbnails/11.jpg)
11
Sampling & MixingThe first electronic music sampled, altered, and
mixed sounds by physically cutting and manipulating audio tape!
Scratching: manipulating sound samples by changing speed / reversing vinyl records
![Page 12: From Sound to Music CSC 161: The Art of Programming Prof. Henry Kautz 11/16/2009](https://reader030.vdocuments.net/reader030/viewer/2022032701/56649c865503460f9493cc81/html5/thumbnails/12.jpg)
12
Sound Mix ArtistsRap often mixes in clips of other songs
In classical music, avant garde composers have long been fascinated with found sound John Cage
Starting in the 1960’s, popular artists started to explore the possibilities of mixing arbitrary soundFrank ZappaBrian WilsonThe Beatles: Revolution 9Wilco
![Page 13: From Sound to Music CSC 161: The Art of Programming Prof. Henry Kautz 11/16/2009](https://reader030.vdocuments.net/reader030/viewer/2022032701/56649c865503460f9493cc81/html5/thumbnails/13.jpg)
13
Revolution 9
![Page 14: From Sound to Music CSC 161: The Art of Programming Prof. Henry Kautz 11/16/2009](https://reader030.vdocuments.net/reader030/viewer/2022032701/56649c865503460f9493cc81/html5/thumbnails/14.jpg)
14
The Other Road: Synthesis
![Page 15: From Sound to Music CSC 161: The Art of Programming Prof. Henry Kautz 11/16/2009](https://reader030.vdocuments.net/reader030/viewer/2022032701/56649c865503460f9493cc81/html5/thumbnails/15.jpg)
15
Wendy Carlos
![Page 16: From Sound to Music CSC 161: The Art of Programming Prof. Henry Kautz 11/16/2009](https://reader030.vdocuments.net/reader030/viewer/2022032701/56649c865503460f9493cc81/html5/thumbnails/16.jpg)
16
Synthesizing SoundHow can we write a Python program to
synthesize sound?
Let’s remember the key concepts of digital sound waves
![Page 17: From Sound to Music CSC 161: The Art of Programming Prof. Henry Kautz 11/16/2009](https://reader030.vdocuments.net/reader030/viewer/2022032701/56649c865503460f9493cc81/html5/thumbnails/17.jpg)
17
Key Conceptsfrequency: the number of waves per second =
pitch
amplitude: the height of each wave = loudness
sampling rate: the number of samples per second of the wave = quality
![Page 18: From Sound to Music CSC 161: The Art of Programming Prof. Henry Kautz 11/16/2009](https://reader030.vdocuments.net/reader030/viewer/2022032701/56649c865503460f9493cc81/html5/thumbnails/18.jpg)
18
Formula for Pure Tones
€
€
i = sample (frame) number
S = sample value
α = amplitude (loudness)
f = frequency (pitch)
r = sampling rate
S =α sin(2π f i / r)
![Page 19: From Sound to Music CSC 161: The Art of Programming Prof. Henry Kautz 11/16/2009](https://reader030.vdocuments.net/reader030/viewer/2022032701/56649c865503460f9493cc81/html5/thumbnails/19.jpg)
19
Synth
![Page 20: From Sound to Music CSC 161: The Art of Programming Prof. Henry Kautz 11/16/2009](https://reader030.vdocuments.net/reader030/viewer/2022032701/56649c865503460f9493cc81/html5/thumbnails/20.jpg)
20
Part III (Optional, Extra Credit): Music Synthesizer
Implement a program that reads in a text file containing musical notation and creates a WAV file of the music.
The musical notation: Each note is specified by two characters separated
by white space. The first character is a letter specifying the pitch
A, B, C, D, E, F, G, or the letter R to indicate a restThe second character is the duration specified a
W, H, Q, E (whole, half, quarter, eighth).
![Page 21: From Sound to Music CSC 161: The Art of Programming Prof. Henry Kautz 11/16/2009](https://reader030.vdocuments.net/reader030/viewer/2022032701/56649c865503460f9493cc81/html5/thumbnails/21.jpg)
21
finally
![Page 22: From Sound to Music CSC 161: The Art of Programming Prof. Henry Kautz 11/16/2009](https://reader030.vdocuments.net/reader030/viewer/2022032701/56649c865503460f9493cc81/html5/thumbnails/22.jpg)
22
Part IV (Optional, Extra Credit): Music Composition
Create an original musical composition using any or all of the functions you implementedYou can create your own input WAV files using any
programs you like. iTunes to rip samples from CDsSound Recorder to record from a microphoneYou might run several different functions multiple
times to create your final composition.
![Page 23: From Sound to Music CSC 161: The Art of Programming Prof. Henry Kautz 11/16/2009](https://reader030.vdocuments.net/reader030/viewer/2022032701/56649c865503460f9493cc81/html5/thumbnails/23.jpg)
Movies of the Day
23