예제 #1
0
static mrb_value
mrb_sdl2_mixer_chunk_play(mrb_state *mrb, mrb_value self)
{
  Mix_Chunk *c;
  mrb_int channel, loops, ticks;
  int result;
  int argc = mrb_get_args(mrb, "ii|i", &channel, &loops, &ticks);
  c = mrb_sdl2_chunk_get_ptr(mrb, self);
  if (argc == 2) {
    result = Mix_PlayChannelTimed(channel, c, loops, -1);
  } else {
    result = Mix_PlayChannelTimed(channel, c, loops, ticks);
  }
  return mrb_fixnum_value(result);
}
예제 #2
0
static int I_SDL_StartSound(int id, int channel, int vol, int sep)
{
    Mix_Chunk *chunk;

    if (!sound_initialized)
        return -1;

    // Release a sound effect if there is already one playing
    // on this channel

    ReleaseSoundOnChannel(channel);

    // Get the sound data

    chunk = GetSFXChunk(id);

    if (chunk == NULL)
        return -1;

    // play sound

    Mix_PlayChannelTimed(channel, chunk, 0, -1);

    channels_playing[channel] = id;

    // set separation, etc.

    I_SDL_UpdateSoundParams(channel, vol, sep);

    return channel;
}
예제 #3
0
void THSoundEffects::_playRaw(size_t iIndex, int iVolume)
{
    int iChannel = reserveChannel();

    Mix_Volume(iChannel, iVolume);
    Mix_PlayChannelTimed(iChannel, m_ppSounds[iIndex], 0, -1);
}
예제 #4
0
static int I_SDL_StartSound(sfxinfo_t *sfxinfo, int channel, int vol, int sep)
{
    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 = sfxinfo->driver_data;

    // play sound

    Mix_PlayChannelTimed(channel, &snd->chunk, 0, -1);

    channels_playing[channel] = sfxinfo;

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

    return channel;
}
예제 #5
0
void sound_player::play_raw(size_t iIndex, int iVolume)
{
    int iChannel = reserve_channel();

    Mix_Volume(iChannel, iVolume);
    Mix_PlayChannelTimed(iChannel, sounds[iIndex], 0, -1);
}
예제 #6
0
		int LOBJECT_METHOD(play, Mix_Chunk * chunk){
			int channel = -1;
			int loops = 0;
			int ticks = -1;
			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)){
				ticks = state.to_integer(3);
				result = Mix_PlayChannelTimed(channel, chunk, loops, ticks);
			}else{
				result = Mix_PlayChannel(channel, chunk, loops);
			}
			
			if (result != -1){
				return 1;
			}else{
				return 0;
			}

		}
예제 #7
0
파일: helpers.c 프로젝트: nxths/sdl2-mixer
extern DECLSPEC int SDLCALL
  Mix_PlayChannel_helper(
    int channel,
    Mix_Chunk *chunk,
    int loops) {

  return Mix_PlayChannelTimed(channel, chunk, loops, -1);
}
예제 #8
0
bool ChunkEntry::play()
{
    if (channel != -1)
        Mix_HaltChannel(channel);
    if(!chunk)
        return false;
    return (Mix_PlayChannelTimed(channel, chunk, 0, -1) != -1);
}
예제 #9
0
파일: audio.c 프로젝트: mafiosso/mgean
void
MG_play_music (int *channel, int ms_expire, int current_time, Mix_Chunk * m)
{
  if ((current_time < ms_expire) || !m)
    return;

  if (*channel == -1)
    {
      *channel = Mix_PlayChannelTimed (-1, m, 1, ms_expire);
      printf ("got channel: %d\n", *channel);
    }
  else
    {
      Mix_HaltChannel (*channel);
      Mix_PlayChannelTimed (*channel, m, 1, ms_expire);
    }
}
예제 #10
0
void soundLib::play_timed_sfx(Uint8 sfx, int time) {
	if (game_config.sound_enabled == false) {
        return;
	}

	if (sfx_list[sfx] != NULL) {
		Mix_PlayChannelTimed(-1, sfx_list[sfx], -1 , time);
	}
}
예제 #11
0
파일: mixdll.cpp 프로젝트: nedbrek/tclsdl
	bool playSound(const char *filename, int chn, int loop, int ticks)
	{
		Mix_Chunk *chk = loadSound(filename);
		if (!chk)
			return false;

		int ret = Mix_PlayChannelTimed(chn, chk, loop, ticks);
		return ret != -1;
	}
