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
softvolume.h File Reference

Go to the source code of this file.

Enumerations

enum  Mix_SoftVolume_Shape { MIX_SV_SHAPE_LINEAR, MIX_SV_SHAPE_EXP, MIX_SV_SHAPE_EASED, MIX_SV_SHAPE_EASED_EXP }
 

Functions

void Mix_SoftVolume_Change (int chan, double newvolume, double time, Mix_SoftVolume_Shape shape)
 
void Mix_SoftVolume_Force (int chan, double newvolume)
 
double Mix_SoftVolume_GetCurrentVolume (int chan)
 
void Mix_SoftVolume_AutoStopMusic (int chan, int enable=1)
 

Enumeration Type Documentation

Enumerator
MIX_SV_SHAPE_LINEAR 
MIX_SV_SHAPE_EXP 
MIX_SV_SHAPE_EASED 
MIX_SV_SHAPE_EASED_EXP 

Definition at line 4 of file softvolume.h.

Function Documentation

void Mix_SoftVolume_AutoStopMusic ( int  chan,
int  enable = 1 
)

Definition at line 560 of file softvolume.cpp.

References Mix_SoftVolume_Init().

Referenced by PlayMusic().

561 {
563 
564  SDL_LockAudio();
565  if (channel_state.count( chan ) > 0)
566  channel_state[chan].autoStopMusic = enable;
567  SDL_UnlockAudio();
568 }
void Mix_SoftVolume_Change ( int  chan,
double  newvolume,
double  time,
Mix_SoftVolume_Shape  shape 
)

Definition at line 474 of file softvolume.cpp.

References t_SoftVolume_State::autoStopMusic, C_PI, UniverseUtil::cos(), t_SoftVolume_State::current_volume, dtof16(), f16tod(), fprintf, i, t_SoftVolume_State::in_transition, shape_sampler::init(), linear2log(), log2linear(), Mix_SoftVolume_Init(), MIX_SV_SHAPE_EASED, MIX_SV_SHAPE_EASED_EXP, MIX_SV_SHAPE_EXP, MIX_SV_SHAPE_LINEAR, shape_sampler::shape, SHAPE_SAMPLES, STD_ERR, and t_SoftVolume_State::t_shape.

Referenced by main(), and PlayMusic().

475 {
477 
478  //Setup transition record
479  {
480  SDL_LockAudio();
481 
482  SoftVolume_State &cstat = channel_state[chan];
483 
484  double cur_volume = f16tod( cstat.current_volume );
485  double new_volume = newvolume;
486 
487  int i;
488  cstat.in_transition = true;
489  switch (shape)
490  {
491  case MIX_SV_SHAPE_LINEAR:
492 mix_sv_shape_linear:
493  for (i = 0; i <= SHAPE_SAMPLES; i++)
494  cstat.t_shape.shape[i] = dtof16( cur_volume+(new_volume-cur_volume)*( i*(1.0/SHAPE_SAMPLES) ) );
495  break;
496  case MIX_SV_SHAPE_EXP:
497  cur_volume = linear2log( cur_volume );
498  new_volume = linear2log( new_volume );
499  for (i = 0; i <= SHAPE_SAMPLES; i++)
500  cstat.t_shape.shape[i] = dtof16( log2linear( cur_volume+(new_volume-cur_volume)*( i*(1.0/SHAPE_SAMPLES) ) ) );
501  break;
502  case MIX_SV_SHAPE_EASED:
503  for (i = 0; i <= SHAPE_SAMPLES; i++)
504  cstat.t_shape.shape[i] =
505  dtof16( cur_volume+(new_volume-cur_volume)*( 0.5-0.5*cos( i*(1.0/SHAPE_SAMPLES)*C_PI ) ) );
506  break;
508  cur_volume = linear2log( cur_volume );
509  new_volume = linear2log( new_volume );
510  for (i = 0; i <= SHAPE_SAMPLES; i++)
511  cstat.t_shape.shape[i] =
512  dtof16( log2linear( cur_volume+(new_volume-cur_volume)*( 0.5-0.5*cos( i*(1.0/SHAPE_SAMPLES)*C_PI ) ) ) );
513  break;
514  default:
515  fprintf( STD_ERR, "WARNING(softvolume.cpp): unrecognized transition shape, using default (linear)\n" );
516  goto mix_sv_shape_linear;
517  break;
518  }
519  cstat.t_shape.init( (unsigned long) (time*g_sdl_frequency) );
520  cstat.autoStopMusic = 0;
521 
522  SDL_UnlockAudio();
523  }
524 
525  //Register effect
526  Mix_UnregisterEffect( chan, g_sdl_effect_func ); //Is it necessary?
527  Mix_RegisterEffect( chan, g_sdl_effect_func, 0, 0 );
528 }
void Mix_SoftVolume_Force ( int  chan,
double  newvolume 
)

Definition at line 530 of file softvolume.cpp.

References t_SoftVolume_State::current_volume, dtof16(), t_SoftVolume_State::in_transition, and Mix_SoftVolume_Init().

Referenced by PlayMusic().

531 {
533 
534  SDL_LockAudio();
535 
536  SoftVolume_State &cstat = channel_state[chan];
537  cstat.current_volume = dtof16( newvolume );
538  cstat.in_transition = false;
539 
540  SDL_UnlockAudio();
541 }
double Mix_SoftVolume_GetCurrentVolume ( int  chan)

Definition at line 543 of file softvolume.cpp.

References f16tod(), and Mix_SoftVolume_Init().

544 {
545  double res;
546 
548 
549  SDL_LockAudio();
550  if (channel_state.count( chan ) > 0)
551  res = f16tod( channel_state[chan].current_volume );
552 
553  else
554  res = 1;
555  SDL_UnlockAudio();
556 
557  return res;
558 }