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.cpp File Reference
#include <stdlib.h>
#include <map>
#include <memory.h>
#include <stdio.h>
#include <math.h>
#include <limits>
#include "softvolume.h"

Go to the source code of this file.

Classes

class  t_rng16
 
class  shape_sampler
 
struct  t_SoftVolume_State
 

Macros

#define SDL_MIX_MAXVOLUME   128
 
#define SDL_INT64   __undefined_64bit_type__
 
#define SDL_UINT64   __undefined_64bit_type__
 
#define UC8_MIN   ( (unsigned long) std::numeric_limits< unsigned char >::min() )
 
#define UC8_MAX   ( (unsigned long) std::numeric_limits< unsigned char >::max() )
 
#define SC8_MIN   ( (signed long) std::numeric_limits< signed char >::min() )
 
#define SC8_MAX   ( (signed long) std::numeric_limits< signed char >::max() )
 
#define US16_MIN   ( (unsigned long) std::numeric_limits< unsigned short >::min() )
 
#define US16_MAX   ( (unsigned long) std::numeric_limits< unsigned short >::max() )
 
#define SS16_MIN   ( (signed long) std::numeric_limits< signed short >::min() )
 
#define SS16_MAX   ( (signed long) std::numeric_limits< signed short >::max() )
 
#define DB_INF   -144.0
 
#define STD_ERR   stderr
 
#define STD_OUT   stdout
 
#define SHAPE_SAMPLE_ORDER   10
 
#define SHAPE_SAMPLES   (1<<SHAPE_SAMPLE_ORDER)
 
#define SHAPE_SAMPLE_SAFEPOS(p)   ( (p)&( (1<<SHAPE_SAMPLE_ORDER)-1 ) )
 
#define RNG_COUNT   (1<<16)
 
#define RNG_MASK   ( (1<<16)-1 )
 
#define LOG_10   2.3025850929940456840179914546844
 
#define INV_LOG_10   (1.0/LOG_10)
 
#define C_PI   3.1415926535897932384626433832795
 
#define lil_endian_to_native(x)   x
 
#define native_to_big_endian(x)   big_endian_to_native( x )
 
#define native_to_lil_endian(x)   lil_endian_to_native( x )
 

Typedefs

typedef int Mix_Music
 
typedef struct t_SoftVolume_State SoftVolume_State
 

Functions

template<typename T >
min (const T a, const T b)
 
template<typename T >
max (const T a, const T b)
 
unsigned long interpolateF16F16 (unsigned long a, unsigned long b, unsigned long t)
 
unsigned long dtof16 (double f)
 
double f16tod (unsigned long f16)
 
double log2linear (double lg)
 
double linear2log (double lin)
 
unsigned short mpyUS16F16 (unsigned short a, unsigned long f16)
 
signed short mpySS16F16 (signed short a, unsigned long f16)
 
unsigned char mpyUC8F16 (unsigned char a, unsigned long f16)
 
signed char mpySC8F16 (signed char a, unsigned long f16)
 
signed short big_endian_to_native (signed short x)
 
unsigned short big_endian_to_native (unsigned short x)
 
void sdl_softvolume_effect_U8 (int chan, void *stream, int len, void *)
 
void sdl_softvolume_effect_S8 (int chan, void *stream, int len, void *)
 
void sdl_softvolume_effect_U16LSB (int chan, void *stream, int len, void *)
 
void sdl_softvolume_effect_S16LSB (int chan, void *stream, int len, void *)
 
void sdl_softvolume_effect_U16MSB (int chan, void *stream, int len, void *)
 
void sdl_softvolume_effect_S16MSB (int chan, void *stream, int len, void *)
 
void Mix_SoftVolume_Init ()
 
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)
 

Variables

class t_rng16 rng16
 
std::map< int, SoftVolume_Statechannel_state
 
int g_sdl_frequency
 
Uint16 g_sdl_format
 
int g_sdl_channels
 
int g_sdl_init = 0
 
