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

Above, Below, Around


WebReview.com: May 25, 2001; Tag of the Week: CSS2 Audio: Above, Below, Around

One of the more clever aural features in the CSS2 standard is the ability to position sound anywhere above, below, and around the listener. Last week, we covered the "above and below" part; this week we'll handle the "around" features.

The azimuth Property

While the elevation property moves a sound up and down, the azimuth property moves it around the listener. Together, these two properties let you control the position of a sound using a spherical coordinate system. Like the elevation property, the azimuth accepts a value in degrees or any one of several keywords that define preset positions around the listener. Angular positions are expressed as a numeric value in the range -360 to 360, followed by the unit deg. Straight ahead of the listener is defined as zero degrees, or 0deg when written as a value for the azimuth property. Positive value move around the listener in a clockwise fashion; negative values move around in a counter-clockwise fashion.

With a little thought, it becomes apparent that 90deg is to the right, 180deg is directly behind, and 270deg is to the left of the listener. Using the reverse direction, -270deg, -180deg, and -90deg correspond to the same positions, respectively. Of course, you can use any and all values in between these primary positions to position a sound in just the right spot.

Keyword Values

If geometry was never your strong suit, there are a number of handy keywords that make positioning easier. They are:

left-side
Completely left, equivalent to 270deg.

far-left
Not quite as far left, equivalent to 300deg.

left
A bit closer to center, equivalent to 320deg.

center-left
Approaching the front of the listener, equivalent to 340deg.

center
Right in front, equivalent to 0deg.

center-right
Slightly to the right, equivalent to 20deg.

right
More to the right, equivalent to 40deg.

far-right
Even further to the right, equivalent to 60deg.

right-side
Hard to the right, equivalent to 90deg.

All of these positions place the sound in front of the listener, shifting from left to right. You can add the keyword behind to select the same position, left to right, but behind the listener. Specifically, left-side and right-side stay the same, while the other positions flip behind the listener:

behind far-left240deg
behind left220deg
behind center-left200deg
behind center180deg
behind center-right160deg
behind right140deg
behind far-right120deg

If all this isn't enough, you can also use the leftwards and rightwards keywords, which shift the azimuth to the left or right of the containing element's azimuth. More accurately, they move the sound 20 degrees clockwise (rightwards) or counterclockwise (leftwards) from the current azimuth. This is important to note, since a sound at 180 degrees moved leftwards winds up at 160 degrees, which is actually to the right of the listener.

Aural Positioning

Appearances notwithstanding, positioning sounds is pretty easy. Need a sound above and to the right? Try:

     .above-right { elevation : above; azimuth : right }

Keep in mind that as the elevation increases (or decreases) the azimuth is less apparent to the listener.

Also remember that being able to fine-tune the position of every sound in your document doesn't mean that you must do so. Like the ransom-note font usage that emerged when authors were first able to choose from more than two fonts for their document, placing sounds all around the listener may be cool but will ultimately prove annoying. Think long and hard about how you want your document to sound and place your audio elements in a consistent manner. Used wisely, aural positioning, like every other feature in HTML and CSS2, will enhance your documents and invite your listeners to visit your pages more often.


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

Audio in CSS2: Spatial Positioning
Sound of Music: Background Sound with CSS2
Content Cueing


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.