Chapter 6: Modifying Sounds Using Loops

Similar documents
BBN ANG 141 Foundations of phonology Phonetics 3: Acoustic phonetics 1

The Physics Of Sound. Why do we hear what we hear? (Turn on your speakers)

PSYCHOACOUSTICS & THE GRAMMAR OF AUDIO (By Steve Donofrio NATF)

Musical Signal Processing with LabVIEW Introduction to Audio and Musical Signals. By: Ed Doering

Lecture 1: What we hear when we hear music

Digital Signal. Continuous. Continuous. amplitude. amplitude. Discrete-time Signal. Analog Signal. Discrete. Continuous. time. time.

Ch. 1: Audio/Image/Video Fundamentals Multimedia Systems. School of Electrical Engineering and Computer Science Oregon State University

UNIVERSITY OF DUBLIN TRINITY COLLEGE

MIE 402: WORKSHOP ON DATA ACQUISITION AND SIGNAL PROCESSING Spring 2003

ECE 4220 Real Time Embedded Systems Final Project Spectrum Analyzer

Note on Posted Slides. Noise and Music. Noise and Music. Pitch. PHY205H1S Physics of Everyday Life Class 15: Musical Sounds

Lab experience 1: Introduction to LabView

Musical Acoustics Lecture 15 Pitch & Frequency (Psycho-Acoustics)

Chapter 14 D-A and A-D Conversion

Professor Laurence S. Dooley. School of Computing and Communications Milton Keynes, UK

Pitch. The perceptual correlate of frequency: the perceptual dimension along which sounds can be ordered from low to high.

I. LISTENING. For most people, sound is background only. To the sound designer/producer, sound is everything.!tc 243 2

Laboratory 5: DSP - Digital Signal Processing

Audacity Tips and Tricks for Podcasters

Supplementary Course Notes: Continuous vs. Discrete (Analog vs. Digital) Representation of Information

Simple Harmonic Motion: What is a Sound Spectrum?

Audio and Other Waveforms

Dither Explained. An explanation and proof of the benefit of dither. for the audio engineer. By Nika Aldrich. April 25, 2002

ADDING (INJECTING) NOISE TO IMPROVE RESULTS.

Music Representations

QUIZ. Explain in your own words the two types of changes that a signal experiences while propagating. Give examples!

CSC475 Music Information Retrieval

CTP 431 Music and Audio Computing. Basic Acoustics. Graduate School of Culture Technology (GSCT) Juhan Nam

Digital Representation

Department of Electrical & Electronic Engineering Imperial College of Science, Technology and Medicine. Project: Real-Time Speech Enhancement

Music Representations

Using the new psychoacoustic tonality analyses Tonality (Hearing Model) 1

Lab 5 Linear Predictive Coding

Announcements. Project Turn-In Process. and URL for project on a Word doc Upload to Catalyst Collect It

Foundations and Theory

AN ARTISTIC TECHNIQUE FOR AUDIO-TO-VIDEO TRANSLATION ON A MUSIC PERCEPTION STUDY

The Distortion Magnifier

RaneNote SETTING SOUND SYSTEM LEVEL CONTROLS

Edison Revisited. by Scott Cannon. Advisors: Dr. Jonathan Berger and Dr. Julius Smith. Stanford Electrical Engineering 2002 Summer REU Program

Integrated Circuit for Musical Instrument Tuners

Musical Sound: A Mathematical Approach to Timbre

Spectrum Analyser Basics

NanoGiant Oscilloscope/Function-Generator Program. Getting Started

Realizing Waveform Characteristics up to a Digitizer s Full Bandwidth Increasing the effective sampling rate when measuring repetitive signals

Adaptive Resampling - Transforming From the Time to the Angle Domain

Experiments on tone adjustments

PCM ENCODING PREPARATION... 2 PCM the PCM ENCODER module... 4

Pole Zero Correction using OBSPY and PSN Data

Hugo Technology. An introduction into Rob Watts' technology

FPFV-285/585 PRODUCTION SOUND Fall 2018 CRITICAL LISTENING Assignment

1/29/2008. Announcements. Announcements. Announcements. Announcements. Announcements. Announcements. Project Turn-In Process. Quiz 2.

Announcements. Project Turn-In Process. Project 1A: Project 1B. and URL for project on a Word doc Upload to Catalyst Collect It

PHYSICS OF MUSIC. 1.) Charles Taylor, Exploring Music (Music Library ML3805 T )

R&D White Paper WHP 085. The Rel : a perception-based measure of resolution. Research & Development BRITISH BROADCASTING CORPORATION.

Dynamic Spectrum Mapper V2 (DSM V2) Plugin Manual

