Exemple #1
0
int SD_PlayDigitized(const SoundData &which,int leftpos,int rightpos,SoundChannel chan)
{
    if (!DigiMode)
        return 0;

    // If this sound has been played too recently, don't play it again.
    // (Fix for extremely loud sounds when one plays over itself too much.)
    uint32_t currentTick = SDL_GetTicks();
    if (currentTick - SoundInfo.GetLastPlayTick(which) < MIN_TICKS_BETWEEN_DIGI_REPEATS)
        return 0;

    SoundInfo.SetLastPlayTick(which, currentTick);

    int channel = chan;
    if(chan == SD_GENERIC)
    {
        channel = Mix_GroupAvailable(1);
        if(channel == -1) channel = Mix_GroupOldest(1);
        if(channel == -1)           // All sounds stopped in the meantime?
            channel = Mix_GroupAvailable(1);
    }
    SD_SetPosition(channel, leftpos,rightpos);

    DigiPlaying = true;

    Mix_Chunk *sample = reinterpret_cast<Mix_Chunk*> (which.GetData(SoundData::DIGITAL));
    if(sample == NULL)
        return 0;

    Mix_Volume(channel, static_cast<int> (ceil(128.0*MULTIPLY_VOLUME(SoundVolume))));
    if(Mix_PlayChannel(channel, sample, 0) == -1)
    {
        printf("Unable to play sound: %s\n", Mix_GetError());
        return 0;
    }

    // Return channel + 1 because zero is a valid channel.
    return channel + 1;
}