Exemplo n.º 1
0
int SD_PlayDigitized(word which,int leftpos,int rightpos)
{
   if (!DigiMode)
      return 0;

   if (which >= NumDigi)
      Quit("SD_PlayDigitized: bad sound number %i", which);

   int channel = SD_GetChannelForDigi(which);
   SD_SetPosition(channel, leftpos,rightpos);

   DigiPlaying = true;

   Mix_Chunk *sample = SoundChunks[which];
   if(sample == NULL)
   {
      printf("SoundChunks[%i] is NULL!\n", which);
      return 0;
   }

   if(Mix_PlayChannel(channel, sample, 0) == -1)
      return 0; /* Unable to play sound */

   return channel;
}
Exemplo n.º 2
0
void UpdateSoundLoc(void)
{
	if (SoundPositioned)
	{
		SetSoundLoc(globalsoundx,globalsoundy);
		SD_SetPosition(leftchannel,rightchannel);
	}
}
Exemplo n.º 3
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;
}