19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL - Simple DirectMedia Layer 39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Copyright (C) 1997-2012 Sam Lantinga 49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall This library is free software; you can redistribute it and/or 69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall modify it under the terms of the GNU Lesser General Public 79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall License as published by the Free Software Foundation; either 89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall version 2.1 of the License, or (at your option) any later version. 99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall This library is distributed in the hope that it will be useful, 119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall but WITHOUT ANY WARRANTY; without even the implied warranty of 129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Lesser General Public License for more details. 149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall You should have received a copy of the GNU Lesser General Public 169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall License along with this library; if not, write to the Free Software 179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Sam Lantinga 209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall slouken@libsdl.org 219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/ 229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_config.h" 239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* This provides the default mixing callback for the SDL audio routines */ 259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_cpuinfo.h" 279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_timer.h" 289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_audio.h" 299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_sysaudio.h" 309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_mixer_MMX.h" 319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_mixer_MMX_VC.h" 329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_mixer_m68k.h" 339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* This table is used to add two sound values together and pin 359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * the value to avoid overflow. (used with permission from ARDI) 369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Changed to use 0xFE instead of 0xFF for better sound quality. 379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic const Uint8 mix8[] = 399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0x7D, 0x7E, 0x7F, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92, 659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0x9E, 0x9F, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB0, 0xB1, 0xB2, 0xB3, 689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0xBF, 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, 729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFE, 0xFE, 759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE 879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}; 889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* The volume ranges from 0 - 128 */ 909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define ADJUST_VOLUME(s, v) (s = (s*v)/SDL_MIX_MAXVOLUME) 919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define ADJUST_VOLUME_U8(s, v) (s = (((s-128)*v)/SDL_MIX_MAXVOLUME)+128) 929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_MixAudio (Uint8 *dst, const Uint8 *src, Uint32 len, int volume) 949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint16 format; 969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( volume == 0 ) { 989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return; 999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Mix the user-level audio format */ 1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( current_audio ) { 1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( current_audio->convert.needed ) { 1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall format = current_audio->convert.src_format; 1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall format = current_audio->spec.format; 1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* HACK HACK HACK */ 1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall format = AUDIO_S16; 1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall switch (format) { 1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case AUDIO_U8: { 1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(__GNUC__) && (defined(__m68k__) && !defined(__mcoldfire__)) && defined(SDL_ASSEMBLY_ROUTINES) 1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_MixAudio_m68k_U8((char*)dst,(char*)src,(unsigned long)len,(long)volume,(char *)mix8); 1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else 1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint8 src_sample; 1189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while ( len-- ) { 1209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall src_sample = *src; 1219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ADJUST_VOLUME_U8(src_sample, volume); 1229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *dst = mix8[*dst+src_sample]; 1239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ++dst; 1249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ++src; 1259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 1299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case AUDIO_S8: { 1319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(SDL_BUGGY_MMX_MIXERS) /* buggy, so we're disabling them. --ryan. */ 1329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(__GNUC__) && defined(__i386__) && defined(SDL_ASSEMBLY_ROUTINES) 1339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (SDL_HasMMX()) 1349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 1359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_MixAudio_MMX_S8((char*)dst,(char*)src,(unsigned int)len,(int)volume); 1369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else 1389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#elif ((defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)) && defined(SDL_ASSEMBLY_ROUTINES) 1399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (SDL_HasMMX()) 1409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 1419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_MixAudio_MMX_S8_VC((char*)dst,(char*)src,(unsigned int)len,(int)volume); 1429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else 1449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(__GNUC__) && (defined(__m68k__) && !defined(__mcoldfire__)) && defined(SDL_ASSEMBLY_ROUTINES) 1489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_MixAudio_m68k_S8((char*)dst,(char*)src,(unsigned long)len,(long)volume); 1499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else 1509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 1519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Sint8 *dst8, *src8; 1529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Sint8 src_sample; 1539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int dst_sample; 1549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall const int max_audioval = ((1<<(8-1))-1); 1559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall const int min_audioval = -(1<<(8-1)); 1569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall src8 = (Sint8 *)src; 1589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dst8 = (Sint8 *)dst; 1599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while ( len-- ) { 1609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall src_sample = *src8; 1619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ADJUST_VOLUME(src_sample, volume); 1629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dst_sample = *dst8 + src_sample; 1639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( dst_sample > max_audioval ) { 1649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *dst8 = max_audioval; 1659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else 1669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( dst_sample < min_audioval ) { 1679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *dst8 = min_audioval; 1689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 1699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *dst8 = dst_sample; 1709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ++dst8; 1729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ++src8; 1739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 1789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case AUDIO_S16LSB: { 1809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(SDL_BUGGY_MMX_MIXERS) /* buggy, so we're disabling them. --ryan. */ 1819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(__GNUC__) && defined(__i386__) && defined(SDL_ASSEMBLY_ROUTINES) 1829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (SDL_HasMMX()) 1839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 1849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_MixAudio_MMX_S16((char*)dst,(char*)src,(unsigned int)len,(int)volume); 1859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else 1879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#elif ((defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)) && defined(SDL_ASSEMBLY_ROUTINES) 1889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (SDL_HasMMX()) 1899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 1909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_MixAudio_MMX_S16_VC((char*)dst,(char*)src,(unsigned int)len,(int)volume); 1919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else 1939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(__GNUC__) && (defined(__m68k__) && !defined(__mcoldfire__)) && defined(SDL_ASSEMBLY_ROUTINES) 1979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_MixAudio_m68k_S16LSB((short*)dst,(short*)src,(unsigned long)len,(long)volume); 1989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else 1999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 2009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Sint16 src1, src2; 2019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int dst_sample; 2029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall const int max_audioval = ((1<<(16-1))-1); 2039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall const int min_audioval = -(1<<(16-1)); 2049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall len /= 2; 2069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while ( len-- ) { 2079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall src1 = ((src[1])<<8|src[0]); 2089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ADJUST_VOLUME(src1, volume); 2099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall src2 = ((dst[1])<<8|dst[0]); 2109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall src += 2; 2119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dst_sample = src1+src2; 2129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( dst_sample > max_audioval ) { 2139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dst_sample = max_audioval; 2149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else 2159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( dst_sample < min_audioval ) { 2169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dst_sample = min_audioval; 2179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dst[0] = dst_sample&0xFF; 2199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dst_sample >>= 8; 2209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dst[1] = dst_sample&0xFF; 2219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dst += 2; 2229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 2259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 2279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case AUDIO_S16MSB: { 2299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(__GNUC__) && (defined(__m68k__) && !defined(__mcoldfire__)) && defined(SDL_ASSEMBLY_ROUTINES) 2309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_MixAudio_m68k_S16MSB((short*)dst,(short*)src,(unsigned long)len,(long)volume); 2319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else 2329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Sint16 src1, src2; 2339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int dst_sample; 2349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall const int max_audioval = ((1<<(16-1))-1); 2359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall const int min_audioval = -(1<<(16-1)); 2369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall len /= 2; 2389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while ( len-- ) { 2399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall src1 = ((src[0])<<8|src[1]); 2409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ADJUST_VOLUME(src1, volume); 2419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall src2 = ((dst[0])<<8|dst[1]); 2429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall src += 2; 2439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dst_sample = src1+src2; 2449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( dst_sample > max_audioval ) { 2459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dst_sample = max_audioval; 2469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else 2479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( dst_sample < min_audioval ) { 2489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dst_sample = min_audioval; 2499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dst[1] = dst_sample&0xFF; 2519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dst_sample >>= 8; 2529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dst[0] = dst_sample&0xFF; 2539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dst += 2; 2549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 2569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 2589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall default: /* If this happens... FIXME! */ 2609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("SDL_MixAudio(): unknown audio format"); 2619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return; 2629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 2649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 265