/* Change the group of a channel */ int Mix_GroupChannel(int which, int tag) { if ( which < 0 || which > num_channels ) return(0); Mix_LockAudio(); mix_channel[which].tag = tag; Mix_UnlockAudio(); return(1); }
void native_midi_stop() { if (currentsong) { SDL_PauseAudio(1); Mix_UnlockAudio(); MusicPlayerStop(currentsong->player); currentsong = NULL; Mix_LockAudio(); SDL_PauseAudio(0); } }
/* Fade in a sound on a channel, over ms milliseconds */ int Mix_FadeInChannelTimed(int which, Mix_Chunk *chunk, int loops, int ms, int ticks) { int i; /* Don't play null pointers :-) */ if ( chunk == NULL ) { return(-1); } if ( !checkchunkintegral(chunk)) { Mix_SetError("Tried to play a chunk with a bad frame"); return(-1); } /* Lock the mixer while modifying the playing channels */ Mix_LockAudio(); { /* If which is -1, play on the first free channel */ if ( which == -1 ) { for ( i=reserved_channels; i<num_channels; ++i ) { if ( mix_channel[i].playing <= 0 ) break; } if ( i == num_channels ) { which = -1; } else { which = i; } } /* Queue up the audio data for this channel */ if ( which >= 0 && which < num_channels ) { Uint32 sdl_ticks = SDL_GetTicks(); if (Mix_Playing(which)) _Mix_channel_done_playing(which); mix_channel[which].samples = chunk->abuf; mix_channel[which].playing = chunk->alen; mix_channel[which].looping = loops; mix_channel[which].chunk = chunk; mix_channel[which].paused = 0; mix_channel[which].fading = MIX_FADING_IN; mix_channel[which].fade_volume = mix_channel[which].volume; mix_channel[which].fade_volume_reset = mix_channel[which].volume; mix_channel[which].volume = 0; mix_channel[which].fade_length = (Uint32)ms; mix_channel[which].start_time = mix_channel[which].ticks_fade = sdl_ticks; mix_channel[which].expire = (ticks > 0) ? (sdl_ticks+ticks) : 0; } } Mix_UnlockAudio(); /* Return the channel on which the sound is being played */ return(which); }
/* Add your own music player or mixer function. If 'mix_func' is NULL, the default music player is re-enabled. */ void Mix_HookMusic(void (*mix_func)(void *udata, Uint8 *stream, int len), void *arg) { Mix_LockAudio(); if ( mix_func != NULL ) { music_data = arg; mix_music = mix_func; } else { music_data = NULL; mix_music = music_mixer; } Mix_UnlockAudio(); }
/* Change the expiration delay for a channel */ int Mix_ExpireChannel(int which, int ticks) { int status = 0; if ( which == -1 ) { int i; for ( i=0; i < num_channels; ++ i ) { status += Mix_ExpireChannel(i, ticks); } } else if ( which < num_channels ) { Mix_LockAudio(); mix_channel[which].expire = (ticks>0) ? (SDL_GetTicks() + ticks) : 0; Mix_UnlockAudio(); ++ status; } return(status); }
/* Halt playing of a particular channel */ int Mix_HaltChannel(int which) { int i; if ( which == -1 ) { for ( i=0; i<num_channels; ++i ) { Mix_HaltChannel(i); } } else if ( which < num_channels ) { Mix_LockAudio(); if (mix_channel[which].playing) { _Mix_channel_done_playing(which); mix_channel[which].playing = 0; mix_channel[which].looping = 0; } mix_channel[which].expire = 0; if(mix_channel[which].fading != MIX_NO_FADING) /* Restore volume */ mix_channel[which].volume = mix_channel[which].fade_volume_reset; mix_channel[which].fading = MIX_NO_FADING; Mix_UnlockAudio(); } return(0); }
/* Free an audio chunk previously loaded */ void Mix_FreeChunk(Mix_Chunk *chunk) { int i; /* Caution -- if the chunk is playing, the mixer will crash */ if ( chunk ) { /* Guarantee that this chunk isn't playing */ Mix_LockAudio(); if ( mix_channel ) { for ( i=0; i<num_channels; ++i ) { if ( chunk == mix_channel[i].chunk ) { mix_channel[i].playing = 0; mix_channel[i].looping = 0; } } } Mix_UnlockAudio(); /* Actually free the chunk */ if ( chunk->allocated ) { SDL_free(chunk->abuf); } SDL_free(chunk); } }
/* Dynamically change the number of channels managed by the mixer. If decreasing the number of channels, the upper channels are stopped. */ int Mix_AllocateChannels(int numchans) { if ( numchans<0 || numchans==num_channels ) return(num_channels); if ( numchans < num_channels ) { /* Stop the affected channels */ int i; for(i=numchans; i < num_channels; i++) { Mix_UnregisterAllEffects(i); Mix_HaltChannel(i); } } Mix_LockAudio(); mix_channel = (struct _Mix_Channel *) SDL_realloc(mix_channel, numchans * sizeof(struct _Mix_Channel)); if ( numchans > num_channels ) { /* Initialize the new channels */ int i; for(i=num_channels; i < numchans; i++) { mix_channel[i].chunk = NULL; mix_channel[i].playing = 0; mix_channel[i].looping = 0; mix_channel[i].volume = SDL_MIX_MAXVOLUME; mix_channel[i].fade_volume = SDL_MIX_MAXVOLUME; mix_channel[i].fade_volume_reset = SDL_MIX_MAXVOLUME; mix_channel[i].fading = MIX_NO_FADING; mix_channel[i].tag = -1; mix_channel[i].expire = 0; mix_channel[i].effects = NULL; mix_channel[i].paused = 0; } } num_channels = numchans; Mix_UnlockAudio(); return(num_channels); }
/* Resume a paused channel */ void Mix_Resume(int which) { Uint32 sdl_ticks = SDL_GetTicks(); Mix_LockAudio(); if ( which == -1 ) { int i; for ( i=0; i<num_channels; ++i ) { if ( mix_channel[i].playing > 0 ) { if(mix_channel[i].expire > 0) mix_channel[i].expire += sdl_ticks - mix_channel[i].paused; mix_channel[i].paused = 0; } } } else if ( which < num_channels ) { if ( mix_channel[which].playing > 0 ) { if(mix_channel[which].expire > 0) mix_channel[which].expire += sdl_ticks - mix_channel[which].paused; mix_channel[which].paused = 0; } } Mix_UnlockAudio(); }
void Mix_ChannelFinished(void (*channel_finished)(int channel)) { Mix_LockAudio(); channel_done_callback = channel_finished; Mix_UnlockAudio(); }