Sound, Part 3. Multiple Echoes Here is a recipe to create multiple echoes: def echoes(sndfile, delay, num): s1 = makeSound(sndfile) ends1 = getLength(s1)

Slides:



Advertisements
Similar presentations
Sound and the Codec Output On the DE2. Sound Sound is transmitted in air through compressions and rarefactions (stretches) of the air. This can be represented.
Advertisements

CS 102 Computers In Context (Multimedia)‏ 04 / 13 / 2009 Instructor: Michael Eckmann.
Tamara Berg Advanced Multimedia
ITEC 109 Lecture 25 Sound.
Features of MP3, MIDI, wave, audio and file types including suffixes. By Georgina Honeysett PGCE ICT.
CNIT 132 – Week 9 Multimedia. Working with Multimedia Bandwidth is a measure of the amount of data that can be sent through a communication pipeline each.
Sound in multimedia How many of you like the use of audio in The Universal Machine? What about The Universal Computer? Why or why not? Does your preference.
4.1Different Audio Attributes 4.2Common Audio File Formats 4.3Balancing between File Size and Audio Quality 4.4Making Audio Elements Fit Our Needs.
Part A Multimedia Production Rico Yu. Part A Multimedia Production Ch.1 Text Ch.2 Graphics Ch.3 Sound Ch.4 Animations Ch.5 Video.
Chapter 8: Making Sounds by Combining Pieces. Chapter Objectives.
Introduction to Computing and Programming in Python: A Multimedia Approach Chapter 8: Making Sounds by Combining Pieces.
From Sound to Music CSC 161: The Art of Programming Prof. Henry Kautz 11/16/2009.
Int 2 Multimedia Revision. Digitised Sound Analogue sound recorded from person, or real instruments.
Georgia Institute of Technology Creating Sounds and MIDI part 2 Barb Ericson Georgia Institute of Technology Oct 2005.
CMPS1371 Introduction to Computing for Engineers PROCESSING SOUNDS.
Music and Mathematics are they related?. What is Sound? Sound consists of vibrations of the air. In the air there are a large number of molecules moving.
Digital audio recording Kimmo Tukiainen. My background playing music since I was five first time in a studio at fourteen recording on my own for six months.
Sound, Part 2 Using range to manipulate samples by index number.
CSE466 Autumn ‘00- 1 System Functional Requirements  Children’s toy…comes with PC software. Child plays notes on the screen and the device makes corresponding.
Music and Logo Some Music Theory Just enough.. KISS We will say in the key of C no flats or sharps unless indicated. For our purpose we will stick to.
Spring 2002EECS150 - Lec13-proj Page 1 EECS150 - Digital Design Lecture 13 - Final Project Description March 7, 2002 John Wawrzynek.
Chapter 14 Recording and Editing Sound. Getting Started FAQs: − How does audio capability enhance my PC? − How does your PC record, store, and play digital.
Digital Audio Multimedia Systems (Module 1 Lesson 1)
Audio Production Basics. Pros and Cons of Digital Recording Pros – Much easier for the average person. Much less cumbersome Will not deteriorate over.
infinity-project.org Engineering education for today’s classroom 53 Design Problem - Digital Band Build a digital system that can create music of any.
 Continuous sequence of vibrations of air  (Why no sound in space? Contrary to Star Wars etc.)  Abstraction of an audio wave:  Ear translates vibrations.
