Beispiel #1
0
int dsound_set_listener_3d_position ( vec3d *position )
{

	unsigned int
		dsrval;
#ifdef _WIN32
	dsrval = IDirectSound3DListener_SetPosition ( d3dsound_listener, position->x, position->y, position->z, DS3D_DEFERRED );

	if ( dsrval != DS_OK )
	{

		debug_log ( "Unable to set position of 3d listener object: %s", get_dsound_error_message ( dsrval ) );

		return ( FALSE );
	}
	else
	{

		return ( TRUE );
	}
#endif
}
Beispiel #2
0
void I_UpdateListener(listener3d_t *desc)
{
    float   temp[3], val;
    int     i;

    if(!initOk || !dsListener || !desc) return;
    if(desc->flags & DDLISTENERF_POS)
    {
        for(i=0; i<3; i++) temp[i] = FIX2FLT(desc->pos[i]);
        IDirectSound3DListener_SetPosition(dsListener, temp[VX], temp[VY], temp[VZ], DS3D_DEFERRED);
    }
    if(desc->flags & DDLISTENERF_MOV)
    {
        for(i=0; i<3; i++) temp[i] = FIX2FLT(desc->mov[i]);
        IDirectSound3DListener_SetVelocity(dsListener, temp[VX], temp[VY], temp[VZ], DS3D_DEFERRED);
    }
    if(desc->flags & DDLISTENERF_YAW || desc->flags & DDLISTENERF_PITCH)
    {
        float y, p;
        float top[3];   // Top vectors.
        if(desc->flags & DDLISTENERF_YAW) listenerYaw = desc->yaw;
        if(desc->flags & DDLISTENERF_PITCH) listenerPitch = desc->pitch;
        // The angles in radians.
        y = listenerYaw / 180 * PI;
        p = (listenerPitch-90) / 180 * PI;
        // Calculate the front vector.
        temp[VX] = sin(y) * cos(p);
        temp[VZ] = cos(y) * cos(p);
        temp[VY] = sin(p);
        /*temp[VX] = sin(y);
        temp[VZ] = cos(y);
        temp[VY] = 0;*/
        // And the top vector.
        top[VX] = -sin(y) * sin(p);
        top[VZ] = -cos(y) * sin(p);
        top[VY] = cos(p);
        /*top[VX] = 0;
        top[VY] = 1;
        top[VZ] = 0;*/
        IDirectSound3DListener_SetOrientation(dsListener,
            temp[VX], temp[VY], temp[VZ],   // Front vector.
            top[VX], top[VY], top[VZ], DS3D_DEFERRED);
    }
    if(desc->flags & DDLISTENERF_SET_REVERB && eaxListener)
    {
        val = desc->reverb.space;
        if(desc->reverb.decay > .5)
        {
            // This much decay needs at least the Generic environment.
            if(val < .2) val = .2f;
        }
        EAX_dwSet(DSPROPERTY_EAXLISTENER_ENVIRONMENT,
            val >= 1? EAX_ENVIRONMENT_PLAIN
            : val >= .8? EAX_ENVIRONMENT_CONCERTHALL
            : val >= .6? EAX_ENVIRONMENT_AUDITORIUM
            : val >= .4? EAX_ENVIRONMENT_CAVE
            : val >= .2? EAX_ENVIRONMENT_GENERIC
            : EAX_ENVIRONMENT_ROOM);

        EAX_dwSet(DSPROPERTY_EAXLISTENER_ROOM, volLinearToLog(desc->reverb.volume));

        val = (desc->reverb.decay - .5)*1.5 + 1;
        EAX_fMul(DSPROPERTY_EAXLISTENER_DECAYTIME, val, EAXLISTENER_MINDECAYTIME,
            EAXLISTENER_MAXDECAYTIME);

        val = 1.1 * (1.2 - desc->reverb.damping);
        if(val < .1) val = .1f;
        EAX_dwMul(DSPROPERTY_EAXLISTENER_ROOMHF, val);

        EAX_fSet(DSPROPERTY_EAXLISTENER_ROOMROLLOFFFACTOR, 1.3f);

        EAX_CommitDeferred();
    }
    if(desc->flags & DDLISTENERF_DISABLE_REVERB && eaxListener)
    {
        // Turn off all reverb by setting the room value to -100 dB.
        EAX_dwSet(DSPROPERTY_EAXLISTENER_ROOM, EAXLISTENER_MINROOM);
        EAX_CommitDeferred();
    }
}