예제 #12
0
void THSoundEffects::_playRaw(size_t iIndex, int iVolume)
{
    // NB: Callers ensure that m_iChannelStatus != 0
    int iChannel = 0;
    for(; (m_iChannelStatus & (1 << iChannel)) == 0; ++iChannel) {}
    m_iChannelStatus &=~ (1 << iChannel);

    Mix_Volume(iChannel, iVolume);
    Mix_PlayChannelTimed(iChannel, m_ppSounds[iIndex], 0, -1);
}
예제 #13
0
void mix_adsr(Mix_Chunk *sample,int counter){

  // violine
  int attack = 500;
  int decay = 300;
  int sustain = 10;
  int release = 750; 

  if(Mix_PlayChannelTimed(-1, sample, -1 , attack)==-1) {
    printf("Mix_PlayChannel: %s\n",Mix_GetError());
  }
  Mix_VolumeChunk(sample, volume);
  if(Mix_PlayChannelTimed(-1, sample, -1 , decay)==-1) {
    printf("Mix_PlayChannel: %s\n",Mix_GetError());
  }
  if(Mix_PlayChannelTimed(-1, sample, -1 , attack)==-1) {
    printf("Mix_PlayChannel: %s\n",Mix_GetError());
  } 

}
예제 #14
0
// Play WAV
bool ModuleAudio::PlayFx(uint id, uint duration)
{
	bool ret = false;

	if (fx[id] != nullptr)
	{
		Mix_PlayChannelTimed(-1, fx[id], 1, duration);
		ret = true;
	}

	return ret;
}
예제 #15
0
// Returns an integer for the channel this chunk is playing at
// Returns -1 for errors
int SDLAudio::play_chunk(int index, int loops, int channel, int ticks) {
  Mix_Chunk *chunk = m_chunks[index];
  
  if (channel != -1 && Mix_Playing(channel) != 0) {
    // the channel is already playing
    std::cout << "Warning: Channel " << channel << " is already playing. Will Halt It." << std::endl;
  }
  channel = Mix_PlayChannelTimed(channel, chunk, loops, ticks);
  if (channel == -1) {
    logError(std::cout, "Play Wav Chunk");
    return -1;
  }

  return channel;
}
예제 #16
0
/* 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 );
	}
}
예제 #17
0
static VALUE Mixer_s_playChannelTimed(VALUE mod,
                                      VALUE channel,
                                      VALUE wave,
                                      VALUE loops,
                                      VALUE ticks)
{
    int play_channel;

    play_channel = Mix_PlayChannelTimed(NUM2INT(channel),
                                        Get_Mix_Chunk(wave),
                                        NUM2INT(loops),
                                        NUM2INT(ticks));
    if( play_channel == -1 ) {
        rb_raise(eSDLError, "couldn't play wave: %s",
                 Mix_GetError());
    }

    rb_ary_store(playing_wave, play_channel, wave);/* to avoid gc problem */
    return INT2FIX(play_channel);
}
예제 #18
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_StartSound (int id, int vol, int sep, int pitch, bool loop)
{
	if(!sound_initialized)
		return 0;

	Mix_Chunk *chunk = (Mix_Chunk *)S_sfx[id].data;
	int channel;
	
	// find a free channel, starting from the first after
	// the last channel we used

	channel = nextchannel;

	do
	{
		channel = (channel + 1) % NUM_CHANNELS;

		if (channel == nextchannel)
		{
			fprintf(stderr, "No free sound channels left.\n");
			return -1;
		}
        } while (channel_in_use[channel] != -1);

	nextchannel = channel;

	// play sound

	Mix_PlayChannelTimed(channel, chunk, loop ? -1 : 0, -1);

	channel_in_use[channel] = 1;

	// set seperation, etc.
	I_UpdateSoundParams(channel, vol, sep, pitch);

	return channel;
}
예제 #19
0
 void Sound::play(int16 loops, int16 delay) const {
     if (_chunk) {
         loops = loops > 0 ? loops - 1 : loops;
         SDL_Check(Mix_PlayChannelTimed(_channel, _chunk, loops, delay));
     }
 }
