Example #1
0
File: al.c Project: jayschwa/q2pro
void AL_Update(void)
{
    int         i;
    channel_t   *ch;
    vec_t       orientation[6];

    if (!s_active) {
        return;
    }

    paintedtime = cl.time;

    // set listener parameters
    qalListener3f(AL_POSITION, AL_UnpackVector(listener_origin));
    AL_CopyVector(listener_forward, orientation);
    AL_CopyVector(listener_up, orientation + 3);
    qalListenerfv(AL_ORIENTATION, orientation);
    qalListenerf(AL_GAIN, s_volume->value);
    qalDistanceModel(AL_LINEAR_DISTANCE_CLAMPED);

    // update spatialization for dynamic sounds
    ch = channels;
    for (i = 0; i < s_numchannels; i++, ch++) {
        if (!ch->sfx)
            continue;

        if (ch->autosound) {
            // autosounds are regenerated fresh each frame
            if (ch->autoframe != s_framecount) {
                AL_StopChannel(ch);
                continue;
            }
        } else {
            ALenum state;

            qalGetError();
            qalGetSourcei(ch->srcnum, AL_SOURCE_STATE, &state);
            if (qalGetError() != AL_NO_ERROR || state == AL_STOPPED) {
                AL_StopChannel(ch);
                continue;
            }
        }

#ifdef _DEBUG
        if (s_show->integer) {
            Com_Printf("%.1f %s\n", ch->master_vol, ch->sfx->name);
            //    total++;
        }
#endif

        AL_Spatialize(ch);         // respatialize channel
    }

    s_framecount++;

    // add loopsounds
    AL_AddLoopSounds();

    AL_IssuePlaysounds();
}
Example #2
0
 /*
  * Main update function. Called every frame,
  * performes all necessary calculations.
  */
 void
 AL_Update ( void )
 {
   q_int32_t i;
   channel_t *ch;
   vec_t orientation[6];
   paintedtime = cl.time;
   /* set listener (player) parameters */
   AL_CopyVector ( listener_forward, orientation );
   AL_CopyVector ( listener_up, orientation + 3 );
   qalListenerf ( AL_GAIN, s_volume->value );
   qalListenerf ( AL_MAX_GAIN, s_openal_maxgain->value );
   qalDistanceModel ( AL_LINEAR_DISTANCE_CLAMPED );
   qalListener3f ( AL_POSITION, AL_UnpackVector ( listener_origin ) );
   qalListenerfv ( AL_ORIENTATION, orientation );
   /* update spatialization for dynamic sounds */
   ch = channels;

   for ( i = 0; i < s_numchannels; i++, ch++ ) {
     if ( !ch->sfx ) {
       continue;
     }

     if ( ch->autosound ) {
       /* autosounds are regenerated fresh each frame */
       if ( ch->autoframe != s_framecount ) {
         AL_StopChannel ( ch );
         continue;
       }
     } else {
       ALenum state;
       qalGetError();
       qalGetSourcei ( ch->srcnum, AL_SOURCE_STATE, &state );

       if ( ( qalGetError() != AL_NO_ERROR ) || ( state == AL_STOPPED ) ) {
         AL_StopChannel ( ch );
         continue;
       }
     }

     if ( s_show->value ) {
       Com_Printf ( "%3i %s\n", ch->master_vol, ch->sfx->name );
     }

     /* respatialize channel */
     AL_Spatialize ( ch );
   }

   s_framecount++;
   /* add loopsounds */
   AL_AddLoopSounds();
   /* add music */
 #ifdef HT_WITH_OGG
   OGG_Stream();
 #endif
   AL_StreamUpdate();
   AL_IssuePlaysounds();
 }
Example #3
0
/*
 * Stops playback of all channels.
 */
void
AL_StopAllChannels(void)
{
	int i;
	channel_t *ch;

	ch = channels;

	/* It doesn't matter if a channel
	   is active or not. */
	for (i = 0; i < s_numchannels; i++, ch++)
	{
		if (!ch->sfx)
		{
			continue;
		}

		AL_StopChannel(ch);
	}

	s_rawend = 0;

	/* Remove all pending samples */
	AL_StreamDie();
}
Example #4
0
File: al.c Project: jayschwa/q2pro
void AL_PlayChannel(channel_t *ch)
{
    sfxcache_t *sc = ch->sfx->cache;

#ifdef _DEBUG
    if (s_show->integer > 1)
        Com_Printf("%s: %s\n", __func__, ch->sfx->name);
#endif

    ch->srcnum = s_srcnums[ch - channels];
    qalGetError();
    qalSourcei(ch->srcnum, AL_BUFFER, sc->bufnum);
    //qalSourcei(ch->srcnum, AL_LOOPING, sc->loopstart == -1 ? AL_FALSE : AL_TRUE);
    qalSourcei(ch->srcnum, AL_LOOPING, ch->autosound ? AL_TRUE : AL_FALSE);
    qalSourcef(ch->srcnum, AL_GAIN, ch->master_vol);
    qalSourcef(ch->srcnum, AL_REFERENCE_DISTANCE, SOUND_FULLVOLUME);
    qalSourcef(ch->srcnum, AL_MAX_DISTANCE, 8192);
    qalSourcef(ch->srcnum, AL_ROLLOFF_FACTOR, ch->dist_mult * (8192 - SOUND_FULLVOLUME));

    AL_Spatialize(ch);

    // play it
    qalSourcePlay(ch->srcnum);
    if (qalGetError() != AL_NO_ERROR) {
        AL_StopChannel(ch);
    }
}
Example #5
0
/*
 * Plays a channel (in the frontends
 * sense) with OpenAL.
 */
