Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. #include "audio.h"
  2. #include "../options.h"
  3. #include <SDL.h>
  4.  
  5. int music_volume = 4;
  6.  
  7. void PHL_AudioInit()
  8. {
  9.     SDL_InitSubSystem(SDL_INIT_AUDIO);
  10.     #ifndef __MORPHOS__
  11.     Mix_Init(MIX_INIT_OGG); // midi is on by default
  12.     #endif
  13.     Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 4096);
  14.  
  15.     PHL_MusicVolume(0.25f * music_volume);
  16. }
  17.  
  18. void PHL_AudioClose()
  19. {
  20.     Mix_CloseAudio();
  21.     #ifndef __MORPHOS__
  22.     Mix_Quit();
  23.     #endif
  24. }
  25.  
  26. //Same as PHL_LoadSound, but expects a file name without extension
  27. PHL_Music PHL_LoadMusic(char* fname, int loop)
  28. {
  29.     PHL_Music ret;
  30.     ret.loop = loop;
  31.     char buff[4096];
  32.     strcpy(buff, "data/");
  33.     strcat(buff, fname);
  34.     strcat(buff, getMusicType()?".ogg":".mid");
  35.     ret.snd = Mix_LoadMUS(buff);
  36.     return ret;
  37. }
  38.  
  39. PHL_Sound PHL_LoadSound(char* fname)
  40. {
  41.     char buff[4096];
  42.     strcpy(buff, "data/");
  43.     strcat(buff, fname);
  44.     return Mix_LoadWAV(buff);
  45. }
  46.  
  47. void PHL_MusicVolume(float vol)
  48. {
  49.     Mix_VolumeMusic(SDL_MIX_MAXVOLUME*vol);
  50. }
  51.  
  52. void PHL_PlayMusic(PHL_Music snd)
  53. {
  54.     if(snd.snd)
  55.         Mix_PlayMusic(snd.snd, snd.loop?-1:0);
  56. }
  57.  
  58. void PHL_PlaySound(PHL_Sound snd, int channel)
  59. {
  60.     Mix_PlayChannel(channel, snd, 0);
  61. }
  62.  
  63. void PHL_StopMusic()
  64. {
  65.     Mix_HaltMusic();
  66. }
  67.  
  68. void PHL_StopSound(PHL_Sound snd, int channel)
  69. {
  70.     Mix_HaltChannel(channel);
  71. }
  72.  
  73. void PHL_FreeMusic(PHL_Music snd)
  74. {
  75.     if(snd.snd)
  76.         Mix_FreeMusic(snd.snd);
  77.     snd.snd = NULL;
  78. }
  79.  
  80. void PHL_FreeSound(PHL_Sound snd)
  81. {
  82.     Mix_FreeChunk(snd);
  83. }
  84.