예제 #20
0
int main(int argc, char *argv[]) try
{
   setPath(argv[0]);
   
   bool shaders = true;
   
   // load tune if argument is given
   for (int i=1; i<argc; ++i)
   {
      const std::string arg = argv[i];
      if (arg == "--no-shaders")
         shaders = false;
      else
         loadTune(arg);
   }

   class InitAndQuit
   {
      public:
         InitAndQuit(bool shadersOn)
         {
            if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) != 0)
            {
               std::ostringstream error;
               error << "Failed on SDL_Init: " << SDL_GetError() << "\n";
               throw std::runtime_error(error.str());
            }
            graphics::setupGraphics(shadersOn);
            SDL_WM_SetCaption("Sousaphone Hero", "Sousaphone Hero");
            if(Mix_OpenAudio(AUDIO_RATE, AUDIO_FORMAT, AUDIO_CHANNELS, AUDIO_BUFFERS) != 0)
            {
               SDL_Quit();
               std::ostringstream error;
               error << "Failed on Mix_OpenAudio: " << Mix_GetError() << "\n";
               throw std::runtime_error(error.str());
            }

            std::srand(time(NULL));

            Mix_ChannelFinished(doChangedNotes); // set callback function

            startTiming();
         }

         ~InitAndQuit()
         {
            graphics::cleanupGraphics();
            Mix_CloseAudio();
            SDL_Quit();
         }
   } iandq(shaders);

   // load all the notes (to load them)
   getNoteA(); getNoteB(); getNoteC(); getNoteD(); getNoteE(); getNoteF(); getNoteG();

   const bool demoMode = false;

   double lastNoteFraction = 0;

   int channel = -1;

   bool tuneStarted = false;

   try
   {
      while(1)
      {
         const double currentNoteFraction = noteFraction();
         if (currentNoteFraction < lastNoteFraction) // i.e. we have wrapped round a note
         {
            incrementTune();
            if (demoMode)
            {
               const char current = getCurrentNote();
               if (current != NO_NOTE_CHARACTER)
               {
                  if (channel != -1)
                     Mix_HaltChannel(channel);

                  channel = Mix_PlayChannelTimed(-1, getNote(current).get(), -1, NOTE_DURATION);
               }
            }
         }
         lastNoteFraction = currentNoteFraction;

         if ((getTimeSinceStart() > graphics::ZOOM_OUT_LENGTH*1000.0) && !tuneStarted)
         {
            startTune();
            tuneStarted = true;
         }

         //SDL_Delay(100);

         doIOLoop();
         playAppropriateNote();
         graphics::draw(currentNoteFraction);
         graphics::updateScreen();
         score::doEveryLoop();
      }
   }
   catch(QuitSignal&)
   {} // do nothing

   return 0;
} catch (std::exception& error)
{
   std::cout << error.what();
   return 1;
}
 int SDLPlayAudioTimed(Mix_Chunk* SDLAudioClip, unsigned int time, int loopCount)
 {
     return Mix_PlayChannelTimed(-1, SDLAudioClip, loopCount, time);
 }
예제 #22
0
 void SDLSoundBufferMemory::play(int _channel, bool _loop)
 {
     Mix_PlayChannelTimed(_channel, &m_chunk, _loop ? -1 : 0, -1);
 }
