OpenAL problems

Started by
5 comments, last by Insodus 20 years, 6 months ago
I''m coding a cross platform FPS with OpenAL right. Now it''s going fine, OpenAL is working fine. Then, I don''t know what I changed but I dont hear any sounds at all anymore. Ok, so I try to isolate the problem, I can''t figure out whats wrong. So I strip it down to just this code...

	ALuint sounds[10];
	ALuint sources[10];

	ALint audio_error;
	alutInit(0, NULL);
	if ((audio_error = alGetError()) != AL_NO_ERROR) {
		erLogError(ER_AUDIO, "Couldn''t start OpenAL", audio_error);
	}
	atexit(alutExit);

	alGenBuffers(10, sounds);
	if ((audio_error = alGetError()) != AL_NO_ERROR) {
		erLogError(ER_AUDIO, "Couldn''t start OpenAL", audio_error);
	}
	alGenSources(10, sources);
	if ((audio_error = alGetError()) != AL_NO_ERROR) {
		erLogError(ER_AUDIO, "Couldn''t start OpenAL", audio_error);
	}

	ALint format;
	void* data;
	ALsizei size, freq;
	ALboolean loop;

	alutLoadWAVFile("phaser.wav",&format,&data,&size,&freq,&loop);
	alBufferData(sounds[0],format,data,size,freq);
	alutUnloadWAV(format,data,size,freq);

	alSourcei(sources[0], AL_BUFFER, sounds[0]);
	alSourcei(sources[0], AL_LOOPING, AL_TRUE);
	alSource3f(sources[0], AL_POSITION, 0, 0, 0);
	alSource3f(sources[0], AL_VELOCITY, 0, 0, 0);

	alListener3f(AL_POSITION, 0, 0, 0);
	alListener3f(AL_ORIENTATION, 1, 1, 1);
	alListener3f(AL_VELOCITY, 0, 0, 0);

	alSourcePlay(sources[0]);
	if ((audio_error = alGetError()) != AL_NO_ERROR) {
		erLogError(ER_AUDIO, "Couldn''t play OpenAL source", audio_error);
	}
I also used to have error checking on the load WAV but that works fine. The problem seems to be a AL_INVALID_NAME error coming from the alSourcePlay call. What the hell does that mean? In the source it says "Illegal name passed as an argument to an AL call." That just doesn''t make sense. Any ideas whats going on here?
---------------------------------"Without C, all we would have is Pasal, Basi, and obol.""Black holes are where god divided by zero."http://www.insodus.com
Advertisement
sources[0] NULL?

alBufferData(sounds[0],format,data,size,freq);
alSourcei(sources[0], AL_BUFFER, sounds[0]);
alSourcei(sources[0], AL_LOOPING, AL_TRUE);
alSource3f(sources[0], AL_POSITION, 0, 0, 0);
alSource3f(sources[0], AL_VELOCITY, 0, 0, 0);

Im just about to start using openAL, but I would guess sources[0] is NULL, or had a Error within one of those calls. =/
-BourkeIV
Indeed my friend.

I also get the AL_INVALID_NAME on the line...
alSourcei(sources[0], AL_BUFFER, sounds[0]);

I noticed the value of sounds[0] is not initialized. (Instead of something normal like 0 through 10 its 4134551) This must mean then that the file isnt being loaded correctly? Or that the alBufferData function isnt working?

[edited by - Insodus on October 11, 2003 3:34:22 AM]
---------------------------------"Without C, all we would have is Pasal, Basi, and obol.""Black holes are where god divided by zero."http://www.insodus.com
Are these global or local?

ALuint sounds[10];
ALuint sources[10];
global
---------------------------------"Without C, all we would have is Pasal, Basi, and obol.""Black holes are where god divided by zero."http://www.insodus.com
I believe that OpenAL errors are sticky, ie set until they are read.

Meaning that if you have an code

alBufferData(sounds[0],format,data,size,freq);
alSourcei(sources[0], AL_BUFFER, sounds[0]);
alSourcei(sources[0], AL_LOOPING, AL_TRUE);
alSource3f(sources[0], AL_POSITION, 0, 0, 0);
alSource3f(sources[0], AL_VELOCITY, 0, 0, 0);
errorcheck = alGetError();

And the first line causes an error then even if all the other lines execute ok you will still read an error when you check at the end. Therefore it''s sensible to clear the error and then execute your openal commands:

alGetError(); // clear error value
alBufferData(sounds[0],format,data,size,freq);
if( alGetError() != AL_NO_ERROR)
// error occured.

I would (and do) check for errors after every OpenAL call, I suggest you add these checks to your code to see where the problem first occurs.

Next as far as I know alListener AL_ORIENTATION takes 6 values:
ALfloat v[6];
v[0] = forwardX;
v[1] = forwardY;
v[2] = forwardZ;
v[4] = upX;
v[5] = upY;
v[6] = upZ;
alListenerfv(AL_ORIENTATION, v);

Otherwise you code seems (worryingly) fine.

Things to try :
1. Generate just the one source and hold it in an ALuint rather than an array.
2. Instead of using sounds and sources to pass to alGenSource etc use &sounds[0] and &sources[0]
3. Use a ''proper'' OpenAl device setup. ie alcOpenDevice,alcCreateContext, alcMakeContextCurrent. It''s hardly more difficult than the alutInit setup (pass NULL to OpenDevice to get the default/preferered device).



Sorry I meant:

v[0] = forwardX
v[1] = forwardY
v[2] = forwardZ
v[3] = upX
v[4] = upY
v[5] = upZ

of course!!

PS. What version of OpenAL are you using, and on which platform?

This topic is closed to new replies.

Advertisement