Homepage | Demos | Overview | Downloads | Tutorials | Reference | Credits |
SoundPlay.hGo 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 size_t SOUND_NUM_BUFFER = 2; //!< number of buffers to use 00056 00057 unsigned int active; //!< number of active sound channels - if it's 0, we'll purposely starve system of sound buffers 00058 00059 RCRegion* soundManagerMemRgn; //!< SoundPlay creates, Main & Motion receive - Shared region used by SoundManager 00060 RCRegion* eventTranslatorQueueMemRgn; //!< Main creates, Motion (& SoundPlay) receive 00061 EventTranslator etrans; //!< will be given all events created by SoundManager to be forwarded to Main 00062 00063 OPrimitiveID speakerID; //!< ID returned to system after opening SPEAKER_LOCATOR 00064 RCRegion* region[SOUND_NUM_BUFFER]; //!< holds references to shared regions holding sound clips 00065 00066 SoundPlay(const SoundPlay&); //!< don't call 00067 SoundPlay& operator=(const SoundPlay&); //!< don't call 00068 }; 00069 00070 /*! @file 00071 * @brief Describes the SoundPlay process (a.k.a. OObject), which is responsible for sending sound buffers to the system to play 00072 * @author Sony (Creator) 00073 * 00074 * This is basically the SoundPlay example from the Sony code, with a few modifications. 00075 * Here's the license Sony provided with it: 00076 * 00077 * Copyright 2002,2003 Sony Corporation 00078 * 00079 * Permission to use, copy, modify, and redistribute this software for 00080 * non-commercial use is hereby granted. 00081 * 00082 * This software is provided "as is" without warranty of any kind, 00083 * either expressed or implied, including but not limited to the 00084 * implied warranties of fitness for a particular purpose. 00085 * 00086 * $Author: ejt $ 00087 * $Name: tekkotsu-2_2_2 $ 00088 * $Revision: 1.5 $ 00089 * $State: Exp $ 00090 * $Date: 2003/12/23 06:33:44 $ 00091 */ 00092 00093 #endif // SoundPlay_h_DEFINED |
Tekkotsu v2.2.2 |
Generated Tue Jan 4 15:43:15 2005 by Doxygen 1.4.0 |