src/audio/SDL_mixer.c
changeset 5536 05af1b9ff46d
parent 5535 96594ac5fd1a
child 6138 4c64952a58fb
equal deleted inserted replaced
5535:96594ac5fd1a 5536:05af1b9ff46d
    24 
    24 
    25 #include "SDL_cpuinfo.h"
    25 #include "SDL_cpuinfo.h"
    26 #include "SDL_timer.h"
    26 #include "SDL_timer.h"
    27 #include "SDL_audio.h"
    27 #include "SDL_audio.h"
    28 #include "SDL_sysaudio.h"
    28 #include "SDL_sysaudio.h"
    29 #include "SDL_mixer_MMX.h"
       
    30 #include "SDL_mixer_MMX_VC.h"
       
    31 #include "SDL_mixer_m68k.h"
       
    32 
    29 
    33 /* This table is used to add two sound values together and pin
    30 /* This table is used to add two sound values together and pin
    34  * the value to avoid overflow.  (used with permission from ARDI)
    31  * the value to avoid overflow.  (used with permission from ARDI)
    35  * Changed to use 0xFE instead of 0xFF for better sound quality.
    32  * Changed to use 0xFE instead of 0xFF for better sound quality.
    36  */
    33  */
   119         }
   116         }
   120         break;
   117         break;
   121 
   118 
   122     case AUDIO_S8:
   119     case AUDIO_S8:
   123         {
   120         {
   124 #if defined(SDL_BUGGY_MMX_MIXERS) /* buggy, so we're disabling them. --ryan. */
   121             Sint8 *dst8, *src8;
   125 #if defined(__GNUC__) && defined(__i386__) && defined(SDL_ASSEMBLY_ROUTINES)
   122             Sint8 src_sample;
   126             if (SDL_HasMMX()) {
   123             int dst_sample;
   127                 SDL_MixAudio_MMX_S8((char *) dst, (char *) src,
   124             const int max_audioval = ((1 << (8 - 1)) - 1);
   128                                     (unsigned int) len, (int) volume);
   125             const int min_audioval = -(1 << (8 - 1));
   129             } else
   126 
   130 #elif ((defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)) && defined(SDL_ASSEMBLY_ROUTINES)
   127             src8 = (Sint8 *) src;
   131             if (SDL_HasMMX()) {
   128             dst8 = (Sint8 *) dst;
   132                 SDL_MixAudio_MMX_S8_VC((char *) dst, (char *) src,
   129             while (len--) {
   133                                        (unsigned int) len, (int) volume);
   130                 src_sample = *src8;
   134             } else
   131                 ADJUST_VOLUME(src_sample, volume);
   135 #endif
   132                 dst_sample = *dst8 + src_sample;
   136 #endif
   133                 if (dst_sample > max_audioval) {
   137 #if defined(__GNUC__) && defined(__M68000__) && !defined(__mcoldfire__) && defined(SDL_ASSEMBLY_ROUTINES)
   134                     *dst8 = max_audioval;
   138                 SDL_MixAudio_m68k_S8((char *) dst, (char *) src,
   135                 } else if (dst_sample < min_audioval) {
   139                                      (unsigned long) len, (long) volume);
   136                     *dst8 = min_audioval;
   140 #else
   137                 } else {
   141             {
   138                     *dst8 = dst_sample;
   142                 Sint8 *dst8, *src8;
   139                 }
   143                 Sint8 src_sample;
   140                 ++dst8;
   144                 int dst_sample;
   141                 ++src8;
   145                 const int max_audioval = ((1 << (8 - 1)) - 1);
   142             }
   146                 const int min_audioval = -(1 << (8 - 1));
       
   147 
       
   148                 src8 = (Sint8 *) src;
       
   149                 dst8 = (Sint8 *) dst;
       
   150                 while (len--) {
       
   151                     src_sample = *src8;
       
   152                     ADJUST_VOLUME(src_sample, volume);
       
   153                     dst_sample = *dst8 + src_sample;
       
   154                     if (dst_sample > max_audioval) {
       
   155                         *dst8 = max_audioval;
       
   156                     } else if (dst_sample < min_audioval) {
       
   157                         *dst8 = min_audioval;
       
   158                     } else {
       
   159                         *dst8 = dst_sample;
       
   160                     }
       
   161                     ++dst8;
       
   162                     ++src8;
       
   163                 }
       
   164             }
       
   165 #endif
       
   166         }
   143         }
   167         break;
   144         break;
   168 
   145 
   169     case AUDIO_S16LSB:
   146     case AUDIO_S16LSB:
   170         {
   147         {
   171 #if defined(SDL_BUGGY_MMX_MIXERS) /* buggy, so we're disabling them. --ryan. */
   148             Sint16 src1, src2;
   172 #if defined(__GNUC__) && defined(__i386__) && defined(SDL_ASSEMBLY_ROUTINES)
   149             int dst_sample;
   173             if (SDL_HasMMX()) {
   150             const int max_audioval = ((1 << (16 - 1)) - 1);
   174                 SDL_MixAudio_MMX_S16((char *) dst, (char *) src,
   151             const int min_audioval = -(1 << (16 - 1));
   175                                      (unsigned int) len, (int) volume);
   152 
   176             } else
   153             len /= 2;
   177 #elif ((defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)) && defined(SDL_ASSEMBLY_ROUTINES)
   154             while (len--) {
   178             if (SDL_HasMMX()) {
   155                 src1 = ((src[1]) << 8 | src[0]);
   179                 SDL_MixAudio_MMX_S16_VC((char *) dst, (char *) src,
   156                 ADJUST_VOLUME(src1, volume);
   180                                         (unsigned int) len, (int) volume);
   157                 src2 = ((dst[1]) << 8 | dst[0]);
   181             } else
   158                 src += 2;
   182 #endif
   159                 dst_sample = src1 + src2;
   183 #endif
   160                 if (dst_sample > max_audioval) {
   184 #if defined(__GNUC__) && defined(__M68000__) && !defined(__mcoldfire__) && defined(SDL_ASSEMBLY_ROUTINES)
   161                     dst_sample = max_audioval;
   185                 SDL_MixAudio_m68k_S16LSB((short *) dst, (short *) src,
   162                 } else if (dst_sample < min_audioval) {
   186                                          (unsigned long) len, (long) volume);
   163                     dst_sample = min_audioval;
   187 #else
   164                 }
   188             {
   165                 dst[0] = dst_sample & 0xFF;
   189                 Sint16 src1, src2;
   166                 dst_sample >>= 8;
   190                 int dst_sample;
   167                 dst[1] = dst_sample & 0xFF;
   191                 const int max_audioval = ((1 << (16 - 1)) - 1);
   168                 dst += 2;
   192                 const int min_audioval = -(1 << (16 - 1));
   169             }
   193 
       
   194                 len /= 2;
       
   195                 while (len--) {
       
   196                     src1 = ((src[1]) << 8 | src[0]);
       
   197                     ADJUST_VOLUME(src1, volume);
       
   198                     src2 = ((dst[1]) << 8 | dst[0]);
       
   199                     src += 2;
       
   200                     dst_sample = src1 + src2;
       
   201                     if (dst_sample > max_audioval) {
       
   202                         dst_sample = max_audioval;
       
   203                     } else if (dst_sample < min_audioval) {
       
   204                         dst_sample = min_audioval;
       
   205                     }
       
   206                     dst[0] = dst_sample & 0xFF;
       
   207                     dst_sample >>= 8;
       
   208                     dst[1] = dst_sample & 0xFF;
       
   209                     dst += 2;
       
   210                 }
       
   211             }
       
   212 #endif
       
   213         }
   170         }
   214         break;
   171         break;
   215 
   172 
   216     case AUDIO_S16MSB:
   173     case AUDIO_S16MSB:
   217         {
   174         {