Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
al_init.cpp File Reference
#include "audiolib.h"
#include "config_xml.h"
#include "xml_support.h"
#include "vs_globals.h"

Go to the source code of this file.

Functions

void AUDChangeVolume (float volume)
 Changes the volume (generally 0 or between 1 and 1000) More...
 
float AUDGetVolume ()
 
void AUDChangeDoppler (float doppler)
 changes the scale used for doppler...generally between 0 for off or .01 and 10 More...
 
float AUDGetDoppler ()
 Gets current doppler val. More...
 
bool AUDInit ()
 
void AUDDestroy ()
 

Function Documentation

void AUDChangeDoppler ( float  doppler)

changes the scale used for doppler...generally between 0 for off or .01 and 10

Definition at line 102 of file al_init.cpp.

Referenced by decdop(), and incdop().

103 {
104 #ifdef HAVE_AL
105  if (doppler <= 0)
106  usedoppler = false;
107  else
108  usedoppler = true;
109  scalevel = doppler;
110 #endif
111 }
void AUDChangeVolume ( float  volume)

Changes the volume (generally 0 or between 1 and 1000)

Definition at line 81 of file al_init.cpp.

References volume.

Referenced by decvol(), and incvol().

82 {
83 #ifdef HAVE_AL
84  if (volume == 0) {
85  usepositional = false;
86  return;
87  } else {
88  usepositional = true;
89  }
90  scalepos = 1./volume;
91 #endif
92 }
void AUDDestroy ( )

Definition at line 204 of file al_init.cpp.

References AUDDeleteSound(), AUDStopPlaying(), buffer, and i.

Referenced by cleanup().

205 {
206 #ifdef HAVE_AL
207  //Go through and delete all loaded wavs
208  unsigned int i;
209  for (i = 0; i < sounds.size(); i++) {
210  if (sounds[i].buffer != 0)
211  AUDStopPlaying( i );
212  AUDDeleteSound( i );
213  }
214  for (i = 0; i < unusedsrcs.size(); i++)
215  alDeleteSources( 1, &unusedsrcs[i] );
216  for (i = 0; i < buffers.size(); i++)
217  alDeleteBuffers( 1, &buffers[i] );
218  buffers.clear();
219  if (context_id)
220  alcDestroyContext( (ALCcontext*) context_id );
221  if (dev)
222  alcCloseDevice( dev );
223 #endif
224 }
float AUDGetDoppler ( )

Gets current doppler val.

Definition at line 112 of file al_init.cpp.

Referenced by decdop(), and incdop().

113 {
114 #ifdef HAVE_AL
115  return scalevel;
116 
117 #else
118  return 1;
119 #endif
120 }
float AUDGetVolume ( )

Definition at line 93 of file al_init.cpp.

Referenced by decvol(), and incvol().

94 {
95 #ifdef HAVE_AL
96  return 1./scalepos;
97 
98 #else
99  return 1;
100 #endif
101 }
bool AUDInit ( )

Definition at line 132 of file al_init.cpp.

References game_data_t::audio_frequency_mode, g_game, VegaConfig::getVariable(), game_data_t::max_sound_sources, game_data_t::music_enabled, XMLSupport::parse_bool(), XMLSupport::parse_float(), XMLSupport::parse_int(), game_data_t::sound_enabled, and vs_config.

Referenced by main().

133 {
135  g_game.music_enabled = false;
136 #ifdef HAVE_AL
137  usedoppler = XMLSupport::parse_bool( vs_config->getVariable( "audio", "Doppler", "false" ) );
138  usepositional = XMLSupport::parse_bool( vs_config->getVariable( "audio", "Positional", "true" ) );
139  double linuxadjust=1;
140 #ifndef _WIN32
141 #ifndef __APPLE__
142  linuxadjust=1./3.;
143 #endif
144 #endif
145  scalepos = 1.0f/(XMLSupport::parse_float( vs_config->getVariable( "audio", "Volume", "100" ) )
146  *linuxadjust
147  );
148  scalevel = XMLSupport::parse_float( vs_config->getVariable( "audio", "DopplerScale", "1" ) );
149  //enabled = XMLSupport::parse_bool (vs_config->getVariable ("audio","enabled","true"));
150  g_game.audio_frequency_mode = XMLSupport::parse_int( vs_config->getVariable( "audio", "frequency", "48000" ) );
151  maxallowedsingle = XMLSupport::parse_int( vs_config->getVariable( "audio", "MaxSingleSounds", "8" ) );
153  maxallowedtotal = XMLSupport::parse_int( vs_config->getVariable( "audio", "MaxTotalSounds", "20" ) );
154  bool sound_enabled = XMLSupport::parse_bool( vs_config->getVariable( "audio", "Sound", "true" ) );
155  bool music_enabled = XMLSupport::parse_bool( vs_config->getVariable( "audio", "Music", "true" ) );
156  if (!sound_enabled && !music_enabled)
157  return false;
158  int attrlist[] = {ALC_FREQUENCY, g_game.audio_frequency_mode, 0};
159 #ifdef _WIN32
160  dev = alcOpenDevice( (ALCchar*)"DirectSound3D" );
161  // dev = alcOpenDevice( (ALCubyte*)"DirectSound3D" ); pre update. New includes barf on ubyte. cannot convert parameter.
162 #else
163 #ifdef __APPLE__
164  dev = alcOpenDevice( "sdl" );
165  if (dev == NULL)
166  dev = alcOpenDevice( NULL );
167 #else
168  dev = alcOpenDevice( NULL );
169 #endif
170 #endif
171  if (dev == NULL)
172  return false;
173  context_id = alcCreateContext( dev, attrlist );
174  if (context_id == NULL) {
175  alcCloseDevice( dev );
176  return false;
177  }
178  alcMakeContextCurrent( (ALCcontext*) context_id );
179 
180  fixup_function_pointers();
181  ALenum alGetEr = 0;
182  ALuint cursrc;
183  alGetError();
184  alGenSources( 1, &cursrc );
185  alGetEr = alGetError();
186  while (alGetEr == 0) {
187  unusedsrcs.push_back( cursrc );
188  if (unusedsrcs.size() >= maxallowedtotal)
189  break;
190  alGenSources( 1, &cursrc );
191  alGetEr = alGetError();
192  }
193 
194  alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);
195 
196  g_game.sound_enabled = sound_enabled;
197  g_game.music_enabled = music_enabled;
198 
199  return true;
200 #endif
201  return false;
202 }