home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 123 / cdrom123.iso / edu / tux / Tuxtype2-1.5.3-installer.exe / src / audio.c < prev    next >
Encoding:
C/C++ Source or Header  |  2004-01-21  |  2.2 KB  |  68 lines

  1. /***************************************************************************
  2.  -  file: audio.c
  3.  -  description: this file contains audio related functions
  4.                             -------------------
  5.     begin                : Jan 22, 2003
  6.     copyright            : Sam Hart, Jesse Andrews (C) 2003
  7.     email                : tuxtype-dev@tux4kids.net
  8. ***************************************************************************/
  9.  
  10. /***************************************************************************
  11. *                                                                         *
  12. *   This program is free software; you can redistribute it and/or modify  *
  13. *   it under the terms of the GNU General Public License as published by  *
  14. *   the Free Software Foundation; either version 2 of the License, or     *
  15. *   (at your option) any later version.                                   *
  16. *                                                                         *
  17. ***************************************************************************/
  18.  
  19. #include "globals.h"
  20. #include "funcs.h"
  21.  
  22. Mix_Chunk      *sound[NUM_WAVES];
  23. Mix_Music      *music;
  24.  
  25. void playsound(Mix_Chunk *snd) {
  26.     if (!sys_sound) return;
  27.  
  28.     Mix_PlayChannel(-1, snd, 0);
  29. }
  30.  
  31. Mix_Music *defaultMusic = NULL; // holds music for audioMusicLoad/unload
  32.  
  33. /* audioMusicLoad attempts to load and play the music file 
  34.  * Note: loops == -1 means forever
  35.  */
  36. void audioMusicLoad( char *musicFilename, int loops ) {
  37.     if (!sys_sound) return;
  38.  
  39.     audioMusicUnload(); // make sure defaultMusic is clear
  40.  
  41.     defaultMusic = LoadMusic( musicFilename );
  42.     Mix_PlayMusic( defaultMusic, loops );
  43. }
  44.  
  45. /* audioMusicUnload attempts to unload any music data that was
  46.  * loaded using the audioMusicLoad function
  47.  */
  48. void audioMusicUnload( void ) {
  49.     if (!sys_sound) return;
  50.  
  51.     if ( defaultMusic )
  52.         Mix_FreeMusic( defaultMusic );
  53.  
  54.     defaultMusic=NULL;
  55. }
  56.  
  57. /* audioMusicPlay attempts to play the passed music data. 
  58.  * if a music file was loaded using the audioMusicLoad
  59.  * it will be stopped and unloaded
  60.  * Note: loops == -1 means forever
  61.  */
  62. void audioMusicPlay( Mix_Music *musicData, int loops ) { 
  63.     if (!sys_sound) return;
  64.  
  65.     audioMusicUnload();    
  66.     Mix_PlayMusic( musicData, loops );
  67. }
  68.