Exemple #1
0
//
// Starting a sound means adding it
//  to the current list of active sounds
//  in the internal channels.
// As the SFX info struct contains
//  e.g. a pointer to the raw data,
//  it is ignored.
// As our sound handling does not handle
//  priority, it is ignored.
// Pitching (that is, increased speed of playback)
//  is set, but currently not used by mixing.
//
int I_SDL_StartSound(sfxinfo_t *sfxinfo, int channel, int vol, int sep, int pitch)
{
    allocated_sound_t   *snd;

    if (!sound_initialized || channel < 0 || channel >= NUM_CHANNELS)
        return -1;

    // Release a sound effect if there is already one playing
    // on this channel
    ReleaseSoundOnChannel(channel);

    // Get the sound data
    if (!LockSound(sfxinfo))
        return -1;

    snd = GetAllocatedSoundBySfxInfoAndPitch(sfxinfo, pitch);

    if (!snd)
    {
        allocated_sound_t       *newsnd;

        // fetch the base sound effect, un-pitch-shifted
        snd = GetAllocatedSoundBySfxInfoAndPitch(sfxinfo, NORM_PITCH);
        if (!snd)
            return -1;

        if (s_randompitch)
        {
            newsnd = PitchShift(snd, pitch);
            if (newsnd)
            {
                LockAllocatedSound(newsnd);
                UnlockAllocatedSound(snd);
                snd = newsnd;
            }
        }
    }
    else
        LockAllocatedSound(snd);

    // play sound
    Mix_PlayChannel(channel, &snd->chunk, 0);

    channels_playing[channel] = snd;

    // set separation, etc.
    I_SDL_UpdateSoundParams(channel, vol, sep);

    return channel;
}
Exemple #2
0
// Load a SFX chunk into memory and ensure that it is locked.
static dboolean LockSound(sfxinfo_t *sfxinfo)
{
    // If the sound isn't loaded, load it now
    if (!GetAllocatedSoundBySfxInfoAndPitch(sfxinfo, NORM_PITCH))
        if (!CacheSFX(sfxinfo))
            return false;

    LockAllocatedSound(GetAllocatedSoundBySfxInfoAndPitch(sfxinfo, NORM_PITCH));

    return true;
}
Exemple #3
0
static boolean LockSound(sfxinfo_t *sfxinfo)
{
    // If the sound isn't loaded, load it now

    if (sfxinfo->driver_data == NULL)
    {
        if (!CacheSFX(sfxinfo))
        {
            return false;
        }
    }

    LockAllocatedSound(sfxinfo->driver_data);

    return true;
}