示例#1
0
/**
 * @brief Plays a sound in a group.
 *
 *    @param group Group to play sound in.
 *    @param sound Sound to play.
 *    @param once Whether to play only once.
 *    @return 0 on success.
 */
int sound_mix_playGroup( int group, alSound *s, int once )
{
   int ret, channel;

   /* Get the channel. */
   channel = Mix_GroupAvailable(group);
   if (channel == -1) {
      channel = Mix_GroupOldest(group);
      if (channel == -1) {
         WARN("Group '%d' has no free channels!", group);
         return -1;
      }
   }

   /* Play the sound. */
   ret = Mix_PlayChannel( channel, s->u.mix.buf, (once == 0) ? -1 : 0 );
   if (ret < 0) {
      WARN("Unable to play sound %s for group %d: %s",
            s->name, group, Mix_GetError());
      return -1;
   }
   else
      Mix_Volume( channel, sound_mixVolume );

   return 0;
}
示例#2
0
static mrb_value
mrb_sdl2_mixer_group_oldest(mrb_state *mrb, mrb_value self)
{
  mrb_int tag;
  mrb_get_args(mrb, "i", &tag);
  return mrb_fixnum_value(Mix_GroupOldest(tag));
}
示例#3
0
	static int lua_Mix_GroupOldest(State & state){
		Stack * stack = state.stack;
		int tag = -1;
		if (stack->is<LUA_TNUMBER>(1)){
			tag = stack->to<int>(1);
		}
		int result = Mix_GroupOldest(tag);
		if (result >= 0){
			stack->push<int>(result);
		}else{
			stack->push<bool>(false);
		}
		return 1;
	}
示例#4
0
int SD_GetChannelForDigi(int which)
{
   int channel;
   if(DigiChannel[which] != -1)
      return DigiChannel[which];

   channel = Mix_GroupAvailable(1);
   if(channel == -1)
      channel = Mix_GroupOldest(1);

   if(channel == -1)           /* All sounds stopped in the meantime? */
      return Mix_GroupAvailable(1);
   return channel;
}
示例#5
0
int SDLAudio::OldestGROUP(std::string name)
{
    /** Check to see if we've created it */
    SListIterator<SGZChanGroup*> GroupListITR = GroupList.GetIterator();

    for( GroupListITR.Start(); GroupListITR.Valid(); GroupListITR.Forth() )
        if((GroupListITR.Item()->Name.compare(name))==0)
        {
            return Mix_GroupOldest(GroupListITR.Item()->groupNum);
        }

    SGZLogger.warn("AudioMAN: Group \"%s\" doesn't exist!\n", name.c_str());
    return 0;
}
示例#6
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;
}