Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Audio in CSS2


WebReview.com: May 18, 2001; Tag of the Week: Audio in CSS2

May 18, 2001 > Tag of the Week

Audio in CSS2: Spatial Positioning

By Chuck Musciano

Conventional documents are laid out on a two-dimensional surface: a rendered page. Whether on your display or on a sheet of paper, elements of any Web document wind up at some specific (x,y) location on the page. Audio does this one better, as we'll see this week.

When you "lay out" an audio document, you get to place sound in a three-dimensional volume: the space surrounding the listener's head. Most of us are familiar with stereo music, which places sounds to the right and left of a listener, and more advanced audio systems that place sound all around the listener. The aural properties of CSS2 let you take advantage of these more advanced audio capabilities if your listener's aural browser supports them.

Sounds are placed around a listener using two values: azimuth and elevation. If you place the listener at the center of a circle, the azimuth is the angle around that circle at which the sound is produced. An azimuth of 0 degrees is directly in front of the listener; 90 degrees is to his or her right, 180 degrees is directly behind, and 270 degrees is to the left.

Once the azimuth is set, the height of the sound is determined by the elevation. Again, this is a value expressed as an angle. An elevation of 0 degrees is on the listener's horizon. The maximum elevation is 90 degrees, directly overhead, and the minimum elevation is -90 degrees, directly below the listener.

Controlling Elevation

As you might expect, there are two CSS2 properties, azimuth and elevation, to manage the spatial positioning of sounds in your aural document. You can assign these properties to any and all elements in your document, making different elements appear to be positioned in different spots as the document is read.

The elevation property accepts both numeric and keyword values in a fairly straightforward manner. We'll cover elevation now and move on to the much fancier azimuth property next week.

To set a specific elevation, provide a value in degrees. Within CSS2, degree values must have deg after the numeric value. Thus, to place a sound halfway up, you might say:

     B : { elevation : 45deg }

Similarly, a sound slightly below the listener could be obtained with

     I : { elevation : -15deg }

For the geometrically challenged, there are a few keywords that make life easier. If you specify the above or below keywords, you get the same effect as if you had used the values 90deg and -90deg, respectively.

If you would prefer relative positioning, you can use the higher and lower keywords with the elevation property. These keywords place the affected element 10 degrees higher or lower than the containing element. This is handy for lifting certain sounds above the general level of the surrounding sounds without having to compute a specific elevation for each element.

Finally, keep in mind that increasing elevation diminishes the effect of azimuth changes. When a sound moves directly overhead, you cannot tell if it is in front of you or behind you. Like all layout tools, sound placement requires some thought and attention to detail to make things just right. Next week, we'll see just how clever you can be, as we work through the various features of the azimuth property.


Chuck is the author of the best-selling HTML: The Definitive Guide and now, the fourth and expanded edition, HTML & XHTML: The Definitive Guide. He also writes on a variety of Internet and Web-related topics for a number of online magazines.


Previously in Tag of the Week

Sound of Music: Background Sound with CSS2
Content Cueing
CSS2 Aural Properties: Fact or Fiction?


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.