Acoustical Testing 1

Understanding PQR, DMOS, and PSNR Measurements

Experiment 9A: Magnetism/The Oscilloscope

Automatic music transcription

Pitch correction on the human voice

Experiment P32: Sound Waves (Sound Sensor)

Please feel free to download the Demo application software from analogarts.com to help you follow this seminar.

Lab P-6: Synthesis of Sinusoidal Signals A Music Illusion. A k cos.! k t C k / (1)

The BAT WAVE ANALYZER project

TDM 24CX-2 24CX-3 24CX-4 ELECTRONIC CROSSOVER OWNER S MANUAL A U D I O

Studio One Pro Mix Engine FX and Plugins Explained

F600A COMPRESSOR Operating Manual

Sound technology. TNGD10 - Moving media

SOUND LABORATORY LING123: SOUND AND COMMUNICATION

CZT vs FFT: Flexibility vs Speed. Abstract

The Cocktail Party Effect. Binaural Masking. The Precedence Effect. Music 175: Time and Space

Version 1.10 CRANE SONG LTD East 5th Street Superior, WI USA tel: fax:

HEAD. HEAD VISOR (Code 7500ff) Overview. Features. System for online localization of sound sources in real time

Jennifer H. Moore FEBRUARY Jennifer H. Moore. All rights reserved.

CM3106 Solutions. Do not turn this page over until instructed to do so by the Senior Invigilator.

Collection of Setups for Measurements with the R&S UPV and R&S UPP Audio Analyzers. Application Note. Products:

INSTRUCTION SHEET FOR NOISE MEASUREMENT

HARMONIC ANALYSIS OF ACOUSTIC WAVES

General Certificate of Education Advanced Subsidiary Examination June Problem Solving, Programming, Data Representation and Practical Exercise

(Skip to step 11 if you are already familiar with connecting to the Tribot)

8/30/2010. Chapter 1: Data Storage. Bits and Bit Patterns. Boolean Operations. Gates. The Boolean operations AND, OR, and XOR (exclusive or)

Chapter 40: MIDI Tool

Harmonic Analysis of the Soprano Clarinet

Visit for notes and important question. Visit for notes and important question

UNIT 1: QUALITIES OF SOUND. DURATION (RHYTHM)

The Definition of 'db' and 'dbm'

FRQM-2 Frequency Counter & RF Multimeter

BeoVision Televisions

Improving the accuracy of EMI emissions testing. James Young Rohde & Schwarz

MclNTOSH MODEL C-4 and C-4P

EUROPA I PREAMPLIFIER QUICK START GUIDE Dave Hill Designs version

Outline ip24 ipad app user guide. App release 2.1

RS232 Connection. Graphic LCD Screen. Power Button. Charger Adapter Input LNB Output. MagicFINDER Digital SatLock Operating Manual

Bias, Auto-Bias And getting the most from Your Trifid Camera.

Study of White Gaussian Noise with Varying Signal to Noise Ratio in Speech Signal using Wavelet

Music 175: Pitch II. Tamara Smyth, Department of Music, University of California, San Diego (UCSD) June 2, 2015

Measurement of overtone frequencies of a toy piano and perception of its pitch

Noise Detector ND-1 Operating Manual

PROFESSIONAL 2-CHANNEL MIXER WITH EFFECTS LOOP

ADSR AMP. ENVELOPE. Moog Music s Guide To Analog Synthesized Percussion. The First Step COMMON VOLUME ENVELOPES

Transcription:

Chapter 6: Modifying Sounds Using Loops

How sound works: Acoustics, the physics of sound Sounds are waves of air pressure Sound comes in cycles The frequency of a wave is the number of cycles per second (cps), or Hertz Complex sounds have more than one frequency in them. The amplitude is the maximum height of the wave

Volume and Pitch: Psychoacoustics, the psychology of sound Our perception of volume is related (logarithmically) to changes in amplitude If the amplitude doubles, it s about a 3 decibel (db) change 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

Logarithmically? It s strange, but our hearing works on ratios not differences, e.g., for pitch. We hear the difference between 200 Hz and 400 Hz, as the same as 500 Hz and 1000 Hz Similarly, 200 Hz to 600 Hz, and 1000 Hz to 3000 Hz Intensity (volume) is measured as watts per meter squared A change from 0.1W/m2 to 0.01 W/m2, sounds the same to us as 0.001W/m2 to 0.0001W/m2

Decibel is a logarithmic measure A decibel is a ratio between two intensities: 10 * log10(i1/i2) 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

Click here to see viewers while recording Fourier transform (FFT)

