MCCC CIS 177 - Markup Languages

Multimedia

Work with Sound

Overview

Sound files must be in digital format before you can use them on the Web. Two factors come into play when converting from analog to digital: sampling rate and sample resolution. Analog sound waves consist of two components including amplitude, which is the height of the wave and frequency, which is the speed at which the sound wave moves and relates to the pitch. Sounds with low frequency have lower pitches.

Since analog sounds are continuous, they must be converted digitally by recording measurements of the sound at discrete moments in tme. Each measurement is called a sample. The number of samples taken per second is called the sampling rate, which is measured in kilohertz (KHz). Common sampling rates are 11 KHz, 22 KHz, and 44 KHz. The higher the sampling rate, the more samples that are taken per second, resulting in greater quality. Of course, the higher the sampling rate, the larger the file.

Sample resolution indicates the precision in measuring the sound within each sample and is measured in bits. Common resolutions are 8-, 16-, and 32-bit. Again, the higher the resolution, the bigger the file.

While sampling rate and sample resolution dictate the quality of the digitized sound and the size of the file, you must also choose how many channels to use, which is typically either stereo or mono. Stereo is a richer sound than mono, but significantly increases the file size.

Sound file formats

Common sound file formats include AIFF/AIFC (Mac); AU (Unix); MIDI (Synthesized); MPEG (MP3 - also video); RealAudio (realtime playing); SND (Mac); WAV (Windows).

There are type classifications of sound formats including nonstreaming and streaming. Nonstreaming media must fully download before it plays, while streaming media play in a steady continuous stream as they are downloaded.

Adding Sound to a Web Page

Linking to sound file

You can link to a sound file in the same way you link to another Web page using the <a> anchor tag. Of course, the user must have the appropriate sound player installed on their computer to be able to play the file:

<a href="sound.mp3">Play this file</a>

Download the lab files here.

Insert the following code immediately below the last paragraph in raintxt.htm.

<p>Click below to listen to the sounds of <i>Adams & Davis</i> from last year's folk festival.</p>

<blockquote>
<a href="mountain.mp3">Wild Mountain Thyme Full Clip (342K - MP3)</a><br>
<a href="mountain.wav">Wild Mountain Thyme Partial Clip (211K - WAV)</a><br>
<a href="mountain.au">Wild Mountain Thyme Partial Clip (211K - AU)</a>

Save the file and test the links in the browser.

Embedding a sound file

Linking to a sound file as in the previous section causes the browser to open the related application separately. An embedded sound file can be played from within the Web page. Of course, the user must have the supporting application installed. Use the <embed> tag to embed a sound file in a Web page:

<embed src="URL" width="value" height="value" align="value" autostart="value">

width and height = pixels (size of the control panel)
align = left, right to wrap text or top, or bottom to align with baseline
autostart = true or false

Edit raintxt.htm and add the following code in the blockquote. Use the format that is supported by the local system:

<embed src="mountain.mp3" width="145" height="60" autostart="false">

Save the file and test the embedded sound file in the browser.

Use <bgsound> tag

You can automatically have the browser play sound in the background when the page loads using the <bgsound> tag:

<bgsound src="URL" balance="value" loop="value" volume="value">

balance = defines how the sound should be balanced between left and right speakers (-10,000 to 10,000)
loop = how many times the clip should play (1,2,3...infinite)
volume = 0 (muted) - 10,000

Edit raintxt.htm and add the following code inthe blockquote.

<bgsound src="mountain.mp3" balance="0" loop="1" volume="10">

Save the file and test it in the browser.