Mix_EffectFunc_t g_sdl_effect_func = 0
 

Macro Definition Documentation

#define C_PI   3.1415926535897932384626433832795

Definition at line 189 of file softvolume.cpp.

Referenced by Mix_SoftVolume_Change().

#define DB_INF   -144.0

Definition at line 61 of file softvolume.cpp.

Referenced by linear2log().

#define INV_LOG_10   (1.0/LOG_10)

Definition at line 188 of file softvolume.cpp.

Referenced by linear2log().

#define lil_endian_to_native (   x)    x

Definition at line 258 of file softvolume.cpp.

Referenced by sdl_softvolume_effect_S16LSB(), and sdl_softvolume_effect_U16LSB().

#define LOG_10   2.3025850929940456840179914546844

Definition at line 187 of file softvolume.cpp.

Referenced by log2linear().

#define native_to_big_endian (   x)    big_endian_to_native( x )

Definition at line 259 of file softvolume.cpp.

Referenced by sdl_softvolume_effect_S16MSB(), and sdl_softvolume_effect_U16MSB().

#define native_to_lil_endian (   x)    lil_endian_to_native( x )

Definition at line 260 of file softvolume.cpp.

Referenced by sdl_softvolume_effect_S16LSB(), and sdl_softvolume_effect_U16LSB().

#define RNG_COUNT   (1<<16)

Definition at line 76 of file softvolume.cpp.

Referenced by t_rng16::t_rng16().

#define RNG_MASK   ( (1<<16)-1 )

Definition at line 77 of file softvolume.cpp.

Referenced by t_rng16::get().

#define SC8_MAX   ( (signed long) std::numeric_limits< signed char >::max() )

Definition at line 45 of file softvolume.cpp.

Referenced by mpySC8F16().

#define SC8_MIN   ( (signed long) std::numeric_limits< signed char >::min() )

Definition at line 44 of file softvolume.cpp.

Referenced by mpySC8F16().

#define SDL_INT64   __undefined_64bit_type__

Definition at line 26 of file softvolume.cpp.

#define SDL_MIX_MAXVOLUME   128

Definition at line 2 of file softvolume.cpp.

#define SDL_UINT64   __undefined_64bit_type__

Definition at line 27 of file softvolume.cpp.

#define SHAPE_SAMPLE_ORDER   10

Definition at line 72 of file softvolume.cpp.

Referenced by shape_sampler::done().

#define SHAPE_SAMPLE_SAFEPOS (   p)    ( (p)&( (1<<SHAPE_SAMPLE_ORDER)-1 ) )

Definition at line 74 of file softvolume.cpp.

Referenced by shape_sampler::operator*().

#define SHAPE_SAMPLES   (1<<SHAPE_SAMPLE_ORDER)
#define SS16_MAX   ( (signed long) std::numeric_limits< signed short >::max() )

Definition at line 49 of file softvolume.cpp.

#define SS16_MIN   ( (signed long) std::numeric_limits< signed short >::min() )

Definition at line 48 of file softvolume.cpp.

#define STD_ERR   stderr

Definition at line 68 of file softvolume.cpp.

Referenced by Mix_SoftVolume_Change().

#define STD_OUT   stdout

Definition at line 69 of file softvolume.cpp.

#define UC8_MAX   ( (unsigned long) std::numeric_limits< unsigned char >::max() )

Definition at line 43 of file softvolume.cpp.

Referenced by mpyUC8F16().

#define UC8_MIN   ( (unsigned long) std::numeric_limits< unsigned char >::min() )

Definition at line 42 of file softvolume.cpp.

Referenced by mpyUC8F16().

#define US16_MAX   ( (unsigned long) std::numeric_limits< unsigned short >::max() )

Definition at line 47 of file softvolume.cpp.

#define US16_MIN   ( (unsigned long) std::numeric_limits< unsigned short >::min() )

Definition at line 46 of file softvolume.cpp.

Typedef Documentation

typedef int Mix_Music

