Homepage Demos Overview Downloads Tutorials Reference
Credits
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Search

SoundPlay.h

Go to the documentation of this file.
00001 #ifndef INCLUDED_SoundPlay_h_
00002 #define INCLUDED_SoundPlay_h_
00003 
00004 #include <OPENR/OObject.h>
00005 #include <OPENR/OSubject.h>
00006 #include <OPENR/OObserver.h>
00007 #include "def.h"
00008 
00009 #include "Events/EventTranslator.h"
00010 
00011 //! The process (a.k.a. OObject), which is responsible for sending sound buffers to the system to play
00012 /*! This sound process will purposely starve the system of sound buffers when nothing is
00013  *  playing, both to eliminate needless zeroing of entire buffers, as well as to reduce system
00014  *  overhead of playing empty buffers.
00015  *
00016  *  If you want to know how to play sounds, you should be looking at SoundManager's documentation.
00017  *  
00018  *  Basically a slightly modified version of the SoundPlay example code from Sony.  Here's their license:
00019  *  Copyright 2002,2003 Sony Corporation 
00020  *
00021  *  Permission to use, copy, modify, and redistribute this software for
00022  *  non-commercial use is hereby granted.
00023  *
00024  *  This software is provided "as is" without warranty of any kind,
00025  *  either expressed or implied, including but not limited to the
00026  *  implied warranties of fitness for a particular purpose.
00027  */
00028 class SoundPlay : public OObject {
00029  public:
00030   SoundPlay();            //!< constructor
00031   virtual ~SoundPlay() {} //!< destructor
00032 
00033   virtual OStatus DoInit   (const OSystemEvent& event); //!< called by system when time to do init
00034   virtual OStatus DoStart  (const OSystemEvent& event); //!< called by system when time to start running
00035   virtual OStatus DoStop   (const OSystemEvent& event); //!< called by system when time to stop running
00036   virtual OStatus DoDestroy(const OSystemEvent& event); //!< called by system when time to free
00037 
00038   void ReadySendSound(const OReadyEvent& event);            //!< called by system when it's ready for another sound buffer
00039   void ReadyRegisterSoundManager(const OReadyEvent& event); //!< called by system when observers are ready to receive the SoundManager
00040   void GotEventTranslatorQueue(const ONotifyEvent& event);  //!< called by system when the queue for sending events to Main is being published
00041 
00042   void GotSoundMsg(const ONotifyEvent& event); //!< called by system when SoundManager has sent itself a message on a different process (either to add or remove sounds from memory)
00043 
00044   OSubject*  subject[numOfSubject];   //!< array of subject IDs, used to identify outgoing data
00045   OObserver* observer[numOfObserver]; //!< array of observer IDs, used to identify what's ready
00046 
00047  private:
00048   void      doSendSound();                 //!< called to send sound buffer(s) to system
00049   void      OpenSpeaker();                 //!< initializes speaker
00050   void      NewSoundVectorData();          //!< sets up sound buffers
00051   void      SetPowerAndVolume();           //!< sets volume to max
00052   RCRegion* InitRegion(unsigned int size); //!< inits each buffer
00053   RCRegion* FindFreeRegion();              //!< finds the first sound buffer which system isn't using (buffers are recycled)
00054     
00055   static const char* const SPEAKER_LOCATOR = "PRM:/r1/c1/c2/c3/s1-Speaker:S1"; //!< ID for speaker in system
00056   static const size_t SOUND_NUM_BUFFER = 2;                                    //!< number of buffers to use
00057   
00058   unsigned int active; //!< number of active sound channels - if it's 0, we'll purposely starve system of sound buffers
00059 
00060   RCRegion*      soundManagerMemRgn; //!< SoundPlay creates, Main & Motion receive - Shared region used by SoundManager
00061   RCRegion*      eventTranslatorQueueMemRgn; //!< Main creates, Motion (& SoundPlay) receive
00062   EventTranslator etrans; //!< will be given all events created by SoundManager to be forwarded to Main
00063 
00064   OPrimitiveID   speakerID;  //!< ID returned to system after opening SPEAKER_LOCATOR
00065   RCRegion*      region[SOUND_NUM_BUFFER]; //!< holds references to shared regions holding sound clips
00066 };
00067 
00068 /*! @file
00069  * @brief Describes the SoundPlay process (a.k.a. OObject), which is responsible for sending sound buffers to the system to play
00070  * @author Sony (Creator)
00071  *
00072  * This is basically the SoundPlay example from the Sony code, with a few modifications.
00073  * Here's the license Sony provided with it:
00074  *
00075  * Copyright 2002,2003 Sony Corporation 
00076  *
00077  * Permission to use, copy, modify, and redistribute this software for
00078  * non-commercial use is hereby granted.
00079  *
00080  * This software is provided "as is" without warranty of any kind,
00081  * either expressed or implied, including but not limited to the
00082  * implied warranties of fitness for a particular purpose.
00083  *
00084  * $Author: ejt $
00085  * $Name: tekkotsu-1_4_1 $
00086  * $Revision: 1.3 $
00087  * $State: Exp $
00088  * $Date: 2003/04/09 03:33:57 $
00089  */
00090 
00091 #endif // SoundPlay_h_DEFINED

Tekkotsu v1.4
Generated Sat Jul 19 00:06:31 2003 by Doxygen 1.3.2