コード例 #1
0
ファイル: mix_chunk.hpp プロジェクト: swc4848a/LuaSDL-2.0
		int LOBJECT_METHOD(fadeIn, Mix_Chunk * chunk){
			int channel = -1;
			int loops = 0;
			int ticks = -1;
			int ms = 0;
			int result = 0;

			if (state.is_number(1)){
				channel = state.to_integer(1);
			}
			if (state.is_number(2)){
				loops = state.to_integer(2);
			}
			if (state.is_number(3)){
				ms = state.to_integer(3);
			}
			if (state.is_number(4)){
				ticks = state.to_integer(4);
				result = Mix_FadeInChannelTimed(channel, chunk, loops, ms, ticks);
			}else{
				result = Mix_FadeInChannel(channel, chunk, loops, ms);
			}

			if (result != -1){
				return 1;
			}else{
				return 0;
			}

		}
コード例 #2
0
ファイル: helpers.c プロジェクト: nxths/sdl2-mixer
extern DECLSPEC int SDLCALL
  Mix_FadeInChannel_helper(
    int channel,
    Mix_Chunk *chunk,
    int loops,
    int ms) {

  return Mix_FadeInChannelTimed(channel, chunk, loops, ms, -1);
}
コード例 #3
0
ファイル: sdl2-mixer.c プロジェクト: Moon4u/mruby-sdl2-mixer
static mrb_value
mrb_sdl2_mixer_music_fade_in_timed(mrb_state *mrb, mrb_value self)
{
  Mix_Chunk *c;
  mrb_int channel, loops, ms, ticks;
  mrb_get_args(mrb, "iiii", &channel, &loops, &ms, &ticks);
  c = mrb_sdl2_chunk_get_ptr(mrb, self);
  return mrb_fixnum_value(Mix_FadeInChannelTimed(channel, c, loops, ms, ticks));
}
コード例 #4
0
ファイル: rubygame_sound.c プロジェクト: atiaxi/rubygame
/* Play the sound, fading in, repeating, and stopping as specified.
 * fade_in and stop_after are in milliseconds!
 */
static int _rg_sound_play( RG_Sound *sound, 
                            int fade_in, int repeats, int stop_after )
{

	/* Open audio if it's not already. Return -1 if it failed. */
	if( ensure_open_audio() != 0 )
	{
		return -1;
	}

	/* If it's already playing on a channel, stop it first. */
	if( _rg_sound_channel_check(sound) )
	{
		Mix_HaltChannel( sound->channel );
	}

	/* Find first available channel */
	sound->channel = Mix_GroupAvailable(-1);

	if( sound->channel == -1 )
	{
		/* No channels were available, so make one more than there are now.
		 * (Mix_AllocateChannels(-1) returns the current number of channels)
		 */
		Mix_AllocateChannels( Mix_AllocateChannels(-1) + 1 );

		/* Try again. */
		sound->channel = Mix_GroupAvailable(-1);
	}
	
	/* Set its volume before we play */
	Mix_Volume( sound->channel, (int)(MIX_MAX_VOLUME * sound->volume) );


	if( fade_in <= 0 )
	{
		/* Play sound without fading in */
		return Mix_PlayChannelTimed( sound->channel, sound->wrap->chunk,
		                             repeats, stop_after );
	}
	else
	{
		/* Play sound with fading in */
		return Mix_FadeInChannelTimed( sound->channel, sound->wrap->chunk,
		                               repeats, fade_in, stop_after );
	}
}
コード例 #5
0
ファイル: rubysdl_mixer.c プロジェクト: ohai/rubysdl
static VALUE Mixer_s_fadeInChannelTimed(VALUE mod,
                                        VALUE channel,
                                        VALUE wave,
                                        VALUE loops,
                                        VALUE ms, VALUE ticks)
{
    int playing_channel;

    playing_channel = Mix_FadeInChannelTimed(NUM2INT(channel),
                      Get_Mix_Chunk(wave),
                      NUM2INT(loops),
                      NUM2INT(ms),
                      NUM2INT(ticks));
    if( playing_channel == -1 ) {
        rb_raise(eSDLError, "couldn't play wave: %s",
                 Mix_GetError());
    }
    /* to avoid gc problem */
    rb_ary_store(playing_wave, playing_channel, wave);
    return INT2FIX(playing_channel);
}
コード例 #6
0
ファイル: sound.cpp プロジェクト: aquileia/wesnoth
void play_sound_internal(const std::string& files, channel_group group, unsigned int repeats,
			unsigned int distance, int id, int loop_ticks, int fadein_ticks)
{
	if(files.empty() || distance >= DISTANCE_SILENT || !mix_ok) {
		return;
	}

	audio_lock lock;

	// find a free channel in the desired group
	int channel = Mix_GroupAvailable(group);
	if(channel == -1) {
		LOG_AUDIO << "All channels dedicated to sound group(" << group << ") are busy, skipping.\n";
		return;
	}

	Mix_Chunk *chunk;
	std::string file = pick_one(files);

	try {
		chunk = load_chunk(file, group);
		assert(chunk);
	} catch(const chunk_load_exception&) {
		return;
	}

	/*
	 * This check prevents SDL_Mixer from blowing up on Windows when UI sound is played
	 * in response to toggling the checkbox which disables sound.
	 */
	if(group != SOUND_UI) {
		Mix_SetDistance(channel, distance);
	}

	int res;
	if(loop_ticks > 0) {
		if(fadein_ticks > 0) {
			res = Mix_FadeInChannelTimed(channel, chunk, -1, fadein_ticks, loop_ticks);
		} else {
			res = Mix_PlayChannel(channel, chunk, -1);
		}

		if(res >= 0) {
			Mix_ExpireChannel(channel, loop_ticks);
		}
	} else {
		if(fadein_ticks > 0) {
			res = Mix_FadeInChannel(channel, chunk, repeats, fadein_ticks);
		} else {
			res = Mix_PlayChannel(channel, chunk, repeats);
		}
	}

	if(res < 0) {
		ERR_AUDIO << "error playing sound effect: " << Mix_GetError() << std::endl;
		//still keep it in the sound cache, in case we want to try again later
		return;
	}

	channel_ids[channel] = id;

	//reserve the channel's chunk from being freed, since it is playing
	channel_chunks[res] = chunk;
}
コード例 #7
0
 int SDLPlayAudioFadeInTimed(Mix_Chunk* SDLAudioClip, unsigned int fadeTime, unsigned int time, int loopCount)
 {
     Mix_FadeInChannelTimed(-1, SDLAudioClip, loopCount, fadeTime, time);
 }
コード例 #8
0
ファイル: Channel.cpp プロジェクト: Jedzia/Humbug
//fade in
bool CChannel::FadeIn(CSound* pSound,int ms,int loops,int ticks)
{
	//fade in the sound
	return(Mix_FadeInChannelTimed(m_Channel,pSound->GetChunk(),loops,ms,ticks)!=-1);
}