Definition at line 9 of file softvolume.cpp.

Function Documentation

signed short big_endian_to_native ( signed short  x)
inline

Definition at line 250 of file softvolume.cpp.

Referenced by sdl_softvolume_effect_S16MSB(), and sdl_softvolume_effect_U16MSB().

251 {
252  return (x>>8)|(x<<8);
253 }
unsigned short big_endian_to_native ( unsigned short  x)
inline

Definition at line 254 of file softvolume.cpp.

255 {
256  return (x>>8)|(x<<8);
257 }
unsigned long dtof16 ( double  f)
inline

Definition at line 178 of file softvolume.cpp.

References max(), and min().

Referenced by Mix_SoftVolume_Change(), and Mix_SoftVolume_Force().

179 {
180  return (unsigned long) max( 0.0f, min( (float) 0xFFFFFFFF, (float) (f*0x10000) ) );
181 }
double f16tod ( unsigned long  f16)
inline

Definition at line 182 of file softvolume.cpp.

Referenced by Mix_SoftVolume_Change(), and Mix_SoftVolume_GetCurrentVolume().

183 {
184  return f16/(double) 0x10000;
185 }
unsigned long interpolateF16F16 ( unsigned long  a,
unsigned long  b,
unsigned long  t 
)
inline

Definition at line 129 of file softvolume.cpp.

Referenced by shape_sampler::operator*().

130 {
131  return (a>>8)*( (0x10000-t)>>8 )+(b>>8)*(t>>8);
132 }
double linear2log ( double  lin)
inline

Definition at line 195 of file softvolume.cpp.

References DB_INF, INV_LOG_10, and UniverseUtil::log().

Referenced by Mix_SoftVolume_Change().

196 {
197  return (lin <= 0) ? DB_INF : (20*log( lin )*INV_LOG_10);
198 }
double log2linear ( double  lg)
inline

Definition at line 191 of file softvolume.cpp.

References UniverseUtil::exp(), and LOG_10.

Referenced by Mix_SoftVolume_Change().

192 {
193  return exp( lg*0.05*LOG_10 );
194 }
void Mix_SoftVolume_AutoStopMusic ( int  chan,
int  enable 
)

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 }
void Mix_SoftVolume_Init ( )

Definition at line 444 of file softvolume.cpp.

References sdl_softvolume_effect_S16LSB(), sdl_softvolume_effect_S16MSB(), sdl_softvolume_effect_S8(), sdl_softvolume_effect_U16LSB(), sdl_softvolume_effect_U16MSB(), and sdl_softvolume_effect_U8().

Referenced by Mix_SoftVolume_AutoStopMusic(), Mix_SoftVolume_Change(), Mix_SoftVolume_Force(), and Mix_SoftVolume_GetCurrentVolume().

445 {
446  //Query device format
447  if (!g_sdl_init) {
448  Mix_QuerySpec( &g_sdl_frequency, &g_sdl_format, &g_sdl_channels );
449  switch (g_sdl_format)
450  {
451  case AUDIO_U8:
453  break;
454  case AUDIO_S8:
456  break;
457  case AUDIO_U16LSB:
459  break;
460  case AUDIO_S16LSB:
462  break;
463  case AUDIO_U16MSB:
465  break;
466  case AUDIO_S16MSB:
468  break;
469  }
470  g_sdl_init = 1;
471  }
472 }
signed char mpySC8F16 ( signed char  a,
unsigned long  f16 
)
inline

Definition at line 244 of file softvolume.cpp.

References t_rng16::get(), max(), min(), rng16, SC8_MAX, and SC8_MIN.

Referenced by sdl_softvolume_effect_S8().

245 {
246  return (signed char) min( SC8_MAX, max( SC8_MIN, ( (signed long) ( ( ( (signed long) a )*f16 )+rng16.get() )/(1<<16) ) ) );
247 }
signed short mpySS16F16 ( signed short  a,
unsigned long  f16 
)
inline

Definition at line 229 of file softvolume.cpp.

