Jump to content


need openal help


5 replies to this topic

#1 animatedantmo

    New Member

  • Members
  • Pip
  • 4 posts

Posted 30 April 2006 - 04:55 PM

Im trying to see if i can produce a working openal console proj from "scratch". I can get the sample code to compile without errors but whenever i simply transfer the code to a blank project i can not produce any sounds. I recieve two warnings about the depricated alut functions but that is it. Would someone be kind enough to look at the code and tell me if i have done anything wrong?



#include <al/alut.h>  

#include <al/Framework.h>



#define WAV_FILE "smile.wav"


// Position of the source sound.

ALfloat SourcePos[] = { 0.0, 0.0, 0.0 };


// Velocity of the source sound.

ALfloat SourceVel[] = { 0.0, 0.0, 0.0 };



// Position of the Listener.

ALfloat ListenerPos[] = { 0.0, 0.0, 0.0 };


// Velocity of the Listener.

ALfloat ListenerVel[] = { 0.0, 0.0, 0.0 };


// Orientation of the Listener. (first 3 elements are "at", second 3 are "up")

// Also note that these should be units of '1'.

ALfloat ListenerOri[] = { 0.0, 0.0, -1.0,  0.0, 1.0, 0.0 };




int main()

{

	ALuint buffer;

	ALuint source;


	

	ALenum format;

	ALsizei size;

	ALvoid *data;

	ALsizei freq;

	ALboolean loop;


	ALint error;


	ALCdevice *device = alcOpenDevice(NULL);

	

	if (device) 

	{

		ALCcontext *context = alcCreateContext(device,NULL);

		alcMakeContextCurrent(context);

	}

	alGetError(); // clear error code

	alGenBuffers(1, &buffer);

	if ((error = alGetError()) != AL_NO_ERROR)

	{

		return(-1);

	}

	// Load test.wav

	alutLoadWAVFile(WAV_FILE,&format,&data,&size,&freq,&loop);

	if ((error = alGetError()) != AL_NO_ERROR)

	{

		alDeleteBuffers(1, &buffer);

		return(-2);

	}

	// Copy test.wav data into AL Buffer 0

	alBufferData(buffer,format,data,size,freq);

	if ((error = alGetError()) != AL_NO_ERROR)

	{

		alDeleteBuffers(1, &buffer);

		return(-3);

	}

	// Unload test.wav

	alutUnloadWAV(format, data, size, freq);

	if ((error = alGetError()) != AL_NO_ERROR)

	{

		alDeleteBuffers(1, &buffer);

	        return(-4);

	}

	// Generate Sources

	alGenSources(1, &source);

	if ((error = alGetError()) != AL_NO_ERROR)

	{

		return(-5);

	}


	

	alSourcei (source, AL_BUFFER,   buffer   );

	alSourcef (source, AL_PITCH,    1.0      );

	alSourcef (source, AL_GAIN,     1.0      );

	alSourcefv(source, AL_POSITION, SourcePos);

	alSourcefv(source, AL_VELOCITY, SourceVel);

	alSourcei (source, AL_LOOPING,  loop     );

	

	

	if(alGetError() != AL_NO_ERROR)

		return(-6);




	// Attach buffer 0 to source

	alSourcei(source, AL_BUFFER, buffer);

	if ((error = alGetError()) != AL_NO_ERROR)

	{

	      return(-7);

	}


	alListenerfv(AL_POSITION,    ListenerPos);

	alListenerfv(AL_VELOCITY,    ListenerVel);

	alListenerfv(AL_ORIENTATION, ListenerOri);



	alSourcePlay(source); 


	// EXIT

	ALCcontext *Context=alcGetCurrentContext();

	ALCdevice *Device=alcGetContextsDevice(Context);

	alcMakeContextCurrent(NULL);

	alcDestroyContext(Context);

	alcCloseDevice(Device);


	return(0);

}



#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 4782 posts
  • LocationBellevue, WA

Posted 30 April 2006 - 05:02 PM

When you transfer the code to a blank project, are you setting it to link with the OpenAL libraries? Also, is "smile.wav" in the new project directory?
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 animatedantmo

    New Member

  • Members
  • Pip
  • 4 posts

Posted 30 April 2006 - 05:46 PM

Reedbeta said:

When you transfer the code to a blank project, are you setting it to link with the OpenAL libraries? Also, is "smile.wav" in the new project directory?

I believe i have set it to link to the openal lib otherwise i would get linker errors right? I have "alut.lib OpenAL32.lib" listed in the additional dependencies spot for the linker settings. and smile.wav is in the project directory (with the main.cpp file)

#4 _fs

    New Member

  • Members
  • Pip
  • 1 posts

Posted 01 May 2006 - 07:29 AM

If you're using windows check any openal dlls are accessable (in the path or the same directory as the program)

#5 animatedantmo

    New Member

  • Members
  • Pip
  • 4 posts

Posted 01 May 2006 - 05:11 PM

_fs said:

If you're using windows check any openal dlls are accessable (in the path or the same directory as the program)

alut.dll is in the directory but i dont have any openal dll files. also the program doesnt run without the alut.dll file so does that mean alut.dll is the only one it needs?

#6 animatedantmo

    New Member

  • Members
  • Pip
  • 4 posts

Posted 12 May 2006 - 06:51 PM

OK i managed to get sound to work. I used a different OpenAL32.dll and that seemed to fix the problem.

Thanks for trying guys :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users