예제 #1
0
/* ----------------------------------------------------------------------------
 * Play the sample.
 * max_override_pos: Override the currently playing sound
 *   only if it's already in this position, or beyond.
 *   This is in seconds. 0 means always override. -1 means never override.
 * loop: Loop the sound?
 * gain: Volume, 0 - 1.
 * pan: Panning, 0 - 1 (0.5 is centered).
 * speed: Playing speed.
 */
void sample_struct::play(
    const float max_override_pos, const bool loop, const float gain,
    const float pan, const float speed
) {
    if(!sample || !instance) return;
    
    if(max_override_pos != 0 && al_get_sample_instance_playing(instance)) {
        float secs = al_get_sample_instance_position(instance) / (float) 44100;
        if(
            (secs < max_override_pos && max_override_pos > 0) ||
            max_override_pos == -1
        ) {
            return;
        }
    }
    
    al_set_sample_instance_playmode(
        instance, (loop ? ALLEGRO_PLAYMODE_LOOP : ALLEGRO_PLAYMODE_ONCE)
    );
    al_set_sample_instance_gain(instance, gain);
    al_set_sample_instance_pan(instance, pan);
    al_set_sample_instance_speed(instance, speed);
    
    al_set_sample_instance_position(instance, 0);
    al_set_sample_instance_playing( instance, true);
}
예제 #2
0
static int allua_sample_instance_set_speed(lua_State * L)
{
   ALLUA_sample_instance si = allua_check_sample_instance(L, 1);
   float val = luaL_checknumber(L, 2);
   lua_pushboolean(L, al_set_sample_instance_speed(si, val));
   return 1;
}
예제 #3
0
static void t3f_play_queued_sample(void)
{
	int i;
	
	if(t3f_sample_queue[0])
	{
		t3f_queue_sample_instance = al_create_sample_instance(t3f_sample_queue[0]);
		al_set_sample_instance_gain(t3f_queue_sample_instance, t3f_sound_volume);
		al_set_sample_instance_speed(t3f_queue_sample_instance, 1.0);
		al_set_sample_instance_pan(t3f_queue_sample_instance, 0.0);
		al_play_sample_instance(t3f_queue_sample_instance);
		for(i = 0; i < t3f_queued_samples - 1; i++)
		{
			t3f_sample_queue[i] = t3f_sample_queue[i + 1];
		}
		t3f_sample_queue[i] = NULL;
		t3f_queued_samples--;
	}
}
예제 #4
0
파일: sound.c 프로젝트: sesc4mt/mvcdecoder
/* the main music player function */
static void music_player()
{
   int i, note;

   for (i=0; i<NUM_PARTS; i++) {
      if (part_time[i] <= 0) {
	 note = part_pos[i][0];
	 part_time[i] = part_pos[i][1];

	 al_stop_sample_instance(part_voice[i]);

	 if (i == 3) {
	    if (note == 1) {
	       al_set_sample(part_voice[i], bd);
	       al_set_sample_instance_pan(part_voice[i], PAN(128));
	    }
	    else if (note == 2) {
	       al_set_sample(part_voice[i], snare);
	       al_set_sample_instance_pan(part_voice[i], PAN(160));
	    }
	    else {
	       al_set_sample(part_voice[i], hihat);
	       al_set_sample_instance_pan(part_voice[i], PAN(96));
	    }

	    al_play_sample_instance(part_voice[i]);
	 }
	 else {
	    if (note > 0) {
	       al_set_sample_instance_speed(part_voice[i], freq_table[note]/22050.0);
	       al_play_sample_instance(part_voice[i]);
	    }
	 }

	 part_pos[i] += 2;
	 if (!part_pos[i][1])
	    part_pos[i] = part_ptr[i];
      }

      part_time[i]--;
   }
}
예제 #5
0
static bool do_play_sample(ALLEGRO_SAMPLE_INSTANCE *splinst,
   ALLEGRO_SAMPLE *spl, float gain, float pan, float speed, ALLEGRO_PLAYMODE loop)
{
   if (!al_set_sample(splinst, spl)) {
      ALLEGRO_ERROR("al_set_sample failed\n");
      return false;
   }

   if (!al_set_sample_instance_gain(splinst, gain) ||
         !al_set_sample_instance_pan(splinst, pan) ||
         !al_set_sample_instance_speed(splinst, speed) ||
         !al_set_sample_instance_playmode(splinst, loop)) {
      return false;
   }

   if (!al_play_sample_instance(splinst)) {
      ALLEGRO_ERROR("al_play_sample_instance failed\n");
      return false;
   }

   return true;
}
예제 #6
0
void AllegroSoundSample5::SetPitch( float value )
{
	if ( !m_pInstance )
		return;
	al_set_sample_instance_speed( m_pInstance, value );
}