Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


OpenAL trouble

This topic is 5652 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m trying to get OpenAL working in my game, but I can''t get it to work quite right. The distant-sound-fading-out effect (i can''t remember the proper name) only works on 1 axis (the X I think, maybe the Z. I can''t keep them straight! It''s parallel to the ground, anyways) and the stereo effect is all messed up. If you cross the axis perpendicular (I think Z) then it''ll switch speakers. Lemme see if I can draw a picture:
     X Axis
       |                 <----> Moving out here has no effect on stereo!
    <--|-->  Stereo works when moving back and forth across this axis
     Distance fading works when moving along this axis
I''m calling this code once per frame:
	// Set the OpenAL listener position

		CVector position = currentlistener->position / DISTANCE_FACTOR;
		alListener3f(AL_POSITION, position.x, position.y, position.z);
		// Set the OpenAL listener orientation

		CVector up = currentlistener->up;
		CVector forward = currentlistener->lookAt;
		float orientation[6] = { forward.x, forward.y, forward.z, up.x, up.y, up.z };
		alListenerfv(AL_ORIENTATION, orientation);
		// Set the OpenAL listener velocity

		CVector vel = currentlistener->velocity / DISTANCE_FACTOR;
		alListener3f(AL_VELOCITY, vel.x, vel.y, vel.z);
I hope this all makes sense. Does anyone have any ideas about what''s wrong?

Share this post

Link to post
Share on other sites
Well, I don''t have time at the moment to look into your code, here''s mine though, it works, also called every frame.

static void update_sound(void)
static ALfloat lispos[] = {0.0, 0.0, 0.0};

static ALfloat lisorient[] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};

lispos[0] = ViewMoveMatrix[12] / 4;
lispos[1] = ViewMoveMatrix[13] / 4;
lispos[2] = ViewMoveMatrix[14] / 4;

glGetFloatv(GL_MODELVIEW_MATRIX, ptSoundMatrix);

lisorient[0] = SoundMatrix[2];
lisorient[1] = SoundMatrix[6];
lisorient[2] = SoundMatrix[10];

lisorient[3] = SoundMatrix[1];
lisorient[4] = SoundMatrix[5];
lisorient[5] = SoundMatrix[9];

alListenerfv(AL_ORIENTATION, lisorient);

alListenerfv(AL_POSITION, lispos);

At least it''s very tidy The effect is called attenuation.

Share this post

Link to post
Share on other sites
Hmmm... extracting orientation for the modelview matrix? I guess I''ll try that.

BTW, I''ve gotten it to work lots better than it did yesturday. Attentuation, doppler, and panning all work to an extent, but there''s still some problems with the orientation. It seems like it works OK as long as you''re on one side of the source, but move to the other side and it doesn''t. I also can''t seem to get the scale right. Like 10.0 in OpenAL world is HUGE where 10.0 in OpenGL world is TINY!

Share this post

Link to post
Share on other sites
Well, I''ve tried using the modelview matrix, but I still can''t get the orientation to work right. What kind of coordinate system are you using? I''m using X and Z as forwards and sideways and Y is up and down.

BTW, where you divide the position by 4, does that mean that OpenAL''s scale is 4 times bigger than OpenGL''s scale?

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!