References t_rng16::get(), max(), min(), and rng16.

Referenced by sdl_softvolume_effect_S16LSB(), and sdl_softvolume_effect_S16MSB().

230 {
231  return (signed short) min( SS16_MAX,
232  max( SS16_MIN, ( (signed long) ( ( ( (signed long) a )*(f16>>8) )+rng16.get() )/(1<<8) ) ) );
233 }
unsigned char mpyUC8F16 ( unsigned char  a,
unsigned long  f16 
)
inline

Definition at line 237 of file softvolume.cpp.

References t_rng16::get(), max(), min(), rng16, UC8_MAX, and UC8_MIN.

Referenced by sdl_softvolume_effect_U8().

238 {
239  return (unsigned char) min( UC8_MAX,
240  max( UC8_MIN,
241  (unsigned long) ( ( ( ( ( ( (signed long) a )-0x80 )*f16 )+rng16.get() )>>16 )+0x80 ) ) );
242 }
unsigned short mpyUS16F16 ( unsigned short  a,
unsigned long  f16 
)
inline

Definition at line 221 of file softvolume.cpp.

References t_rng16::get(), max(), min(), and rng16.

Referenced by sdl_softvolume_effect_U16LSB(), and sdl_softvolume_effect_U16MSB().

222 {
223  return (unsigned short) min( US16_MAX,
224  max( US16_MIN,
225  (unsigned long) ( ( ( ( ( ( (signed long) a )
226  -0x8000 )*(f16>>8) )+rng16.get() )>>8 )+0x8000 ) ) );
227 }
void sdl_softvolume_effect_S16LSB ( int  chan,
void *  stream,
int  len,
void *   
)

Definition at line 369 of file softvolume.cpp.

References t_SoftVolume_State::autoStopMusic, t_SoftVolume_State::current_volume, shape_sampler::done(), shape_sampler::finalsample(), i, t_SoftVolume_State::in_transition, lil_endian_to_native, mpySS16F16(), native_to_lil_endian, and t_SoftVolume_State::t_shape.

Referenced by Mix_SoftVolume_Init().

370 {
371  SoftVolume_State &cstat = channel_state[chan];
372  signed short *buf = (signed short*) stream;
373  if (cstat.in_transition) {
374  while ( !cstat.t_shape.done() && (len > 0) ) {
375  for ( int i = g_sdl_channels; i > 0; i--, buf++, len -= sizeof (*buf) )
376  *buf = native_to_lil_endian( mpySS16F16( lil_endian_to_native( *buf ), *cstat.t_shape ) );
377  ++cstat.t_shape;
378  }
379  cstat.current_volume = (cstat.t_shape.done() ? cstat.t_shape.finalsample() : *cstat.t_shape);
380  cstat.in_transition = !cstat.t_shape.done();
381  }
382  if (cstat.current_volume == 0) {
383  memset( buf, 0, len );
384  } else if (cstat.current_volume != 0x10000) {
385  while (len > 0) {
387  buf++, len -= sizeof (*buf);
388  }
389  }
390  if ( (cstat.current_volume == 0) && cstat.autoStopMusic )
391  Mix_HaltMusic();
392 }
void sdl_softvolume_effect_S16MSB ( int  chan,
void *  stream,
int  len,
void *   
)

Definition at line 419 of file softvolume.cpp.

References t_SoftVolume_State::autoStopMusic, big_endian_to_native(), t_SoftVolume_State::current_volume, shape_sampler::done(), shape_sampler::finalsample(), i, t_SoftVolume_State::in_transition, mpySS16F16(), native_to_big_endian, and t_SoftVolume_State::t_shape.

Referenced by Mix_SoftVolume_Init().

