enigma-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Enigma-cvs] enigma/src sound.hh,1.6,1.7 sound.cc,1.20,1.21


From: Daniel Heck <address@hidden>
Subject: [Enigma-cvs] enigma/src sound.hh,1.6,1.7 sound.cc,1.20,1.21
Date: Sun, 16 Nov 2003 19:30:19 +0000

Update of /cvsroot/enigma/enigma/src
In directory subversions:/tmp/cvs-serv17489/src

Modified Files:
        sound.hh sound.cc 
Log Message:
* src/sound.cc: Use new options:: code.  PlayMusic(), StopMusic()
take std::string.

* src/sound.hh: PlayMusic(), StopMusic() take std::string.


Index: sound.cc
===================================================================
RCS file: /cvsroot/enigma/enigma/src/sound.cc,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** sound.cc    27 Oct 2003 11:53:17 -0000      1.20
--- sound.cc    16 Nov 2003 19:30:17 -0000      1.21
***************
*** 59,62 ****
--- 59,83 ----
  /* -------------------- Functions -------------------- */
  
+ static Mix_Chunk *
+ cache_sound(const std::string &name)
+ {
+     px::Dict<Mix_Chunk*>::iterator i=wav_cache.find(name);
+     if (i == wav_cache.end()) {
+         string filename = enigma::FindDataFile("sound/" + name + ".wav");
+         Mix_Chunk *ch = 0;
+ 
+         ch = enigma::oxyd::LoadSound(name);
+         if (ch == 0)
+             ch = Mix_LoadWAV(filename.c_str());
+ 
+         if (ch != 0)
+             wav_cache.insert(name, ch);
+         else
+           enigma::Log << "Couldn't load sample: " << Mix_GetError() << endl;
+         return ch;
+     } else
+         return i->second;
+ }
+ 
  void sound::Init() {
      // Do nothing if user doesn't want sound or mixer lib is already
***************
*** 85,91 ****
          return;                 // SDL_mixer crashes without this check
  
!     int soundvol = int(options::SoundVolume * MIX_MAX_VOLUME);
      Mix_Volume (-1, Clamp (soundvol, 0, MIX_MAX_VOLUME));
!     int musicvol = int(options::MusicVolume * MIX_MAX_VOLUME);
      Mix_VolumeMusic (Clamp (musicvol, 0, MIX_MAX_VOLUME));
  }
--- 106,112 ----
          return;                 // SDL_mixer crashes without this check
  
!     int soundvol = int(options::GetDouble("SoundVolume") * MIX_MAX_VOLUME);
      Mix_Volume (-1, Clamp (soundvol, 0, MIX_MAX_VOLUME));
!     int musicvol = int(options::GetDouble("MusicVolume") * MIX_MAX_VOLUME);
      Mix_VolumeMusic (Clamp (musicvol, 0, MIX_MAX_VOLUME));
  }
***************
*** 128,152 ****
  }
  
- static Mix_Chunk *
- cache_sound(const std::string &name)
- {
-     px::Dict<Mix_Chunk*>::iterator i=wav_cache.find(name);
-     if (i == wav_cache.end()) {
-         string filename = enigma::FindDataFile("sound/" + name + ".wav");
-         Mix_Chunk *ch = 0;
- 
-         ch = enigma::oxyd::LoadSound(name);
-         if (ch == 0)
-             ch = Mix_LoadWAV(filename.c_str());
- 
-         if (ch != 0)
-             wav_cache.insert(name, ch);
-         else
-           enigma::Log << "Couldn't load sample: " << Mix_GetError() << endl;
-         return ch;
-     } else
-         return i->second;
- }
- 
  void sound::SetListenerPosition (const px::V2 &pos) {
      listener_pos = pos;
--- 149,152 ----
***************
*** 163,167 ****
      double dist = max(0.0, length(distv) - fullvol_range);
  
!     int xdist = int(distv[0] * options::StereoSeparation);
      int left  = px::Clamp (255 - xdist, 0, 255);
      int right = px::Clamp (255 + xdist, 0, 255);
--- 163,167 ----
      double dist = max(0.0, length(distv) - fullvol_range);
  
!     int xdist = int(distv[0] * options::GetDouble("StereoSeparation"));
      int left  = px::Clamp (255 - xdist, 0, 255);
      int right = px::Clamp (255 + xdist, 0, 255);
***************
*** 172,176 ****
      if (Mix_Chunk *chunk = cache_sound(name)) {
        int channel = -1; //Mix_GroupOldest(-1);
!       int mixvol = int(volume * options::SoundVolume * MIX_MAX_VOLUME);
  
          channel = Mix_PlayChannel(channel, chunk, 0);
--- 172,176 ----
      if (Mix_Chunk *chunk = cache_sound(name)) {
        int channel = -1; //Mix_GroupOldest(-1);
!       int mixvol = int(volume * options::GetDouble("SoundVolume") * 
MIX_MAX_VOLUME);
  
          channel = Mix_PlayChannel(channel, chunk, 0);
***************
*** 196,200 ****
  }
  
! void sound::PlayMusic(const char *name) {
      if (!sound_enabled || !music_enabled || name==current_music_name)
          return;
--- 196,200 ----
  }
  
! void sound::PlayMusic (const std::string &name) {
      if (!sound_enabled || !music_enabled || name==current_music_name)
          return;
***************
*** 225,240 ****
  }
  
! void sound::StopMusic(const char *name) {
      if (name==current_music_name)
          StopMusic();
  }
  
! /* SDL_ConvertAudio is not very good at audio resampling since it is
!    only capable of changing the sound frequency by integer powers of 2
!    (i.e., by a factor of ... 1/4 1/2 1 2 ...).  The sound files used
!    by Oxyd are sampled at 6kHz which we must convert to roughly 22kHz.
!    This function resamples between any two frequencies using simple
!    linear interpolation.  It is not capable of changing the sample
!    format or dealing with more than one channel.
  */
  namespace
--- 225,244 ----
  }
  
! void sound::StopMusic (const std::string &name) {
      if (name==current_music_name)
          StopMusic();
  }
  
! /* SDL_ConvertAudio is only capable of changing the sound frequency by
!    integer powers of 2 (i.e., by a factor of ... 1/4 1/2 1 2 ...).
!    The sound files used by Oxyd are sampled at 6kHz which we must
!    convert to roughly 22kHz.  This function resamples between any two
!    frequencies using simple linear interpolation.  It is not capable
!    of changing the sample format or dealing with more than one
!    channel.
! 
!    FIXME: We should apply a lowpass filter after reampling to get rid
!    of the artifacts introduced by linear interpolation or use a better
!    interpolator.
  */
  namespace
***************
*** 268,276 ****
          return newdata;
      }
