Ejemplo n.º 1
0
/* Fade out a channel and then stop it automatically */
int Mix_FadeOutChannel(int which, int ms)
{
    int status;

    status = 0;
    if ( audio_opened ) {
        if ( which == -1 ) {
            int i;

            for ( i=0; i<num_channels; ++i ) {
                status += Mix_FadeOutChannel(i, ms);
            }
        } else if ( which < num_channels ) {
            Mix_LockAudio();
            if ( mix_channel[which].playing &&
                    (mix_channel[which].volume > 0) &&
                    (mix_channel[which].fading != MIX_FADING_OUT) ) {
                mix_channel[which].fade_volume = mix_channel[which].volume;
                mix_channel[which].fading = MIX_FADING_OUT;
                mix_channel[which].fade_length = (Uint32)ms;
                mix_channel[which].ticks_fade = SDL_GetTicks();

                /* only change fade_volume_reset if we're not fading. */
                if (mix_channel[which].fading == MIX_NO_FADING) {
                    mix_channel[which].fade_volume_reset = mix_channel[which].volume;
                }
                ++status;
            }
            Mix_UnlockAudio();
        }
    }
    return(status);
}
Ejemplo n.º 2
0
void native_midi_start(NativeMidiSong *song, int loops)
{
    int vol;

    if (song == NULL)
        return;

    SDL_PauseAudio(1);
    Mix_UnlockAudio();

    if (currentsong)
        MusicPlayerStop(currentsong->player);

    currentsong = song;
    currentsong->loops = loops;

    MusicPlayerPreroll(song->player);
    MusicPlayerSetTime(song->player, 0);
    MusicPlayerStart(song->player);

    GetSequenceAudioUnit(song->sequence, &song->audiounit);

    vol = latched_volume;
    latched_volume++;  /* just make this not match. */
    native_midi_setvolume(vol);

    Mix_LockAudio();
    SDL_PauseAudio(0);
}
Ejemplo n.º 3
0
/* Set a function that is called after all mixing is performed.
   This can be used to provide real-time visual display of the audio stream
   or add a custom mixer filter for the stream data.
*/
void Mix_SetPostMix(void (*mix_func)
                    (void *udata, Uint8 *stream, int len), void *arg)
{
    Mix_LockAudio();
    mix_postmix_data = arg;
    mix_postmix = mix_func;
    Mix_UnlockAudio();
}
Ejemplo n.º 4
0
int Mix_UnregisterAllEffects(int channel)
{
    int retval;
    Mix_LockAudio();
    retval = _Mix_UnregisterAllEffects_locked(channel);
    Mix_UnlockAudio();
    return(retval);
}
Ejemplo n.º 5
0
int Mix_UnregisterEffect(int channel, Mix_EffectFunc_t f)
{
    int retval;
    Mix_LockAudio();
    retval = _Mix_UnregisterEffect_locked(channel, f);
    Mix_UnlockAudio();
    return(retval);
}
Ejemplo n.º 6
0
int Mix_RegisterEffect(int channel, Mix_EffectFunc_t f,
                       Mix_EffectDone_t d, void *arg)
{
    int retval;
    Mix_LockAudio();
    retval = _Mix_RegisterEffect_locked(channel, f, d, arg);
    Mix_UnlockAudio();
    return retval;
}
Ejemplo n.º 7
0
/* 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);
}
Ejemplo n.º 8
0
void native_midi_stop()
{
    if (currentsong) {
        SDL_PauseAudio(1);
        Mix_UnlockAudio();
        MusicPlayerStop(currentsong->player);
        currentsong = NULL;
        Mix_LockAudio();
        SDL_PauseAudio(0);
    }
}
Ejemplo n.º 9
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);
}
Ejemplo n.º 10
0
/* 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();
}
Ejemplo n.º 11
0
/* 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);
}
Ejemplo n.º 12
0
/* 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);
}
Ejemplo n.º 13
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);
    }
}
Ejemplo n.º 14
0
/* 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);
}
Ejemplo n.º 15
0
/* 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();
}
Ejemplo n.º 16
0
void Mix_ChannelFinished(void (*channel_finished)(int channel))
{
    Mix_LockAudio();
    channel_done_callback = channel_finished;
    Mix_UnlockAudio();
}