The Game Kit Table of Contents The Game Kit Index

BSimpleGameSound

Derived from: BGameSound

Declared in: be/game/SimpleGameSound.h

Library: libgame.so

Allocation: Constructor only

Summary

The BSimpleGameSound class represents simple sound effects that don't change, and remain in memory.

Using BSimpleGameSound is, well, simple:

   BSimpleGameSound *mysound = new BSimpleGameSound("soundfile.wav");
   ...
   mysound.StartPlaying();

This snippet uses BSimpleGameSound to create an object that can be used to play the sound effect in the file "soundfile.wav". Playing the sound is as simple as calling StartPlaying().

In the current version of the BeOS, when you clone a BSimpleGameSound, the sound data buffer is also cloned, so you'll have multiple copies of the sound effect in memory. Keep this in mind as you write your code, as you can rapidly use a lot of memory this way.


Constructor and Destructor


BSimpleGameSound()

                                                         
  

BSimpleGameSound(const entry_ref *inFile,
      BGameSoundDevice *device = NULL)
BSimpleGameSound(const void *inData, size_t inFrameCount,
      const gs_audio_format *format,
      BGameSoundDevice *device = NULL)
BSimpleGameSound(const BSimpleGameSound &other)

Prepares the object to play the specified sound. The first form of the constructor preloads the entire sound specified by inFile into memory.

The second form of the constructor accepts in inData a pointer to sound data already in memory. inFrameCount indicates how many frames of audio are in that buffer, and format indicates the format of the audio data.

In both cases, device specifies the sound device that should be used for playing the sound; NULL uses the default sound player.

Currently, device must always be NULL.

The final form of the constructor duplicates another BSimpleGameSound object.

After instantiating the BSimpleGameSound object, you should call InitCheck() to determine whether or not the sound was successfully created.


~BSimpleGameSound

                                                         
  

virtual ~BSimpleGameSound()

A typical destructor.


Member Functions


InitCheck()

                                                         
  

status_t InitCheck(void) const

Returns a status_t indicating whether or not the object was successfully instantiated.

RETURN CODES

B_OK. The sound was successfully initialized.

B_ERROR. Unable to create a sound player.

B_NO_MEMORY. Can't get enough memory to preload the sound.

BSoundFile errors. The sound file may be invalid or incompatible.

Other errors. The sound player may return errors.


SetIsLooping(), IsLooping()

                                                         
  

status_t SetIsLooping(bool looping)
bool IsLooping(void) const

SetIsLooping() turns looping of the sound on if looping is true, or off if looping is false.

IsLooping() returns a flag indicating whether or not looping is currently enabled.

RETURN CODES

B_OK. Looping was turned on or off without error.

B_ERROR. The player wasn't initialized properly.


The Game Kit Table of Contents The Game Kit Index


The Be Book,
...in lovely HTML...
for BeOS Release 4.5.

Copyright © 1999 Be, Inc. All rights reserved.

Text last modified June 4, 1999.