예제 #23
0
int Mix_PlayChannel(int channel, Mix_Chunk *chunk, int loops)
{
	return Mix_PlayChannelTimed(channel, chunk, loops, -1);
}
예제 #24
0
void Musica::playSonido(int id){
	switch(id){
		case SELECT: {

			if( !this->s_select ) this->s_select = Mix_LoadWAV("TPTaller/sonido/MINETICK.WAV");
			if(this->s_select == NULL){
				loguear();
				logFile << "No se pudo cargar sonido: %s" << Mix_GetError() << endl;
				return;
			}
			Mix_PlayChannel(-1, this->s_select, 0);
			break;
		}
		case UP: {
			if( !this->s_jump ) this->s_jump = Mix_LoadWAV("TPTaller/sonido/JUMP1.WAV");
			if(this->s_jump == NULL){
				loguear();
				logFile << "No se pudo cargar sonido: %s" << Mix_GetError() << endl;
				return;
			}
			//Mix_VolumeChunk(this->s_jump, 100);
			Mix_PlayChannelTimed(-1, this->s_jump, 0, 1000);
			//Mix_PlayChannel(-1, this->s_jump, 0);
			break;
		}
		case TIME: {
			if( !this->s_time ) this->s_time = Mix_LoadWAV("TPTaller/sonido/clock-ticking-2.wav");
			if(this->s_time == NULL){
				loguear();
				logFile << "No se pudo cargar sonido: %s" << Mix_GetError() << endl;
				return;
			}
			Mix_VolumeChunk(this->s_time, 128);
			Mix_PlayChannelTimed(-1, this->s_time, -1, 10000);
			//Mix_PlayChannel(-1, this->s_time, 0);
			break;
		}
		case START: {
			if( !this->s_start ) this->s_start = Mix_LoadWAV("TPTaller/sonido/StartRound.wav");
			if(this->s_start == NULL){
				loguear();
				logFile << "No se pudo cargar sonido: %s" << Mix_GetError() << endl;
				return;
			}
			Mix_PlayChannel(-1, this->s_start, 0);
			break;
		}

		//Caso Lanzar TIpo disparo
		case DISPARO: {
			if( !this->s_disparo ) this->s_disparo = Mix_LoadWAV("TPTaller/sonido/gunFire.wav");
			if(this->s_disparo == NULL){
				loguear();
				logFile << "No se pudo cargar sonido: %s" << Mix_GetError() << endl;
				return;
			}
			//printf("disparo\n");
			Mix_VolumeChunk(this->s_disparo, 100);
			//Mix_PlayChannelTimed(-1, this->s_disparo, 0, 500);
			Mix_PlayChannel(-1, this->s_disparo, 0);
			break;
		}
		case LANZAR_DINAMITA: {
			if( !this->s_dinamita ) this->s_dinamita = Mix_LoadWAV("TPTaller/sonido/export (1).wav");//dinamita.wav
			if(this->s_dinamita == NULL){
				loguear();
				logFile << "No se pudo cargar sonido: %s" << Mix_GetError() << endl;
				return;
			}
			//printf("Sonido Lanzar dinamita\n");
			Mix_VolumeChunk(this->s_dinamita, 80);
			Mix_PlayChannel(1, this->s_dinamita, 0);
			//Mix_PlayChannelTimed(-1, this->s_dinamita, -1, 4500);
			break;
		}

		case MECHA_DINAMITA: {
			if( !this->s_mecha ) this->s_mecha = Mix_LoadWAV("TPTaller/sonido/mechadinamita.WAV");
			if(this->s_mecha == NULL){
				loguear();
				logFile << "No se pudo cargar sonido: %s" << Mix_GetError() << endl;
				return;
			}
			//printf("sonido mecha dinamita\n");
			Mix_PlayChannelTimed(-1, this->s_mecha, -1, 4500);
			break;
		}
		//Lanzar no disparo
		case LANZAR:{
			if( !this->s_lanzar ) this->s_lanzar = Mix_LoadWAV("TPTaller/sonido/lanzar4.wav");
			if(this->s_lanzar == NULL){
				loguear();
				logFile << "No se pudo cargar sonido: %s" << Mix_GetError() << endl;
				return;
			}
			Mix_PlayChannel(-1, this->s_lanzar, 0);
			break;

		}
		//EXPLOSIONES
		case EXPLOSION_BAZOOKA: {
			if( !this->s_eBazooka ) this->s_eBazooka = Mix_LoadWAV("TPTaller/sonido/Explosion2.wav");
			if(this->s_eBazooka == NULL){
				loguear();
				logFile << "No se pudo cargar sonido: %s" << Mix_GetError() << endl;
				return;
			}
			Mix_PlayChannel(-1, this->s_eBazooka, 0);
			break;

		}
		case EXPLOSION_GRANADA:{
			if( !this->s_eGranada ) this->s_eGranada = Mix_LoadWAV("TPTaller/sonido/Explosion2.wav");
			if(this->s_eGranada == NULL){
				loguear();
				logFile << "No se pudo cargar sonido: %s" << Mix_GetError() << endl;
				return;
			}
			Mix_PlayChannel(-1, this->s_eGranada, 0);
			break;
		}
		case EXPLOSION_DINAMITA:{
			if( !this->s_eDinamita ) this->s_eDinamita = Mix_LoadWAV("TPTaller/sonido/Explosion3.WAV");
			if(this->s_eDinamita == NULL){
				loguear();
				logFile << "No se pudo cargar sonido: %s" << Mix_GetError() << endl;
				return;
			}
			Mix_PlayChannel(-1, this->s_eDinamita, 0);
			break;
		}
		case EXPLOSION_HOLY:{
			if( !this->s_eHoly ) this->s_eHoly = Mix_LoadWAV("TPTaller/sonido/holy.WAV");
			if(this->s_eHoly == NULL){
				loguear();
				logFile << "No se pudo cargar sonido: %s" << Mix_GetError() << endl;
				return;
			}
			Mix_PlayChannel(-1, this->s_eHoly, 0);
			break;
		}
		case KAMIKAZE:{
			if( !this->s_kamikaze ) this->s_kamikaze = Mix_LoadWAV("TPTaller/sonido/KAMIKAZERELEASE.WAV");
			if(this->s_kamikaze == NULL){
				loguear();
				logFile << "No se pudo cargar sonido: %s" << Mix_GetError() << endl;
				return;
			}
			Mix_PlayChannel(-1, this->s_kamikaze, 0);
			break;
		}
		case PATADA:{
			if( !this->s_patada ) this->s_patada = Mix_LoadWAV("TPTaller/sonido/patada3.wav");
			if(this->s_patada == NULL){
				loguear();
				logFile << "No se pudo cargar sonido: %s" << Mix_GetError() << endl;
				return;
			}
			Mix_PlayChannel(-1, this->s_patada, 0);
			break;
		}
		case FUEGO:{
			if( !this->s_fuego ) this->s_fuego = Mix_LoadWAV("TPTaller/sonido/fuego.WAV");
			if(this->s_fuego == NULL){
				loguear();
				logFile << "No se pudo cargar sonido: %s" << Mix_GetError() << endl;
				return;
			}
			Mix_PlayChannel(-1, this->s_fuego, 0);
			break;
		}
		case BYE:{
			if( !this->s_bye ) this->s_bye = Mix_LoadWAV("TPTaller/sonido/BYEBYE.WAV");
			if(this->s_bye == NULL){
				loguear();
				logFile << "No se pudo cargar sonido: %s" << Mix_GetError() << endl;
				return;
			}
			Mix_PlayChannel(-1, this->s_bye, 0);
			break;
		}
		case WALK:{
			if( !this->s_walk ) this->s_walk = Mix_LoadWAV("TPTaller/sonido/walk-expand.wav");
			if(this->s_walk == NULL){
				loguear();
				logFile << "No se pudo cargar sonido: %s" << Mix_GetError() << endl;
				return;
			}
			//Mix_PlayChannelTimed(1, this->s_walk, 0, 500);
			Mix_PlayChannel(-1, this->s_walk, 0);
			break;
		}
		case TICK: {
			if( !this->s_tick ) this->s_tick = Mix_LoadWAV("TPTaller/sonido/tick.WAV");
			if(this->s_tick == NULL){
				loguear();
				logFile << "No se pudo cargar sonido: %s" << Mix_GetError() << endl;
				return;
			}
			Mix_VolumeChunk(this->s_tick, 128);
			Mix_PlayChannelTimed(-1, this->s_tick, 0, 1000);

			//Mix_PlayChannel(0, this->s_tick, 0);
			break;
		}
		case VIDA:{
			if( !this->s_vida ) this->s_vida = Mix_LoadWAV("TPTaller/sonido/OUCH.WAV");
			if(this->s_vida == NULL){
				loguear();
				logFile << "No se pudo cargar sonido: %s" << Mix_GetError() << endl;
				return;
			}
			//printf("Pierde vida\n");
			Mix_PlayChannel(-1, this->s_vida, 0);
			break;
		}
	}
}
예제 #25
0
파일: Channel.cpp 프로젝트: Jedzia/Humbug
//play
bool CChannel::Play(CSound* pSound,int loops,int ticks)
{
	//play the sound
	return(Mix_PlayChannelTimed(m_Channel,pSound->GetChunk(),loops,ticks)!=-1);
}