Title: Programming
1Programming
- Week 5
- LBSC 690
- Information Technology
2Agenda
- Quiz
- Multimedia wrap-up
- Audio encoding
- Streaming and synchronizing
- Programming languages
- History and types
- Basics (data types, control structure, etc.)
- Web programming (JavaScript)
3Basic Audio Coding
- Sample at twice the highest frequency
- One or two bytes per sample
- Speech (0-4 kHz) requires 8 kB/s
- Standard telephone channel (1-byte samples)
- Music (0-22kHz) requires 88 kB/s
- Standard for CD-quality audio (2-byte samples)
4Speech Compression
- Opportunity
- Human voices vary in predictable ways
- Approach
- Predict whats next, then send only any
corrections - Standards
- Real audio can code speech in 6.5 kb/sec
- Demo at http//www.data-compression.com/speech.htm
l - Scroll down to near the bottom
5How do MP3s work?
- Opportunity
- The human ear cannot hear all frequencies at
once, all the time - Approach
- Dont represent things that the human ear cannot
hear
6Human Hearing Response
Experiment Put a person in a quiet room. Raise
level of 1kHz tone until just barely audible.
Vary the frequency and plot the results.
7Frequency Masking
Experiment Play 1kHz tone (masking tone) at
fixed level (60db). Play test tone at a different
level and raise level until just distinguishable.
Vary the frequency of the test tone and plot the
threshold when it becomes audible.
8Temporal Masking
If we hear a loud sound, then it stops, it takes
a while until we can hear a soft tone at about
the same frequency.
9Putting it all together
- Psychoacoustic compression
- Eliminate sounds below threshold of hearing
- Eliminate sounds that are frequency masked
- Eliminate sounds that are temporally masked
- Eliminate stereo information for low frequencies
10Transmission
- Download
- Transfer the whole file, then start replay
- Can be very slow for large files
- Streaming
- Play the file as it is received
- Also suitable for live broadcasts
- Requires a sufficiently fast connection
11The Last Mile
- Traditional modems
- 56 kb/sec modems really move 3 kB/sec
- Digital Subscriber Lines
- 384 kb/sec downloads (38 kB/sec)
- 128 kb/sec uploads (12 kB/sec)
- Cable modems
- 10 Mb/sec downloads (1 MB/sec)
- 256 kb/sec uploads (25kB/sec)
12Streaming Audio and Video
- Begins replay after only a portion received
- Buffer provides time to recover lost packets
- Interrupts replay when rebuffering
Media Sever
Buffer
Internet
13Narrated PowerPoint
- Create your slides
- Slide Show -gt Record Narration
- Set microphone level
- Record the narration
- Slide transitions are automatically captured
- Narration plays automatically when displayed
14Adding Video to PowerPoint
- Insert-gtMovies and Sounds
- Movies from file (a .mpg file)
- Decide whether you want autostart
- If not, it starts when you click on it
15Synchronizing Multiple Media
- Scripting Languages
- Synchronized Multimedia Integration Language
(SMIL) - Custom applications
- Macromedia Flash
- Content representation standards
- MPEG 4
16SMILe
- W3C standard
- Player-specific extensions are common
- XML, with a structure similar to HTML
- ltsmilgt
- ltheadgt lt/headgt
- ltbodygt lt/bodygt
- lt/smilgt
17Elements in SMIL
- Window controls (in ltheadgt)
- Controlling layout ltregiongt, ltroot-layoutgt
- Timeline controls (in ltbodygt)
- Sequence control ltseqgt, ltexclgt, ltpargt
- Timing control ltbegingt, ltendgt, ltdurgt
-
- Content types (in ltbodygt)
- ltaudiogt, ltvideogt, ltimggt, ltrefgt
18SMIL Examples
- Implemented in RealOne Player
- Example
- http//www.umiacs.umd.edu/oard/teaching/690/fall0
5/notes/4/media.html - First, run the executable
- Then, view .smil file
19Software
- Software models aspects of reality
- Input and output represent the state of the world
- Software describes how the two are related
- Examples
- Ballistic computations
- Google
- Microsoft Word
20Types of Software
- Application programs (e.g., Powerpoint)
- What you normally think of as a program
- Compilers and interpreters
- Programs used to write other programs
- Operating system (e.g., Windows XP)
- Manages display, CPU, memory, disk, tape,
- Embedded program (e.g., BIOS)
- Permanent software inside some device
21Programming Languages
- Used to specify every detail of the model
- Special purpose
- Able to specify an entire class of models
- Spreadsheets (Excel, ...)
- Databases (Access, Oracle, ...)
- General purpose
- Able to specify any possible model
- JavaScript, Java, Perl, C, C, ...
22History of Programming
- Machine language
- Language that machine can understand
- Assembly language
- Assembler changes names to machine code
- High-level languages
- Compiler/Interpreter translates to machine
language - FORTRAN, COBOL, C, C, Javascript
- Visual programming language
- Visually arrange the interface components
- Visual Basic,
23Machine Language
- Everything is a binary number
- Operations
- Data
- For instance
-
- 00001000 ADD
- 00010101 first number (21)
- 01010110 second number (86)
00001000 00010101 01010110
24Assembly Language
- Symbolic instruction codes and addresses
- Symbolic instruction code ADD
- Symbolic address SUM1
- For instance
ADD 21, SUM1
25High level Languages
- Procedural (modular) Programming
- Group instructions into meaningful abstractions
- C, Pascal, Perl
- Object oriented programming
- Group data and methods into objects
- Naturally represents the world around us
- C, Java, JavaScript
26Object Models
- Represent things in the world as objects
- Simplest objects are variables
- Represented with a name (n, teacher, )
- May be assigned a value (n4, teacherDoug, )
- Represent actions with methods
- Simplest methods are operations
- Represented with a symbol (, -, , /, , )
- Classes group objects with methods
- Models how kinds of things behave
- Objects are instances of classes
27Basic Data Types
- Boolean true, false
- Number 5, 9, 3.1415926
- String Hello World
28Operations and Assignments
- -x reverse the sign of x (negation)
- 65 Add 6 and 5 (numeric)
- Hello World Concatenate two strings
- 2.1 3 Multiply two values
- x increase value of x by 1
- x 5 set the value of x to be 5
- x y x x y
- x 5 x x 5
29Statements
- Simple assignment statements
- celsius 5/9 (f-32)
- Statements that invoke a method
- Temperature.toCelsius(104)
- Return a value from a method
- return celsius
30Methods
- Reusable code for achieving a single task
- function toCelsius(f)
- celsius 5/9 (f-32)
- return celsius
-
31Basic Control Structures
- Sequential
- Conditional
- Repetition
32Sequential Control Structure
a 2 b 3 c a b
33Conditional Selection Control Structure
- if (gender male)
- greeting Hello, Sir
-
- else
- greeting Hello, Madam
34Generating Boolean Results
- x y true if x and y are equal
- x ! y true if x and y are not equal
- x gt y true if x is greater than y
- x lt y true if x is smaller than or equal
to y - x y true if both x and y are true
- x y true if either x or y is true
- !x true if x is false
35Repetition Control Structure
Program Example 1 n 1 while ( n lt 10)
document.writeln(n) n Program 2 For (n
1 n lt 10 n) document.writeln(n)
36Arrays
- A set of elements
- For example, the number of days in each month
- Each element is assigned an index
- A number used to refer to that element
- For example, x4 is the fifth element (count
from zero!) - Arrays and repetitions work naturally together
37Programming for the Web
- Common Gateway Interface (CGI) Server side
- Forms encode field values into a URL
- CGI passes field values to a Perl program
- Program generates a web page as a response
- JavaScript Client-side, interpreted
- Human-readable source code sent to the browser
- Web browser runs the program
- Java applets Client-side, compiled
- Machine-readable bytecode sent to browser
- Web browser runs the program
38JavaScript
- ltHTMLgt
- ltHEADgt
- ltTITLEgtMy first scriptlt/TITLEgt
- lt/HEADgt
- ltBODY BGCOLORWHITEgt
- ltH1gt
- ltSCRIPT LANGUAGEJAVASCRIPT TYPE"TEXT/JAVASCRIPT
"gt - document.write("Hello, world!")
- lt/SCRIPTgt
- lt/H1gt
- lt/BODYgtlt/HTMLgt
- Try it at http//www.umiacs.umd.edu/daqingd/Cours
es/firstscript.html
39Handling Events
- Events
- actions that users perform while visiting the
page - Embedded in modern GUI
- Use event handlers to response events
- Event handlers triggered by events
- Examples of event handlers in Javascript
- onMouseover the mouse moved over an object
- onMouseout the mouse moved off an object
- onClick the user clicked on an object
40Hands On Adopt a JavaScript Program
- Launch a Web browser
- http//www.umiacs.umd.edu/daqingd/Courses/selecto
r.htm - See how it behaves if you are 13 (or 65)
- View source and read the program
- Save a local copy
- Make some changes and see how it works
41JavaScript Resources
- Google javascript
- Tutorials to learn to write programs
- Code to do things you want to do
- Engineering and Physical Sciences Library
- Books in locked case near circulation desk
42Before You Go!
- On a sheet of paper (no names), answer the
following question - What was the muddiest point in todays class?