Introduction to Interactive Media 10: Audio in Interactive Digital Media.
Introduction to Computing and Programming in Python: A Multimedia Approach Chapter 7: Modifying Samples in a Range.
Problem Solving with Data Structures using Java: A Multimedia Approach Chapter 5: Arrays: A Static Data Structure for Sounds.
CompSci Today’s topics Sound Upcoming ä Intellectual property ä Network analysis ä Security Reading.
ACOUSTICS AND THE ELEMENTS OF MUSIC Is your name and today’s date at the top of the worksheet now?
COMP Representing Sound in a ComputerSound Course book - pages
CSCI-235 Micro-Computers in Science Hardware Part II.
Chapter 11 Audio © 2013 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in.
AUDIO MEDIA 1 Created } “Borrowed” } Microphone MIDI keyboard CD’s & flash drives Internet Audio Sources 2.
Signal Digitization Analog vs Digital Signals An Analog Signal A Digital Signal What type of signal do we encounter in nature?
COSC 1P02 Introduction to Computer Science 4.1 Cosc 1P02 Week 4 Lecture slides “Programs are meant to be read by humans and only incidentally for computers.
Sound on the Web. Using Sound on a Web Site Conveying information  pronounce a word or describe a product Set a mood  music to match the web page scene.
Introduction to Computing and Programming in Python: A Multimedia Approach Chapter 8: Making Sounds by Combining Pieces.
Chapter 15 Recording and Editing Sound. 2Practical PC 5 th Edition Chapter 15 Getting Started In this Chapter, you will learn: − How sound capability.
Physics of Sound Part 1 Sound waves How they are generated and travel.
Computer Science 1 Week 11. This Week... QBasic While Loops QBasic While Loops Audio Basics Audio Basics.
Chapter 7: Modifying Samples in a Range. Chapter Objectives.
Georgia Institute of Technology Processing Sound Ranges Barb Ericson Georgia Institute of Technology July 2005.
Sound Representation Digitizing Sound Sound waves through Air Different Voltages Voltage converted to numbers.
Introduction to Computing and Programming in Python: A Multimedia Approach Chapter 7: Modifying Samples in a Range.
James Hornsby Connor Bradshaw 1168 Unit 1. Unit Unit  I will use Garageband because it has simple user interface, it is easy to use.
1 Rev 07/28/2015.  Describe: examples, definition,? 2.
CS 102 Computers In Context (Multimedia)‏ 03 / 30 / 2009 Instructor: Michael Eckmann.
Chapter 8: Making Sounds by Combining Pieces. Chapter Objectives.
CSCI-100 Introduction to Computing Hardware Part II.
Chapter 8: Making Sounds by Combining Pieces. Chapter Objectives.
“But it looks right”: Bugs in non-majors media programs Mark Guzdial College of Computing/GVU Georgia Institute of Technology.
Chapter 8: Modifying Samples in a Range. Chapter Objectives.
Sounds in Jython 16 bit samples : -32,768 and 32,767 Sound object holds all samples file = pickAFile() sound = makeSound( file ) SoundSample objects store.
12-3 Harmonics.
Working with Sounds Barb Ericson College of Computing Georgia Institute of Technology
1 Section 5.4 Digital Sound Processing Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
XP Practical PC, 3e Chapter 14 1 Recording and Editing Sound.
Chapter 15 Recording and Editing Sound
Chapter 8: Making Sounds by Combining Pieces
Processing Sound Ranges part 3
Chapter 7: Modifying Samples in a Range
Chapter 8: Making Sounds by Combining Pieces
How sound works: Acoustics, the physics of sound
Chapter 7: Modifying Samples in a Range
Processing Sound Ranges
Processing Sound Ranges part 3
CS1315: Introduction to Media Computation
Creating Sounds and MIDI
Presentation transcript:

Sound, Part 3

Multiple Echoes Here is a recipe to create multiple echoes: def echoes(sndfile, delay, num): s1 = makeSound(sndfile) ends1 = getLength(s1) ends2 = ends1 + (delay * num) #ends2 is in samples – convert to seconds and make empty sound that long s2 = makeEmptySound(1 + int(ends2 / getSamplingRate(s1))) echoAmplitude = 1.0 for echoCount in range(1, num + 1): echoAmplitude = echoAmplitude * 0.6 for pos1 in range(1, ends1): pos2 = pos1 + (delay * echoCount) value1 = getSampleValueAt(s1, pos1) * echoAmplitude value2 = getSampleValueAt(s2, pos2) setSampleValueAt(s2, pos2, value1 + value2) play(s2) return s2

Splicing Sounds Say we want to splice pieces of speech together extracting words from the same sound file: –Find the end points of words –Copy the samples into the right places to make the words come out as we want them –(We can also change the volume of the words as we move them, to increase or decrease emphasis and make it sound more natural.)

Finding the word endpoints Using MediaTools and play before/after cursor, can figure out the index numbers where each word ends Change to: “We the United People of the United States…”

Now, it’s all about copying We have to keep track of the source and target indices, srcIndex and destIndex destIndex = Where-the-incoming-sound-should-start for srcIndex in range(startingPoint, endingPoint): sampleValue = getSampleValueAt(source, srcIndex) setSampleValueAt(dest, destIndex, sampleValue) destIndex = destIndex + 1

How to do it First, set up a source and target. Next, we copy “United” (samples to 40052) after “We the” (sample 17408) –That means that we end up at ( ) = =24046 –Where does “People” start? Next, we copy “People” (17408 to 26726) immediately afterward – ( ) = –Do we have to copy “of” to? –Or is there a pause in there that we can make use of? Finally, we insert a little (1/441-th of a second) of space – 0’s

def splicePreamble(): file = "/Users/sweat/1315/MediaSources/preamble10.wav" source = makeSound(file) dest = makeSound(file) # This will be the newly spliced sound destSample = # targetIndex starts after "We the" in the new sound for srcSample in range(33414, 40052): # Where the word "United" is in the sound setSampleValueAt(dest, destSample, getSampleValueAt( source, srcSample)) destSample = destSample + 1 for srcSample in range(17408, 26726): # Where the word "People" is in the sound setSampleValueAt(dest, destSample, getSampleValueAt( source, srcSample)) destSample = destSample + 1 for index in range(1, 1000): #Stick some quiet space after that setSampleValueAt(dest, destSample, 0) destSample = destSample + 1 play(dest) #Let's hear and return the result return dest The Whole Splice