420 {
421  SoftVolume_State &cstat = channel_state[chan];
422  signed short *buf = (signed short*) stream;
423  if (cstat.in_transition) {
424  while ( !cstat.t_shape.done() && (len > 0) ) {
425  for ( int i = g_sdl_channels; i > 0; i--, buf++, len -= sizeof (*buf) )
426  *buf = native_to_big_endian( mpySS16F16( big_endian_to_native( *buf ), *cstat.t_shape ) );
427  ++cstat.t_shape;
428  }
429  cstat.current_volume = (cstat.t_shape.done() ? cstat.t_shape.finalsample() : *cstat.t_shape);
430  cstat.in_transition = !cstat.t_shape.done();
431  }
432  if (cstat.current_volume == 0) {
433  memset( buf, 0, len );
434  } else if (cstat.current_volume != 0x10000) {
435  while (len > 0) {
437  buf++, len -= sizeof (*buf);
438  }
439  }
440  if ( (cstat.current_volume == 0) && cstat.autoStopMusic )
441  Mix_HaltMusic();
442 }
void sdl_softvolume_effect_S8 ( int  chan,
void *  stream,
int  len,
void *   
)

Definition at line 318 of file softvolume.cpp.

References t_SoftVolume_State::autoStopMusic, t_SoftVolume_State::current_volume, shape_sampler::done(), shape_sampler::finalsample(), i, t_SoftVolume_State::in_transition, mpySC8F16(), and t_SoftVolume_State::t_shape.

Referenced by Mix_SoftVolume_Init().

319 {
320  SoftVolume_State &cstat = channel_state[chan];
321  signed char *buf = (signed char*) stream;
322  if (cstat.in_transition) {
323  while ( !cstat.t_shape.done() && (len > 0) ) {
324  for ( int i = g_sdl_channels; i > 0; i--, buf++, len -= sizeof (*buf) )
325  *buf = mpySC8F16( *buf, *cstat.t_shape );
326  ++cstat.t_shape;
327  }
328  cstat.current_volume = (cstat.t_shape.done() ? cstat.t_shape.finalsample() : *cstat.t_shape);
329  cstat.in_transition = !cstat.t_shape.done();
330  }
331  if (cstat.current_volume == 0) {
332  memset( buf, 0, len );
333  } else if (cstat.current_volume != 0x10000) {
334  while (len > 0) {
335  *buf = mpySC8F16( *buf, cstat.current_volume );
336  buf++, len -= sizeof (*buf);
337  }
338  }
339  if ( (cstat.current_volume == 0) && cstat.autoStopMusic )
340  Mix_HaltMusic();
341 }
void sdl_softvolume_effect_U16LSB ( int  chan,
void *  stream,
int  len,
void *   
)

Definition at line 342 of file softvolume.cpp.

References t_SoftVolume_State::autoStopMusic, t_SoftVolume_State::current_volume, shape_sampler::done(), shape_sampler::finalsample(), i, t_SoftVolume_State::in_transition, lil_endian_to_native, mpyUS16F16(), native_to_lil_endian, and t_SoftVolume_State::t_shape.

Referenced by Mix_SoftVolume_Init().

343 {
344  SoftVolume_State &cstat = channel_state[chan];
345  unsigned short *buf = (unsigned short*) stream;
346  if (cstat.in_transition) {
347  while ( !cstat.t_shape.done() && (len > 0) ) {
348  for ( int i = g_sdl_channels; i > 0; i--, buf++, len -= sizeof (*buf) )
349  *buf = native_to_lil_endian( mpyUS16F16( lil_endian_to_native( *buf ), *cstat.t_shape ) );
350  ++cstat.t_shape;
351  }
352  cstat.current_volume = (cstat.t_shape.done() ? cstat.t_shape.finalsample() : *cstat.t_shape);
353  cstat.in_transition = !cstat.t_shape.done();
354  }
355  if (cstat.current_volume == 0) {
356  unsigned short ct = native_to_lil_endian( (unsigned short) 0x8000 );
357  while (len > 0)
358  *(buf++) = ct, len -= sizeof (*buf);
359  } else if (cstat.current_volume != 0x10000) {
360  while (len > 0) {
362  buf++, len -= sizeof (*buf);
363  }
364  }
365  if ( (cstat.current_volume == 0) && cstat.autoStopMusic )
366  Mix_HaltMusic();
367 }
void sdl_softvolume_effect_U16MSB ( int  chan,
void *  stream,
int  len,
void *   
)

