/* otherwhise. NOP if the music is playing */ static int music_halt_or_loop (void) { /* Restart music if it has to loop */ if (!music_internal_playing()) { /* Restart music if it has to loop at a high level */ if (music_loops && --music_loops) { Mix_Fading current_fade = music_playing->fading; music_internal_play(music_playing, 0.0); music_playing->fading = current_fade; } else { music_internal_halt(); if (music_finished_hook) music_finished_hook(); return 0; } } return 1; }
/* otherwhise. NOP if the music is playing */ static int music_halt_or_loop (void) { /* Restart music if it has to loop */ if (!music_internal_playing()) { #ifdef USE_NATIVE_MIDI /* Native MIDI handles looping internally */ if (music_playing->type == MUS_MID && native_midi_ok) { music_loops = 0; } #endif /* Restart music if it has to loop at a high level */ if (music_loops) { Mix_Fading current_fade; --music_loops; current_fade = music_playing->fading; music_internal_play(music_playing, 0.0); music_playing->fading = current_fade; } else { music_internal_halt(); if (music_finished_hook) music_finished_hook(); return 0; } } return 1; }
int Mix_FadeInMusicPos(Mix_Music *music, int loops, int ms, double position) { int retval; if ( ms_per_step == 0 ) { SDL_SetError("Audio device hasn't been opened"); return(-1); } /* Don't play null pointers :-) */ if ( music == NULL ) { Mix_SetError("music parameter was NULL"); return(-1); } /* Setup the data */ if ( ms ) { music->fading = MIX_FADING_IN; } else { music->fading = MIX_NO_FADING; } music->fade_step = 0; music->fade_steps = ms/ms_per_step; /* Play the puppy */ SDL_LockAudio(); /* If the current music is fading out, wait for the fade to complete */ while ( music_playing && (music_playing->fading == MIX_FADING_OUT) ) { SDL_UnlockAudio(); SDL_Delay(100); SDL_LockAudio(); } music_active = 1; if (loops == 1) { /* Loop is the number of times to play the audio */ loops = 0; } music_loops = loops; retval = music_internal_play(music, position); SDL_UnlockAudio(); return(retval); }
/* Mixing function */ void music_mixer(void *udata, Uint8 *stream, int len) { Mix_Music *music_playing_aux = music_playing;//maks if ( music_playing_aux && music_active ) { /* Handle fading */ if ( music_playing_aux->fading != MIX_NO_FADING ) { if ( music_playing_aux->fade_step++ < music_playing_aux->fade_steps ) { int volume; int fade_step = music_playing_aux->fade_step; int fade_steps = music_playing_aux->fade_steps; if ( music_playing_aux->fading == MIX_FADING_OUT ) { volume = (music_volume * (fade_steps-fade_step)) / fade_steps; } else { /* Fading in */ volume = (music_volume * fade_step) / fade_steps; } music_internal_volume(volume); } else { if ( music_playing_aux->fading == MIX_FADING_OUT ) { music_internal_halt(); if ( music_finished_hook ) { music_finished_hook(); } return; } music_playing_aux->fading = MIX_NO_FADING; } } /* Restart music if it has to loop */ if ( !music_internal_playing() ) { /* Restart music if it has to loop at a high level */ if ( music_loops && --music_loops ) { Mix_Fading current_fade = music_playing_aux->fading; music_internal_play(music_playing_aux, 0.0); music_playing_aux->fading = current_fade; } else { music_internal_halt(); if ( music_finished_hook ) { music_finished_hook(); } return; } } switch (music_playing_aux->type) { #ifdef CMD_MUSIC case MUS_CMD: /* The playing is done externally */ break; #endif #ifdef WAV_MUSIC case MUS_WAV: WAVStream_PlaySome(stream, len); break; #endif #ifdef MOD_MUSIC case MUS_MOD: VC_WriteBytes((SBYTE *)stream, len); if ( music_swap8 ) { Uint8 *dst; int i; dst = stream; for ( i=len; i; --i ) { *dst++ ^= 0x80; } } else if ( music_swap16 ) { Uint8 *dst, tmp; int i; dst = stream; for ( i=(len/2); i; --i ) { tmp = dst[0]; dst[0] = dst[1]; dst[1] = tmp; dst += 2; } } break; #endif #ifdef MID_MUSIC #ifdef USE_TIMIDITY_MIDI case MUS_MID: if ( timidity_ok ) { int samples = len / samplesize; Timidity_PlaySome(stream, samples); } break; #endif #endif #ifdef OGG_MUSIC case MUS_OGG: OGG_playAudio(music_playing_aux->data.ogg, stream, len); break; #endif #ifdef MP3_MUSIC case MUS_MP3: //maks //SMPEG_playAudio(music_playing_aux->data.mp3, stream, len); { static Uint8 *mp3Buf = NULL; static int lenBuf = 0; int decoded; if(!mp3Buf || len > lenBuf) mp3Buf = realloc(mp3Buf, len); lenBuf = len; decoded = MAD_Decode(music_playing_aux->data.mp3, mp3Buf, len, used_mixer.channels); if(decoded > 0) { SDL_MixAudio(stream, mp3Buf, decoded, music_playing_aux->data.mp3->volume); } else { music_playing_aux->data.mp3->playing = 0; } } break; #endif default: /* Unknown music type?? */ break; } } }