Digitizing Sound: How do we get that into numbers? Remember in calculus, estimating the 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?

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

Digitizing sound in the computer Each sample is stored as a number (two bytes) What s the range of available combinations? 16 bits, 216 = 65,536 But we want both positive and negative values To indicate compressions and rarefactions. What if we use one bit to indicate positive (0) or negative (1)? That leaves us with 15 bits 15 bits, 215 = 32,768 One of those combinations will stand for zero We ll use a positive one, so that s one less pattern for positives

Two s Complement Numbers 011 +3 Imagine there are only 3 bits 010 +2 we get 2 3 = 8 possible values 001 +1 Subtracting 1 from 2 we borrow 1 000 0 111-1 Subtracting 1 from 0 we borrow 1 s 110-2 which turns on the high bit for all 101-3 negative numbers 100-4

Two s complement numbers can be simply added Adding -9 (11110111) and 9 (00001001)

+/- 32K Each sample can be between -32,768 and 32,767 Why such a bizarre number? Because 32,768 + 32,767 + 1 = 2 16 < 0 > 0 0 i.e. 16 bits, or 2 bytes Compare this to 0...255 for light intensity (i.e. 8 bits or 1 byte)

Sounds as arrays Samples are just stored one right after the other in the computer s memory (Like pixels in a picture) That s called an array It s an especially efficient (quickly accessed) memory structure

Working with sounds We ll use pickafile and makesound. We want.wav files We ll use getsamples to get all the sample objects out of a sound We can also get the value at any index with getsamplevalueat Sounds also know their length (getlength) and their sampling rate (getsamplingrate) Can save sounds with writesoundto(sound, "file.wav")

>>> filename=pickafile() >>> print filename /Users/guzdial/mediasources/preamble.wav >>> sound=makesound(filename) >>> print sound Sound of length 421109 >>> samples=getsamples(sound) >>> print samples Samples, length 421109 >>> print getsamplevalueat(sound,1) 36 >>> print getsamplevalueat(sound,2) 29 >>> explore(sound)

>>> print getlength(sound) 220568 >>> print getsamplingrate(sound) 22050.0 >>> print getsamplevalueat(sound,220568) 68 >>> print getsamplevalueat(sound,220570) I wasn't able to do what you wanted. The error java.lang.arrayindexoutofboundsexception has occurred Please check line 0 of >>> print getsamplevalueat(sound,1) 36 >>> setsamplevalueat(sound,1,12) >>> print getsamplevalueat(sound,1) 12

Working with Samples We can get sample objects out of a sound with getsamples(sound) or getsampleobjectat(sound,index) A sample object remembers its sound, so if you change the sample object, the sound gets changed. Sample objects understand getsample(sample) and setsample(sample,value)

>>> soundfile=pickafile() >>> sound=makesound(soundfile) >>> sample=getsampleobjectat(sound,1) >>> print sample Sample at 1 value at 59 >>> print sound Sound of length 387573 >>> print getsound(sample) Sound of length 387573 >>> print getsample(sample) 59 >>> setsample(sample,29) >>> print getsample(sample) 29

But there are thousands of these samples! How do we do something to these samples to manipulate them, when there are thousands of them per second? We use a loop and get the computer to iterate in order to do something to each sample. An example loop: for sample in getsamples(sound): value = getsample(sample) setsample(sample,value)

def increasevolume(sound): for sample in getsamples(sound): value = getsamplevalue(sample) setsamplevalue(sample,value * 2)

How did that work? When we evaluate increasevolume(s), the function increasevolume is executed The sound in variable s becomes known as sound Sound is a placeholder for the sound object s. >>> f=pickafile() >>> s=makesound(f) >>> increasevolume(s) def increasevolume(sound): for sample in getsamples(sound): value = getsamplevalue(sample) setsamplevalue(sample,value * 2)

Starting the loop getsamples(sound) returns a sequence of all the sample objects in the sound. The for loop makes sample be the first sample as the block is started. def increasevolume(sound): for sample in getsamples(sound): value = getsamplevalue(sample) setsamplevalue(sample,value * 2) Compare: for pixel in getpixels(picture):

Executing the block We get the value of the sample named sample. We set the value of the sample to be the current value (variable value) times 2 def increasevolume(sound): for sample in getsamples(sound): value = getsamplevalue(sample) setsamplevalue(sample,value * 2)

Next sample Back to the top of the loop, and sample will now be the second sample in the sequence. def increasevolume(sound): for sample in getsamples(sound): value = getsamplevalue(sample) setsamplevalue(sample,value * 2)