Definition at line 393 of file softvolume.cpp.

References t_SoftVolume_State::autoStopMusic, big_endian_to_native(), t_SoftVolume_State::current_volume, shape_sampler::done(), shape_sampler::finalsample(), i, t_SoftVolume_State::in_transition, mpyUS16F16(), native_to_big_endian, and t_SoftVolume_State::t_shape.

Referenced by Mix_SoftVolume_Init().

394 {
395  SoftVolume_State &cstat = channel_state[chan];
396  unsigned short *buf = (unsigned short*) stream;
397  if (cstat.in_transition) {
398  while ( !cstat.t_shape.done() && (len > 0) ) {
399  for ( int i = g_sdl_channels; i > 0; i--, buf++, len -= sizeof (*buf) )
400  *buf = native_to_big_endian( mpyUS16F16( big_endian_to_native( *buf ), *cstat.t_shape ) );
401  ++cstat.t_shape;
402  }
403  cstat.current_volume = (cstat.t_shape.done() ? cstat.t_shape.finalsample() : *cstat.t_shape);
404  cstat.in_transition = !cstat.t_shape.done();
405  }
406  if (cstat.current_volume == 0) {
407  unsigned short ct = native_to_big_endian( (unsigned short) 0x8000 );
408  while (len > 0)
409  *(buf++) = ct, len -= sizeof (*buf);
410  } else if (cstat.current_volume != 0x10000) {
411  while (len > 0) {
413  buf++, len -= sizeof (*buf);
414  }
415  }
416  if ( (cstat.current_volume == 0) && cstat.autoStopMusic )
417  Mix_HaltMusic();
418 }
void sdl_softvolume_effect_U8 ( int  chan,
void *  stream,
int  len,
void *   
)

Definition at line 296 of file softvolume.cpp.

References t_SoftVolume_State::autoStopMusic, t_SoftVolume_State::current_volume, shape_sampler::done(), shape_sampler::finalsample(), i, t_SoftVolume_State::in_transition, mpyUC8F16(), and t_SoftVolume_State::t_shape.

Referenced by Mix_SoftVolume_Init().

297 {
298  SoftVolume_State &cstat = channel_state[chan];
299  unsigned char *buf = (unsigned char*) stream;
300  if (cstat.in_transition) {
301  while ( !cstat.t_shape.done() && (len > 0) ) {
302  for ( int i = g_sdl_channels; i > 0; i--, buf++, len -= sizeof (*buf) )
303  *buf = mpyUC8F16( *buf, *cstat.t_shape );
304  ++cstat.t_shape;
305  }
306  cstat.current_volume = (cstat.t_shape.done() ? cstat.t_shape.finalsample() : *cstat.t_shape);
307  cstat.in_transition = !cstat.t_shape.done();
308  }
309  if (cstat.current_volume != 0x10000) {
310  while (len > 0) {
311  *buf = mpyUC8F16( *buf, cstat.current_volume );
312  buf++, len -= sizeof (*buf);
313  }
314  }
315  if ( (cstat.current_volume == 0) && cstat.autoStopMusic )
316  Mix_HaltMusic();
317 }

Variable Documentation

std::map< int, SoftVolume_State > channel_state

Definition at line 289 of file softvolume.cpp.

int g_sdl_channels

Definition at line 292 of file softvolume.cpp.

Mix_EffectFunc_t g_sdl_effect_func = 0

Definition at line 294 of file softvolume.cpp.

Uint16 g_sdl_format

Definition at line 291 of file softvolume.cpp.

int g_sdl_frequency

Definition at line 290 of file softvolume.cpp.

int g_sdl_init = 0

Definition at line 293 of file softvolume.cpp.

class t_rng16 rng16