Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members

SoundEngine.h

Go to the documentation of this file.
00001 /*********************************************************************************
00002  *
00003  * Razor! Engine - A modular C++ presentation engine
00004  *
00005  * $Id$
00006  *
00007  * Copyright (c) 2000 Tilo Christ. All Rights Reserved.
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  *
00014  * This library is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Lesser General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public
00020  * License along with this library; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022  *
00023  **********************************************************************************/
00024 
00025 
00026 
00027 #ifndef SOUND_ENGINE_H
00028 #define SOUND_ENGINE_H
00029 
00030 #include <PalmOS.h>
00031 #include "Customization.h"
00032 
00033 
00034 #ifdef NO_SOUND
00035 
00036 class SoundEngine
00037 {
00038     public:
00039 
00040     static void timeTick();
00041 
00042     private:
00043     SoundEngine() {};
00044     ~SoundEngine() {};
00045 
00046     static void init();
00047     static void destroy();
00048 
00049     friend class Presentation;
00050 };
00051 
00052 #else
00053 
00054 
00055 class MusicEngine;
00056 class FxEngine;
00057 
00058 
00059 /**
00060  * SoundEngine is a facade for sound output from two different sources (music, FX).
00061  */
00062 class SoundEngine
00063 {
00064     public:     
00065     /**
00066      * Play a sound effect which is stored in a resource of type 'Tsfx' with the
00067      * specified resource ID.
00068      *
00069      * @param resID the ID of the 'Tsfx' resource
00070      */
00071     static void playFx(DmResID resID);
00072     
00073     /**
00074      * Play a song where the sequence of patterns is stored in a resource of type
00075      * 'Ttrk' with the specified resource ID. 
00076      * The patterns themselves are stored in resources of type 'Tpat' where the 
00077      * pattern ID is the resource ID.
00078      *
00079      * @param resID the ID of the 'Ttrk' resource
00080      */
00081     static void playSong(DmResID resID);
00082     
00083     
00084     /**
00085      * Stop the currently playing song.
00086      */
00087     static void stopSong();
00088     
00089 
00090     /**
00091      * This method needs to be invoked periodically, in order for SoundEngine
00092      * to work.
00093      */
00094     static void timeTick();
00095 
00096 
00097     private:    
00098     // SoundEngine cannot be instantiated or destroyed.
00099     SoundEngine() {}    
00100     ~SoundEngine() {}
00101 
00102     static void init();
00103     static void destroy();
00104 
00105     static FxEngine *fxEngine;
00106     static MusicEngine *musicEngine;
00107 
00108     static UInt16 baseAmplitude;
00109     static Boolean mute;
00110     static UInt32 nextTimer;
00111 
00112 
00113     friend class Presentation;
00114 };
00115 
00116 
00117 
00118 /**
00119  * FxEngine can play sound fx.
00120  */
00121 class FxEngine
00122 {
00123     private:
00124     
00125     FxEngine(UInt16 baseAmplitude);
00126     ~FxEngine();
00127     
00128     /**
00129      * Play the next portion of the sound.
00130      *
00131      * @return true = sound has been played, false = no sound has been played
00132      */
00133     Boolean timeTick();
00134     
00135     void playFx(DmResID resID);
00136 
00137 
00138     Boolean playing;
00139     DmResID fxResID;
00140     UInt16 fxPosition;
00141     UInt16 baseAmplitude;
00142 
00143     /// A frequency with value FREQ_END means, that the end of the sound effect has been reached.
00144     static const UInt16 FREQ_END = 0x0000;
00145     /// A duration with value DURATION_YIELD means, that timeTick() shall return control to the caller.
00146     static const UInt8 DURATION_YIELD = 0x00;
00147 
00148     friend class SoundEngine;
00149 };
00150 
00151 
00152 /**
00153  * MusicEngine can playback music. It is based on a pattern model,
00154  * comparable to that of MOD players, and it can fake three channels.
00155  */
00156 class MusicEngine
00157 {
00158     private:
00159 
00160     MusicEngine(UInt16 baseAmplitude);
00161     ~MusicEngine();
00162 
00163 
00164     /**
00165      * Play the next portion of the sound.
00166      *
00167      * @return true = sound has been played, false = no sound has been played
00168      */
00169     Boolean timeTick();
00170 
00171     void playSong(DmResID resID);
00172     void stopSong();
00173 
00174     void setPatternsFromTrack();
00175 
00176     void playNote(UInt16 note, UInt16 octave, UInt16 amplitude, UInt16 duration, Boolean wait) const;
00177     void playMute(UInt16 duration, Boolean wait) const;
00178 
00179     void hitIt(UInt16 position, UInt16 pattern, UInt16 amplitude, UInt16 duration, Boolean wait) const;
00180 
00181 
00182     DmResID trackResID;
00183     UInt16 trackPosition;
00184     UInt16 channel1Pattern;
00185     UInt16 channel2Pattern;
00186     UInt16 channel3Pattern;
00187     
00188     UInt16 pattern;
00189     UInt16 patternPosition;
00190 
00191     Boolean playing;
00192     Boolean channel1Playing;
00193     Boolean channel2Playing;
00194     Boolean channel3Playing;
00195 
00196     UInt16 baseDuration;
00197     UInt16 baseAmplitude;
00198 
00199     static const UInt8 CHANNEL_MUTE = 0xFD;
00200     static const UInt8 TRACK_REPEAT = 0xFE;
00201     static const UInt8 TRACK_END    = 0xFF;
00202 
00203     friend class SoundEngine;
00204 };
00205 
00206 
00207 #endif // !NO_SOUND
00208 
00209 #endif

Razor! Engine Developer's Guide. Copyright © by Tilo Christ. All Rights Reserved. Last updated: 4 Nov 2000