home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 February / maximum-cd-2009-02.iso / DiscContents / SMC_1.6_win32.exe / src / audio / audio.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-08-25  |  6.2 KB  |  217 lines

  1. /***************************************************************************
  2.  * audio.h  -  header for the corresponding cpp file
  3.  *
  4.  * Copyright (C) 2003 - 2008 Florian Richter
  5.  ***************************************************************************/
  6. /*
  7.    This program is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License as published by
  9.    the Free Software Foundation; either version 3 of the License, or
  10.    (at your option) any later version.
  11.    
  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  14. */
  15.  
  16. #ifndef SMC_AUDIO_H
  17. #define SMC_AUDIO_H
  18.  
  19. #include "../core/globals.h"
  20. #include "../audio/sound_manager.h"
  21.  
  22. /* *** *** *** *** *** *** *** Sound Resource ID's  *** *** *** *** *** *** *** *** *** *** */
  23.  
  24. // sounds which shouldn't be played multiple times at the same time
  25. enum AudioChannel
  26. {
  27.     RID_MARYO_JUMP        = 1,
  28.     RID_MARYO_TOCK        = 2,
  29.     RID_MARYO_POWERDOWN = 3,
  30.     RID_MARYO_DEATH        = 5,
  31.     RID_MARYO_BALL        = 4,
  32.     RID_MARYO_AU        = 8,
  33.     RID_MARYO_STOP        = 9,
  34.  
  35.     RID_FIREPLANT        = 6,
  36.     RID_MUSHROOM_BLUE    = 6,
  37.     RID_MUSHROOM_GHOST    = 6,
  38.     RID_MUSHROOM        = 6,
  39.     RID_FEATHER            = 6,
  40.     RID_1UP_MUSHROOM    = 7,
  41.     RID_MOON            = 7
  42. };
  43.  
  44. /* *** *** *** *** *** *** *** Audio Sound object *** *** *** *** *** *** *** *** *** *** */
  45.     
  46. // Callback for a sound finished playing 
  47. void Finished_Sound( int channel );
  48.  
  49. class cAudio_Sound
  50. {
  51. public:
  52.     cAudio_Sound( void );
  53.     virtual ~cAudio_Sound( void );
  54.     
  55.     // Load the data
  56.     void Load( cSound *data );
  57.     // Free the data
  58.     void Free( void );
  59.     // Finished playing
  60.     void Finished( void );
  61.  
  62.     /* Play the Sound
  63.      * use_res_id: if set stops all sounds using the same resource id.
  64.      * loops : if set to -1 loops indefinitely or if greater than zero, loop the sound that many times.
  65.     */
  66.     int Play( int use_res_id = -1, int loops = 0 );
  67.     // Stop the Sound if playing
  68.     void Stop( void );
  69.  
  70.     // sound object
  71.     cSound *m_data;
  72.  
  73.     // channel if playing else -1
  74.     int m_channel;
  75.     // the last used resource id
  76.     int m_resource_id;
  77. };
  78.  
  79. typedef vector<cAudio_Sound *> AudioSoundList;
  80.  
  81. /* *** *** *** *** *** *** *** Audio class *** *** *** *** *** *** *** *** *** *** */
  82.  
  83. class cAudio
  84. {
  85. public:
  86.     cAudio( void );
  87.     ~cAudio( void );
  88.  
  89.     // Initialize Audio Engine
  90.     bool Init( void );
  91.     // De-initializes Audio Engine
  92.     void Close( void );
  93.  
  94.     // Set the maximum number of sounds playable at once
  95.     void Set_Max_Sounds( unsigned int limit = 10 );
  96.  
  97.     /* Check if the sound was already loaded and returns a pointer to it else it will be loaded.
  98.      * The returned sound should not be deleted or modified.
  99.      */
  100.     cSound *Get_Sound_File( string filename );
  101.  
  102.     // Play the given sound
  103.     bool Play_Sound( string filename, int res_id = -1, int volume = -1, int loops = 0 );
  104.     // If no forcing it will be played after the current Music file
  105.     bool Play_Music( string filename, int loops = 0, bool force = 1, unsigned int fadein_ms = 0 ); 
  106.  
  107.     /* Returns a pointer to the sound if it is active.
  108.      * The returned sound should not be deleted or modified.
  109.      */
  110.     cAudio_Sound *Get_Playing_Sound( string filename );
  111.  
  112.     /* Returns true if a free channel for the sound is available
  113.     */
  114.     cAudio_Sound *Create_Sound_Channel( void );
  115.  
  116.     // Toggle Music on/off
  117.     void Toggle_Music( void );
  118.     // Toggle Sounds on/off
  119.     void Toggle_Sounds( void );
  120.  
  121.     // Pause Music
  122.     void Pause_Music( void );
  123.  
  124.     /* Resume halted sound
  125.      * if channel is -1 all halted sounds will be resumed
  126.     */
  127.     void Resume_Sound( int channel = -1 );
  128.     // Resume Music
  129.     void Resume_Music( void );
  130.  
  131.     /* Fade out Sound(s)
  132.      * ms : the time to fade out
  133.      * channel : if set only fade this channel out or if -1 all channels
  134.      * overwrite_fading : overwrite an already existing fade out
  135.     */
  136.     void Fadeout_Sounds( unsigned int ms = 200, int channel = -1, bool overwrite_fading = 0 );
  137.     /* Fade out Sound(s)
  138.      * ms : the time to fade out
  139.      * filename : fade all sounds with this filename out
  140.      * overwrite_fading : overwrite an already existing fade out
  141.     */
  142.     void Fadeout_Sounds( unsigned int ms, string filename, bool overwrite_fading = 0 );
  143.     /* Fade out Music
  144.      * ms : the time to fade out
  145.      * overwrite_fading : overwrite an already existing fade out
  146.     */
  147.     void Fadeout_Music( unsigned int ms = 500, bool overwrite_fading = 0 );
  148.  
  149.     // Set the Music position ( if .ogg in seconds )
  150.     void Set_Music_Position( float position );
  151.  
  152.     // Returns 1 if the Music is currently fading in and 2 if it's fading out else 0
  153.     Mix_Fading Is_Music_Fading( void );
  154.     // Returns 1 if the Sound is currently fading in and 2 if it's fading out else 0
  155.     Mix_Fading Is_Sound_Fading( int sound_channel );
  156.  
  157.     // Returns true if the Music is paused
  158.     bool Is_Music_Paused( void );
  159.     // Returns true if the Music is playing
  160.     bool Is_Music_Playing( void );
  161.  
  162.     // Halt the given sounds
  163.     void Halt_Sounds( int channel = -1 );
  164.     // Halt the Music
  165.     void Halt_Music( void );
  166.  
  167.     // Stop all sounds
  168.     void Stop_Sounds( void ); 
  169.  
  170.     // Set the Sound Volume
  171.     void Set_Sound_Volume( Uint8 volume, int channel = -1 );
  172.     // Set the Music Volume
  173.     void Set_Music_Volume( Uint8 volume );
  174.  
  175.     // Update the Audio Engine
  176.     void Update( void );
  177.  
  178.     // is the audio engine initialized
  179.     bool initialised;
  180.     // is sound enabled
  181.     bool sound_enabled;
  182.     // is music enabled
  183.     bool music_enabled;
  184.     // is the debug mode enabled
  185.     bool debug;
  186.  
  187.     // current music and sound volume
  188.     Uint8 sound_volume, music_volume;
  189.  
  190.     // current playing Music pointer
  191.     Mix_Music *music;
  192.     // if new music should play after the current this is the old data
  193.     Mix_Music *music_old;
  194.  
  195.     // The current sounds pointer array
  196.     AudioSoundList sounds;
  197.  
  198.     // maximum sounds allowed at once
  199.     unsigned int max_sounds;
  200.     // last used sound array buffer
  201.     unsigned int sound_count;
  202.  
  203.     // initialization information
  204.     int audio_buffer, audio_channels;
  205.     // sound and music played counter since initialization
  206.     unsigned int sounds_played, music_played;
  207. };
  208.  
  209. /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
  210.  
  211. // Audio Handler
  212. extern cAudio *pAudio;
  213.  
  214. /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
  215.  
  216. #endif
  217.