void
AL_PlayChannel(channel_t *ch)
{
    sfxcache_t *sc;
    float vol;

    /* Debug */
    if (s_show->value > 1)
    {
        Com_Printf("%s: %s\n", __func__, ch->sfx->name);
    }

    /* Clamp volume */
    vol = ch->oal_vol;

    if (vol > 1.0f)
    {
        vol = 1.0f;
    }

    sc = ch->sfx->cache;
    ch->srcnum = s_srcnums[ch - channels];

    qalGetError();
    qalSourcef(ch->srcnum, AL_REFERENCE_DISTANCE, SOUND_FULLVOLUME);
    qalSourcef(ch->srcnum, AL_MAX_DISTANCE, 8192);
    qalSourcef(ch->srcnum, AL_ROLLOFF_FACTOR, ch->dist_mult * (8192 - SOUND_FULLVOLUME));
    qalSourcef(ch->srcnum, AL_GAIN, vol);
    qalSourcei(ch->srcnum, AL_BUFFER, sc->bufnum);
    qalSourcei(ch->srcnum, AL_LOOPING, ch->autosound ? AL_TRUE : AL_FALSE);

    if ((ch->entnum == -1) || (ch->entnum == cl.playernum + 1) || !ch->dist_mult)
    {
        /* anything coming from the view entity will always
         * be full volume and at the listeners position */
        qalSource3f(ch->srcnum, AL_POSITION, 0.0f, 0.0f, 0.0f);
        qalSourcei(ch->srcnum, AL_SOURCE_RELATIVE, AL_TRUE);
    }
    else
    {
        /* all other sources are *not* relative */
        qalSourcei(ch->srcnum, AL_SOURCE_RELATIVE, AL_FALSE);
    }


    /* Spatialize it */
    AL_Spatialize(ch);

    /* Play it */
    qalSourcePlay(ch->srcnum);

    /* Do not play broken channels */
    if (qalGetError() != AL_NO_ERROR)
    {
        AL_StopChannel(ch);
    }
}
Example #6
0
void AL_StopAllChannels( void ) {
    int         i;
    channel_t   *ch;

    ch = channels;
    for( i = 0; i < s_numchannels; i++, ch++ ) {
        if (!ch->sfx)
            continue;
        AL_StopChannel( ch );
    }
}
Example #7
0
/*
 * Plays a channel (in the frontends
 * sense) with OpenAL.
 */
void
AL_PlayChannel(channel_t *ch)
{
	sfxcache_t *sc;
	float vol;

	/* Debug */
	if (s_show->value > 1)
	{
		Com_Printf("%s: %s\n", __func__, ch->sfx->name);
	}

	/* Clamp volume */
	vol = ch->oal_vol + s_volume->value;

	if (vol > 1.0f)
	{
		vol = 1.0f;
	}

    sc = ch->sfx->cache;
	ch->srcnum = s_srcnums[ch - channels];

	qalGetError();
	qalSourcef(ch->srcnum, AL_REFERENCE_DISTANCE, SOUND_FULLVOLUME);
	qalSourcef(ch->srcnum, AL_MAX_DISTANCE, 8192);
	qalSourcef(ch->srcnum, AL_ROLLOFF_FACTOR, ch->dist_mult * (8192 - SOUND_FULLVOLUME));
	qalSourcef(ch->srcnum, AL_GAIN, vol);
 	qalSourcei(ch->srcnum, AL_BUFFER, sc->bufnum);
	qalSourcei(ch->srcnum, AL_LOOPING, ch->autosound ? AL_TRUE : AL_FALSE);

	/* Spatialize it */
	AL_Spatialize(ch);

	/* Play it */
	qalSourcePlay(ch->srcnum);

	/* Do not play broken channels */
	if (qalGetError() != AL_NO_ERROR)
	{
		AL_StopChannel(ch);
	}
}
Example #8
0
void
AL_StopAllChannels(void)
{
	int i;
	channel_t *ch;

	ch = channels;

	for (i = 0; i < s_numchannels; i++, ch++)
	{
		if (!ch->sfx)
		{
			continue;
		}

		AL_StopChannel(ch);
	}

	s_rawend = 0;
	S_AL_StreamDie();
}