Book Contents          Previous Chapter          Next Chapter

Sound

This chapter describes features provided by Magic Cap for playing and managing sounds. Every Magic Cap communicator includes a speaker for playing sounds and a microphone for recording sound samples, along with software capabilities for using those sounds. Before reading this chapter, you should be familiar with viewable objects and with Magic Cap's object runtime.

About Sound

Magic Cap provides features for handling sound input and sound output, available on every Magic Cap communicator. Class Viewable defines the attribute Sound and the operations PlaySound and PlaySoundWithDefault, enabling every viewable object to be associated with a sound. For more information on these fundamental sound features in viewables, see the Sound section in this book's Viewables and Touching chapter.

Most other sound features are implemented by class Playable, an abstract class, and class Sound, a concrete class that inherits the interface of Playable.

Most sound recording and playback in Magic Cap is done as a result of user actions. For example, the user touches a song stamp to play its song, and the user touches a sound stamp to record sound input. Most packages won't ever have to create sound objects or call their operations.

Sound Features

This section describes the concepts and operations provided for sound objects in Magic Cap. Unless otherwise noted, all operations in this section are defined for class Sound.

Playing Sounds

Magic Cap provides several operations that you can use to control sound playing. You can call PlaySound to play the sound object through the speaker. If a sound is playing, you can call Stop to end the sound before it finishes playing. Call Pause to stop the sound from playing temporarily and Resume to start playing again.

You can call Honk to play the Magic Cap standard error sound, which by default is the "clank" sound.

Notes

Magic Cap defines operations that let you play single notes, which you specify by giving pitch and duration. You can call PlayNote to play a note of a given pitch and duration. If you want to play a series of notes, call QueueNote for each note in the sequence. You can play sounds in sequence by calling QueueSound for each one.

If you want to play a note immediately, mixing it with any sound that is currently playing, call MixPlayNote.

You can call NoteOn to play a note continuously. To stop the note, call NoteOff.

Information About Sounds

This section describes operations that provide information about sounds and the state of the speaker.

You can call IsPlaying to determine if any sound is playing. Although IsPlaying requires a particular sound object as its responder, it returns true if any sound is currently playing.

Call PlaybackPitch to get the pitch of the sound or note currently playing.

Recording Sounds

Magic Cap includes operations that let you record sound objects using the communicator's built-in microphone. Note that recorded sound samples require a large amount of memory, so you should use them sparingly.

You can call StartRecordingSound to begin recording a sound sample using the microphone. Pass the maximum duration of the sample and the desired compression when you call StartRecordingSound. To stop recording the sample, call StopRecordingSound.

Related Classes

This section describes other classes you might use when working with sound objects in Magic Cap.

Speakers

Magic Cap defines class Speaker to represent the server that controls the communicator's speaker hardware. You can use indexical iSpeaker as the responder when you call these operations.

Class Speaker defines a number of operations that you might use when working with sounds, but the features of most of these operations are provided at a higher level by class Sound. The one operation that provides features not available at a higher level is PlaySample. You can call PlaySample to play a raw sound sample defined in a buffer that you specify.

Reference

For more information, see the following topics in Magic Cap Class and Method Reference:

class Sound

operations and attributes:

Honk
IsPlaying
MixPlayNote
NoteOff
NoteOn
PlaybackPitch
PlayNote
QueueNote
QueueSound
StartRecordingSound
StopRecordingSound

class Viewable

operations and attributes:

PlaySound
PlaySoundWithDefault
Sound

class Playable

operations and attributes:

Pause
PlaySound
Resume
Stop

class Speaker

operations and attributes:

PlaySample


Book Contents          Previous Chapter          Next Chapter