And increase that next sample We set the value of this sample to be the current value (variable value) times 2. def increasevolume(sound): for sample in getsamples(sound): value = getsamplevalue(sample) setsamplevalue(sample,value * 2)

And on through the sequence The loop keeps repeating until all the samples are doubled def increasevolume(sound): for sample in getsamples(sound): value = getsamplevalue(sample) setsamplevalue(sample,value * 2)

>>> print s Sound of length 220567 >>> print f /Users/guzdial/mediasources/gettysburg10.wav >>> soriginal=makesound(f) >>> print getsamplevalueat(s,1) 118 >>> print getsamplevalueat(soriginal,1) 59 >>> print getsamplevalueat(s,2) 78 >>> print getsamplevalueat(soriginal,2) 39 >>> print getsamplevalueat(s,1000) -80 >>> print getsamplevalueat(soriginal,1000) -40 Here we re comparing the modified sound s to a copy of the original sound soriginal

The right side does look like it s larger.

def decreasevolume(sound): for sample in getsamples(sound): value = getsamplevalue(sample) setsamplevalue(sample,value * 0.5) This works just like increasevolume, but we re lowering each sample by 50% instead of doubling it.

We can make this generic By adding a parameter, we can create a general changevolume that can increase or decrease volume. def changevolume(sound, factor): for sample in getsamples(sound): value = getsamplevalue(sample) setsamplevalue(sample,value * factor)

def increasevolume(sound): for sample in getsamples(sound): value = getsamplevalue(sample) setsamplevalue(sample, value*2) def increasered(picture): for p in getpixels(picture): value=getred(p) setred(p,value*1.2) def decreasevolume(sound): for sample in getsamples(sound): value = getsamplevalue(sample) setsamplevalue(sample, value*0.5) def decreasered(picture): for p in getpixels(picture): value=getred(p) setred(p,value*0.5)

Does increasing the volume change the volume setting? No The physical volume setting indicates an upper bound, the potential loudest sound. Within that potential, sounds can be louder or softer They can fill that space, but might not. (Have you ever noticed how commercials are always louder than regular programs?) Louder content attracts your attention. It maximizes the potential sound.

Maximizing volume How, then, do we get maximal volume? (e.g. automatic recording level) It s a three-step process: First, figure out the loudest sound (largest sample). Next, figure out how much we have to increase/decrease that sound to fill the available space We want to find the amplification factor amp, where amp * loudest = 32767 In other words: amp = 32767/loudest Finally, amplify each sample by multiplying it by amp

def normalize(sound): largest = 0 for s in getsamples(sound): largest = max(largest, getsamplevalue(s)) amplification = 32767.0 / largest print "Largest sample value in original sound was", largest print Amplification multiplier is", amplification for s in getsamples(sound): louder = amplification * getsamplevalue(s) setsamplevalue(s, louder)

Max() max() is a function that takes any number of inputs, and always returns the largest. There is also a function min() which works similarly but returns the minimum >>> print max(1,2,3) 3 >>> print max(4,67,98,-1,2) 98

Or: use if instead of max def normalize(sound): largest = 0 for s in getsamples(sound): if getsamplevalue(s) > largest: largest = getsamplevalue(s) amplification = 32767.0 / largest print "Largest sample value in original sound was", largest print Amplification factor is", amplification for s in getsamples(sound): louder = amplification * getsamplevalue(s) setsamplevalue(s, louder)

Aside: positive and negative extremes assumed to be equal We re making an assumption here that the maximum positive value is also the maximum negative value. That should be true for the sounds we deal with, but isn t necessarily true Try adding a constant to every sample. That makes it non-cyclic I.e. the compressions and rarefactions in the sound wave are not equal But it s fairly subtle what s happening to the sound.

Why 32767.0, not 32767? Why do we divide out of 32767.0 and not just simply 32767? Because of the way Python handles numbers If you give it integers, it will only ever compute integers. >>> print 1.0/2 0.5 >>> print 1.0/2.0 0.5 >>> print 1/2 0

Avoiding clipping Why are we being so careful to stay within range? What if we just multiplied all the samples by some big number and let some of them go over 32,767? The result then is clipping Clipping: The awful, buzzing noise whenever the sound volume is beyond the maximum that your sound system can handle.

All clipping, all the time def onlymaximize(sound): for sample in getsamples(sound): value = getsamplevalue(sample) if value > 0: setsamplevalue(sample, 32767) if value < 0: setsamplevalue(sample, -32768)

Processing only part of the sound What if we wanted to increase or decrease the volume of only part of the sound? Q: How would we do it? A: We d have to use a range() function with our for loop Just like when we manipulated only part of a picture by using range() in conjunction with getpixels()