music.c
changeset 26 25edca541dc9
parent 24 a25bb2d59ce8
child 29 44b09d6e1170
     1.1 --- a/music.c	Tue Dec 21 17:41:12 1999 +0000
     1.2 +++ b/music.c	Sun Dec 26 11:17:50 1999 +0000
     1.3 @@ -1,25 +1,25 @@
     1.4  /*
     1.5 -    MIXERLIB:  An audio mixer library based on the SDL library
     1.6 -    Copyright (C) 1997-1999  Sam Lantinga
     1.7 +	MIXERLIB:  An audio mixer library based on the SDL library
     1.8 +	Copyright (C) 1997-1999  Sam Lantinga
     1.9  
    1.10 -    This library is free software; you can redistribute it and/or
    1.11 -    modify it under the terms of the GNU Library General Public
    1.12 -    License as published by the Free Software Foundation; either
    1.13 -    version 2 of the License, or (at your option) any later version.
    1.14 +	This library is free software; you can redistribute it and/or
    1.15 +	modify it under the terms of the GNU Library General Public
    1.16 +	License as published by the Free Software Foundation; either
    1.17 +	version 2 of the License, or (at your option) any later version.
    1.18  
    1.19 -    This library is distributed in the hope that it will be useful,
    1.20 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.21 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.22 -    Library General Public License for more details.
    1.23 +	This library is distributed in the hope that it will be useful,
    1.24 +	but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.25 +	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.26 +	Library General Public License for more details.
    1.27  
    1.28 -    You should have received a copy of the GNU Library General Public
    1.29 -    License along with this library; if not, write to the Free
    1.30 -    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.31 +	You should have received a copy of the GNU Library General Public
    1.32 +	License along with this library; if not, write to the Free
    1.33 +	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.34  
    1.35 -    Sam Lantinga
    1.36 -    5635-34 Springhouse Dr.
    1.37 -    Pleasanton, CA 94588 (USA)
    1.38 -    slouken@devolution.com
    1.39 +	Sam Lantinga
    1.40 +	5635-34 Springhouse Dr.
    1.41 +	Pleasanton, CA 94588 (USA)
    1.42 +	slouken@devolution.com
    1.43  */
    1.44  
    1.45  #include <stdlib.h>
    1.46 @@ -117,9 +117,9 @@
    1.47  		/* Handle fading */
    1.48  		if ( music_playing->fading != MIX_NO_FADING ) {
    1.49  			if ( music_playing->fade_step++ < music_playing->fade_steps ) {
    1.50 -                int fade_volume = music_playing->fade_volume;
    1.51 -                int fade_step = music_playing->fade_step;
    1.52 -                int fade_steps = music_playing->fade_steps;
    1.53 +				int fade_volume = music_playing->fade_volume;
    1.54 +				int fade_step = music_playing->fade_step;
    1.55 +				int fade_steps = music_playing->fade_steps;
    1.56  
    1.57  				if ( music_playing->fading == MIX_FADING_OUT ) {
    1.58  					Mix_VolumeMusic((fade_volume * (fade_steps-fade_step)) 
    1.59 @@ -190,8 +190,8 @@
    1.60  				break;
    1.61  #endif
    1.62  #ifdef MP3_MUSIC
    1.63 -		    case MUS_MP3:
    1.64 -			    SMPEG_playAudio(music_playing->data.mp3, stream, len);
    1.65 +			case MUS_MP3:
    1.66 +				SMPEG_playAudio(music_playing->data.mp3, stream, len);
    1.67  				break;
    1.68  #endif
    1.69  			default:
    1.70 @@ -242,29 +242,29 @@
    1.71  		break;
    1.72  
    1.73  		default: {
    1.74 -			SDL_SetError("Unknown hardware audio format");
    1.75 +			Mix_SetError("Unknown hardware audio format");
    1.76  			++music_error;
    1.77  		}
    1.78  	}
    1.79  	if ( mixer->channels > 1 ) {
    1.80  		if ( mixer->channels > 2 ) {
    1.81 -			SDL_SetError("Hardware uses more channels than mixer");
    1.82 +			Mix_SetError("Hardware uses more channels than mixer");
    1.83  			++music_error;
    1.84  		}
    1.85  		md_mode |= DMODE_STEREO;
    1.86  	}
    1.87 -	samplesize     = mixer->size/mixer->samples;
    1.88 -	md_mixfreq     = mixer->freq;
    1.89 -	md_device      = 0;
    1.90 -	md_volume      = 96;
    1.91 +	samplesize	 = mixer->size/mixer->samples;
    1.92 +	md_mixfreq	 = mixer->freq;
    1.93 +	md_device	  = 0;
    1.94 +	md_volume	  = 96;
    1.95  	md_musicvolume = 128;
    1.96  	md_sndfxvolume = 128;
    1.97 -	md_pansep      = 128;
    1.98 -	md_reverb      = 0;
    1.99 +	md_pansep	  = 128;
   1.100 +	md_reverb	  = 0;
   1.101  	MikMod_RegisterAllLoaders();
   1.102  	MikMod_RegisterAllDrivers();
   1.103  	if ( MikMod_Init() ) {
   1.104 -		SDL_SetError("%s", _mm_errmsg[_mm_errno]);
   1.105 +		Mix_SetError("%s", _mm_errmsg[_mm_errno]);
   1.106  		++music_error;
   1.107  	}
   1.108  #endif
   1.109 @@ -287,8 +287,8 @@
   1.110  	}
   1.111  	Mix_VolumeMusic(SDL_MIX_MAXVOLUME);
   1.112  
   1.113 -    /* Calculate the number of ms for each callback */
   1.114 -    ms_per_step = ((float)mixer->samples * 1000.0) / mixer->freq;
   1.115 +	/* Calculate the number of ms for each callback */
   1.116 +	ms_per_step = ((float)mixer->samples * 1000.0) / mixer->freq;
   1.117  
   1.118  	return(0);
   1.119  }
   1.120 @@ -306,7 +306,7 @@
   1.121  		if ( fp != NULL ) {
   1.122  			fclose(fp);
   1.123  		}
   1.124 -		SDL_SetError("Couldn't read from '%s'", file);
   1.125 +		Mix_SetError("Couldn't read from '%s'", file);
   1.126  		return(NULL);
   1.127  	}
   1.128  	magic[4] = '\0';
   1.129 @@ -315,7 +315,7 @@
   1.130  	/* Allocate memory for the music structure */
   1.131  	music = (Mix_Music *)malloc(sizeof(Mix_Music));
   1.132  	if ( music == NULL ) {
   1.133 -		SDL_SetError("Out of memory");
   1.134 +		Mix_SetError("Out of memory");
   1.135  		return(NULL);
   1.136  	}
   1.137  	music->error = 0;
   1.138 @@ -348,12 +348,12 @@
   1.139  		if ( timidity_ok ) {
   1.140  			music->data.midi = Timidity_LoadSong((char *)file);
   1.141  			if ( music->data.midi == NULL ) {
   1.142 -				SDL_SetError("%s", Timidity_Error());
   1.143 +				Mix_SetError("%s", Timidity_Error());
   1.144  				music->error = 1;
   1.145  			}
   1.146  		}
   1.147  		else {
   1.148 -			SDL_SetError("%s", Timidity_Error());
   1.149 +			Mix_SetError("%s", Timidity_Error());
   1.150  			music->error = 1;
   1.151  		}
   1.152  	} else
   1.153 @@ -364,7 +364,7 @@
   1.154  		music->type = MUS_MP3;
   1.155  		music->data.mp3 = SMPEG_new(file, &info, 0);
   1.156  		if(!info.has_audio){
   1.157 -			SDL_SetError("MPEG file does not have any audio stream.");
   1.158 +			Mix_SetError("MPEG file does not have any audio stream.");
   1.159  			music->error = 1;
   1.160  		}else{
   1.161  			SMPEG_actualSpec(music->data.mp3, &used_mixer);
   1.162 @@ -376,13 +376,13 @@
   1.163  		music->type = MUS_MOD;
   1.164  		music->data.module = MikMod_LoadSong((char *)file, 64);
   1.165  		if ( music->data.module == NULL ) {
   1.166 -			SDL_SetError("%s", _mm_errmsg[_mm_errno]);
   1.167 +			Mix_SetError("%s", _mm_errmsg[_mm_errno]);
   1.168  			music->error = 1;
   1.169  		}
   1.170  	} else
   1.171  #endif
   1.172  	{
   1.173 -		SDL_SetError("Unrecognized music format");
   1.174 +		Mix_SetError("Unrecognized music format");
   1.175  		music->error = 1;
   1.176  	}
   1.177  	if ( music->error ) {
   1.178 @@ -428,7 +428,7 @@
   1.179  				break;
   1.180  #endif
   1.181  #ifdef MP3_MUSIC
   1.182 -		    case MUS_MP3:
   1.183 +			case MUS_MP3:
   1.184  				SMPEG_delete(music->data.mp3);
   1.185  				break;
   1.186  #endif
   1.187 @@ -472,7 +472,7 @@
   1.188  			break;
   1.189  #endif
   1.190  #ifdef MP3_MUSIC
   1.191 -	    case MUS_MP3:
   1.192 +		case MUS_MP3:
   1.193  			SMPEG_enableaudio(music->data.mp3,1);
   1.194  			SMPEG_enablevideo(music->data.mp3,0);
   1.195  			SMPEG_setvolume(music->data.mp3,((float)music_volume/(float)MIX_MAX_VOLUME)*100.0);
   1.196 @@ -501,7 +501,7 @@
   1.197  
   1.198  	if ( lowlevel_play(music) < 0 ) {
   1.199  		return(-1);
   1.200 -    }
   1.201 +	}
   1.202  	music_active = 1;
   1.203  	music_stopped = 0;
   1.204  	music_loops = loops;
   1.205 @@ -518,7 +518,7 @@
   1.206  		music_volume = 0;
   1.207  		if ( Mix_PlayMusic(music, loops) < 0 ) {
   1.208  			return(-1);
   1.209 -        }
   1.210 +		}
   1.211  		music_playing->fade_step = 0;
   1.212  		music_playing->fade_steps = ms/ms_per_step;
   1.213  		music_playing->fading = MIX_FADING_IN;
   1.214 @@ -631,12 +631,13 @@
   1.215  /* Progressively stop the music */
   1.216  int Mix_FadeOutMusic(int ms)
   1.217  {
   1.218 -	if ( music_playing && !music_stopped && (music_playing->fading == MIX_NO_FADING) ) {
   1.219 +	if ( music_playing && !music_stopped &&
   1.220 +	     (music_playing->fading == MIX_NO_FADING) ) {
   1.221  		if ( music_volume > 0 ) {
   1.222  			music_playing->fading = MIX_FADING_OUT;
   1.223  			music_playing->fade_volume = music_volume;
   1.224 -		    music_playing->fade_step = 0;
   1.225 -		    music_playing->fade_steps = ms/ms_per_step;
   1.226 +			music_playing->fade_step = 0;
   1.227 +			music_playing->fade_steps = ms/ms_per_step;
   1.228  			return(1);
   1.229  		}
   1.230  	}