Hardware Reference
In-Depth Information
Individual beeps can be used as a simple acknowledge tone, to indicate that the system has carried out a particular
task—a high pitched beep for “okay,” and a lower tone for “error”—or to issue an alarm bell (think of the range of
sounds an 80s computer game managed with a similar level of technology!) Its biggest, most obviously, benefit is that
sound requires so little processing power, that you can run complex operations on the chip. We saw this in operation
earlier with software-lead Armstrong, but you can also rely on hardware, and use the voice synthesis chips to generate
multichannel audio.
Sample playback is obviously a better solution for audio feedback. Although beeps are sufferable, they are just
that—sufferable! If you listen to any TV show or film, the beeps and chirps of the high tech equipment presented always
have more color (or timbre) to the sound that a simple square wave. The beeps of R2D2 in Star Wars might sound basic,
but if you analyze them you'll see they have great texture. So having samples to replace beeps is an obvious step up.
Also, sound samples can be used to represent anything. Including pre-recorded speech. This (as we'll see in
Chapter 5) can be used in place of speech synthesis to create a more natural sounding house voice. Some people
have taken Majel Barrett's voice, the computer from Star Trek, in this regard! So, as long as you only need prerecorded
phrases, this provides a very nice interface.
N With the exception of news stories, most feedback systems can be quantified with predetermined error codes
and messages. You might have to reword the message from “You have only N megabytes of free space on /dev/sda1”
to “Your server is running low on disc space,” but it is usually preferable.
Tip
The method for sample playback is a little more involved than making a simple beep. This is because to make
a recognisable sample you have to change the output pin more often. Usually, an order of magnitude more often.
For example, to play a square wave at 440Hz (the “A above middle C”) you must change the output level of the pin
from high to low 440 times a second. (This is 880 operations.) For a sample, you will often need a minimum of 11050
changes per second, with each level change requiring the additional time penalty of a memory access, and the use
of an analog output. The Nyquist theorem indicates that to represent a sound of 1000Hz, you will need a sampling
frequency of at least twice this, 2000Hz. As a guide, CDs have a playback frequency of 44,100Hz.
However, it is possible!
Two software-only solutions are at your disposal, both stem from the base code at http://playground.arduino.cc/
Code/PCMAudio , which provides a fairly low-level solution of manipulating the PWM signal on pin 11. The expanded
(i.e., high level) version of this library is at http://hlt.media.mit.edu/?p=1963 and lets you initiate playback with
code such as:
#include <PCM.h>
const unsigned char sampleData[] PROGMEM = {
126, 127, 128, 128, 128, 128, 128, 127, 128, 128, 128, 129, 129, 128, 127,
... lots more data here ...
};
void setup()
{
startPlayback(sampleData, sizeof(sampleData));
}
void loop()
{
}
 
Search WWH ::




Custom Search