effect_position.c
changeset 201 e55fb6b45559
parent 159 01490534f9fe
child 218 a21e382190a8
     1.1 --- a/effect_position.c	Mon Dec 16 04:50:16 2002 +0000
     1.2 +++ b/effect_position.c	Fri Dec 27 15:13:37 2002 +0000
     1.3 @@ -104,8 +104,11 @@
     1.4      }
     1.5  
     1.6      for (i = 0; i < len; i += sizeof (Uint8) * 2) {
     1.7 -        *(ptr++) = (Uint8)((((float) *ptr) * args->left_f) * args->distance_f);
     1.8 -        *(ptr++) = (Uint8)((((float) *ptr) * args->right_f) * args->distance_f);
     1.9 +        /* must adjust the sample so that 0 is the center */
    1.10 +        *(ptr++) = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128)) 
    1.11 +            * args->left_f) * args->distance_f) + 128);
    1.12 +        *(ptr++) = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128)) 
    1.13 +            * args->right_f) * args->distance_f) + 128);
    1.14      }
    1.15  }
    1.16  
    1.17 @@ -237,15 +240,24 @@
    1.18  
    1.19      for (i = 0; i < len; i += sizeof (Uint16) * 2) {
    1.20  #if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
    1.21 -        Uint16 swapl = (Uint16) ((((float) SDL_Swap16(*(ptr))) *
    1.22 -                                    args->left_f) * args->distance_f);
    1.23 -        Uint16 swapr = (Uint16) ((((float) SDL_Swap16(*(ptr+1))) *
    1.24 -                                    args->right_f) * args->distance_f);
    1.25 +        Sint16 sampl = (Sint16) (SDL_Swap16(*(ptr+0)) - 32768);
    1.26 +        Sint16 sampr = (Sint16) (SDL_Swap16(*(ptr+1)) - 32768);
    1.27 +        
    1.28 +        Uint16 swapl = (Uint16) ((Sint16) (((float) sampl * args->left_f)
    1.29 +                                    * args->distance_f) + 32768);
    1.30 +        Uint16 swapr = (Uint16) ((Sint16) (((float) sampr * args->right_f)
    1.31 +                                    * args->distance_f) + 32768);
    1.32 +
    1.33          *(ptr++) = (Uint16) SDL_Swap16(swapl);
    1.34          *(ptr++) = (Uint16) SDL_Swap16(swapr);
    1.35  #else
    1.36 -        *(ptr++) = (Uint16) ((((float) *ptr)*args->left_f)*args->distance_f);
    1.37 -        *(ptr++) = (Uint16) ((((float) *ptr)*args->right_f)*args->distance_f);
    1.38 +        Sint16 sampl = (Sint16) (*(ptr+0) - 32768);
    1.39 +        Sint16 sampr = (Sint16) (*(ptr+1) - 32768);
    1.40 +
    1.41 +        *(ptr++) = (Uint16) ((Sint16) (((float) sampl * args->left_f) 
    1.42 +                                    * args->distance_f) + 32768);
    1.43 +        *(ptr++) = (Uint16) ((Sint16) (((float) sampr * args->right_f) 
    1.44 +                                    * args->distance_f) + 32768);
    1.45  #endif
    1.46      }
    1.47  }
    1.48 @@ -281,15 +293,24 @@
    1.49  
    1.50      for (i = 0; i < len; i += sizeof (Sint16) * 2) {
    1.51  #if (SDL_BYTEORDER == SDL_LIL_ENDIAN)
    1.52 -        Uint16 swapl = (Uint16) ((((float) SDL_Swap16(*(ptr))) *
    1.53 -                                    args->left_f) * args->distance_f);
    1.54 -        Uint16 swapr = (Uint16) ((((float) SDL_Swap16(*(ptr+1))) *
    1.55 -                                    args->right_f) * args->distance_f);
    1.56 +        Sint16 sampl = (Sint16) (SDL_Swap16(*(ptr+0)) - 32768);
    1.57 +        Sint16 sampr = (Sint16) (SDL_Swap16(*(ptr+1)) - 32768);
    1.58 +        
    1.59 +        Uint16 swapl = (Uint16) ((Sint16) (((float) sampl * args->left_f)
    1.60 +                                    * args->distance_f) + 32768);
    1.61 +        Uint16 swapr = (Uint16) ((Sint16) (((float) sampr * args->right_f)
    1.62 +                                    * args->distance_f) + 32768);
    1.63 +
    1.64          *(ptr++) = (Uint16) SDL_Swap16(swapl);
    1.65          *(ptr++) = (Uint16) SDL_Swap16(swapr);
    1.66  #else
    1.67 -        *(ptr++) = (Uint16) ((((float) *ptr)*args->left_f)*args->distance_f);
    1.68 -        *(ptr++) = (Uint16) ((((float) *ptr)*args->right_f)*args->distance_f);
    1.69 +        Sint16 sampl = (Sint16) (*(ptr+0) - 32768);
    1.70 +        Sint16 sampr = (Sint16) (*(ptr+1) - 32768);
    1.71 +
    1.72 +        *(ptr++) = (Uint16) ((Sint16) (((float) sampl * args->left_f) 
    1.73 +                                    * args->distance_f) + 32768);
    1.74 +        *(ptr++) = (Uint16) ((Sint16) (((float) sampr * args->right_f) 
    1.75 +                                    * args->distance_f) + 32768);
    1.76  #endif
    1.77      }
    1.78  }