What if we didn’t do that second copy? Or the pause? def splicePreamble(): file = "/Users/sweat/1315/MediaSources/preamble10.wav" source = makeSound(file) dest = makeSound(file) # This will be the newly spliced sound destSample = # targetIndex starts after "We the" in the new sound for srcSample in range(33414, 40052): # Where the word "United" is in the sound setSampleValueAt(dest, destSample, getSampleValueAt( source, srcSample)) destSample = destSample + 1 #for srcSample in range(17408, 26726): # Where the word "People" is in the sound #setSampleValueAt(dest, destSample, getSampleValueAt( source, srcSample)) #destSample = destSample + 1 #for index in range(1, 1000): #Stick some quiet space after that #setSampleValueAt(dest, destSample, 0) #destSample = destSample + 1 play(dest) #Let's hear and return the result return dest

Making Sine Waves We can build our own waves using trigonometry functions like sine or cosine 1 π2π2π Let’s say that we want the sound to play at 440 hz ; that is one cycle in 1/440 sec = seconds If our sampling rate is 22,050 samples per second, then for one cycle we need: (seconds) * (samples/second) = 50 samples Get a sample from the sine wave every (2 * pi) / 50 and repeat

Generating a Sine Wave To build the sine wave –Compute sample interval from the sine function samplesPerCycle = (1/freq) * samplingRate samplingInterval = (2 * pi) / samplesPerCycle –Generate blank sound of desired length –Loop through each sample of the blank sound Set it to the next sample from the sine wave

Sine Wave Function def sineWave(frequency, amplitude, duration): snd = makeEmptySound(duration) interval = 1.0 / frequency samplesPerCycle = interval * getSamplingRate(snd) samplingInterval = (2 * ) / samplesPerCycle sampleValue = 0 for pos in range (1, getLength(snd) + 1): rawSample = sin(sampleValue) sampleVal = int(amplitude * rawSample) setSampleValueAt(snd, pos, sampleVal) sampleValue = sampleValue + samplingInterval play(snd) return snd

Did it work? Test with different frequencies, durations, amplitudes Save to a file and examine with media tools –writeSoundTo(snd, “filename.wav”) Getting fancier –Can add sine waves together, just like we did with.wav files, to generate chords and more interesting sounds Early computers used sine waves, square waves, and triangle waves to make sound

MP3 Today, many audio files are stored using the MP3 format Data is compressed so it requires less space Lossless compression –Instead of storing each sample, what if we only stored the difference from the last sample? –The difference is usually much smaller than to It might only be +/- 100, which would require fewer bits to store Lossy compression –Throws away some of the sound, especially at higher frequencies, that you can’t hear E.g. soft sound simultaneously played with a loud sound WAV files also compressed, using a lossless compression technique

MIDI Musical Instrument Digital Interface –Standard for synthesizers so different musical hardware can interoperate with a computer –Can specify notes and instruments –JES has a built-in MIDI player using a piano The musical scale, starting at middle C, proceeds as follows: C C sharp D D sharp E F F sharp G A flat A B …

MIDI The MIDI format assigns a numerical value to each note. The table below shows some notes and their numeric values. Musical NoteNumeric Value C (middle C)60 C Sharp61 D62 D Sharp63 E64 F65 F sharp66 G67 A flat68 A69...

playNote The playNote function is: –playNote(note, duration, velocity) Note - This is the numeric value corresponding to the note using the table above. The value can actually range between 0 and 127, so you can use values below 60 for lower octaves below Middle C, and larger values for higher octaves. Duration. The duration is how long to play the note in milliseconds. A duration of 1000 would play the note for one second, while a duration of 250 would play the note for a quarter of a second. Volume or Velocity. In a metaphor to a piano, the velocity is how hard you hit the key and thus corresponds to the volume of the note. A velocity of 0 is silent while the highest velocity is 127.

Sample Programs def playScale(): for note in range(60, 71): playNote(note, 1000, 127) def playSong(): playNote(60, 500, 127) # C playNote(60, 500, 127) # C playNote(67, 500, 127) # G playNote(67, 500, 127) # G playNote(69, 500, 127) # A playNote(69, 500, 127) # A playNote(67, 1000, 127) # G playNote(65, 500, 127) # F playNote(64, 500, 127) # E playNote(62, 500, 127) # D playNote(60, 1000, 127) # C