Chapter 26. Sound

REALbasic can produce four different types of sound. The first three are: a simple beep; a 'snd' resource (or, what amounts to the same thing, a sound file of type 'sfil', which is simply a way of packaging a 'snd' resource); and a QuickTime MIDI note. This chapter discusses each of these types of sound.

The fourth way in which REALbasic can produce a sound is as part of a movie. In fact, REALbasic can play a sound as a movie: in the presence of QuickTime 4 or later, it can open a sound file in a QuickTime-compatible format (such as AIFF, wav, MP3, or a MIDI file), converting it to a movie on the fly. The sound is then played with a MoviePlayer control; MoviePlayers are the subject of Chapter 27.

On Windows, there’s no such thing as a 'snd' resource; .wav, MIDI, and MP3 files are played as sound files, not as movies.


To play the system beep sound, call the Beep procedure, like this:[136]


Sound Object

REALbasic includes a Sound class; you send an instance of this class the Play message to produce the sound. The question is then how to obtain a Sound instance. There are three ways:

  • Import a sound file from the Finder into your project. The project maintains an alias to the sound file until the application is built, so don’t throw the sound file away while the project is still under development. The listing in the Project Window is the global name of a sound instance.

  • Send a ResourceFork the GetSound message, handing it the ID number of a 'snd' resource. ...

Get REALBasic: TDG, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.