- 
- #ifndef HAVE_MIX_QUICKLOAD
- 
- #endif
- 
  }
  
--- 272,275 ----
***************
*** 281,298 ****
          return 0;
  
!     // get destination format
      int dfreq, dchannels;
      Uint16 dformat;
      Mix_QuerySpec (&dfreq, &dformat, &dchannels);
-     enigma::Log << "converting: (" << sfreq <<","<<schannels
-                 << ") to (" << dfreq <<","<<dchannels << endl;
  
!     // resample
      Uint32 newlen=0;
      Uint8 *newbuf = 
reinterpret_cast<Uint8*>(resample(reinterpret_cast<Sint8*>(const_cast<Uint8*>(buf)),
                                                        len, sfreq, dfreq, 
&newlen));
  
! 
!     // convert audio data
      SDL_AudioCVT cvt;
      if (!SDL_BuildAudioCVT (&cvt, sformat, schannels, dfreq,
--- 280,294 ----
          return 0;
  
!     // Get destination format
      int dfreq, dchannels;
      Uint16 dformat;
      Mix_QuerySpec (&dfreq, &dformat, &dchannels);
  
!     // Resample
      Uint32 newlen=0;
      Uint8 *newbuf = 
reinterpret_cast<Uint8*>(resample(reinterpret_cast<Sint8*>(const_cast<Uint8*>(buf)),
                                                        len, sfreq, dfreq, 
&newlen));
  
!     // Convert audio data
      SDL_AudioCVT cvt;
      if (!SDL_BuildAudioCVT (&cvt, sformat, schannels, dfreq,

Index: sound.hh
===================================================================
RCS file: /cvsroot/enigma/enigma/src/sound.hh,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** sound.hh    7 Jul 2003 21:14:05 -0000       1.6
--- sound.hh    16 Nov 2003 19:30:17 -0000      1.7
***************
*** 24,27 ****
--- 24,29 ----
  #include "px/math.hh"
  
+ #include <string>
+ 
  namespace sound
  {
***************
*** 40,47 ****
  
      void PlaySound(const char *name);
!     void PlayMusic(const char *name);
      void FadeoutMusic();
      void StopMusic();
!     void StopMusic(const char *name);
  
      /* This function converts raw audio data with a specified format
--- 42,49 ----
  
      void PlaySound(const char *name);
!     void PlayMusic (const std::string &name);
      void FadeoutMusic();
      void StopMusic();
!     void StopMusic(const std::string &name);
  
      /* This function converts raw audio data with a specified format
***************
*** 51,58 ****
                               int freq, int format, int channels);
  
      void ClearSoundCache();
  
!     /* Set the sound and music volume according to the settings in
!        namespace options:: */
      void UpdateVolume();
  }
--- 53,62 ----
                               int freq, int format, int channels);
  
+     /* Remove all cached sound files from memory.  This is used to
+        free unused memory when switching to another sound set. */
      void ClearSoundCache();
  
!     /* Set the sound and music volume to the values in
!        options::SoundVolume and options::MusicVolume. */
      void UpdateVolume();
  }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]