OpenAL: "No sound" problem
#1
Posted 06 May 2005 - 01:56 PM
I have begun to work with OpenAL as part of my game to get some sounds (and later music) going. Though, when I first compiled my game (no errors or warnings) and ran it, there was no sound to be heard. I quad-checked everything, and it was in order.
I then downloaded one of the samples from this site (great site btw!), and it ran just fine. I could even modify it. But... if I use the very same .CPP file from the sample in my own project file (linking to OpenAL32.lib and alut.lib), I get the same problem as above, there is no sound to be heard. I am checking if the file I am attempting to load is existant and the path is correct, so that is not the problem.
Have I managed to miss something important in the project settings??
#2
Posted 06 May 2005 - 05:44 PM
// The includes at the top of the file.
#include <alut.h>
#include <al.h>
// Global variables.
ALuint Buffer;
ALuint Source;
ALfloat SourcePos[] = { 0.0, 0.0, 0.0 };
ALfloat SourceVel[] = { 0.0, 0.0, 0.0 };
ALfloat ListenerPos[] = { 0.0, 0.0, 0.0 };
ALfloat ListenerVel[] = { 0.0, 0.0, 0.0 };
ALfloat ListenerOri[] = { 0.0, 0.0, -1.0, 0.0, 0.0, 1.0 }; // Z is up for me. 2D game.
// Special AL functions.
ALboolean LoadALData()
{
// Variables to load into.
ALenum format;
ALsizei size;
ALvoid* data;
ALsizei freq;
ALboolean loop;
// Load wav data into a buffer.
alGenBuffers(1, &Buffer);
if (alGetError() != AL_NO_ERROR)
return AL_FALSE;
FILE *fp = fopen("wavdata/phaser.wav", "r");
if (!fp)
MessageBox(NULL, "Error loading sound!", "Error", MB_OK);
else
fclose(fp);
alutLoadWAVFile("wavdata/phaser.wav", &format, &data, &size, &freq, &loop);
alBufferData(Buffer, format, data, size, freq);
alutUnloadWAV(format, data, size, freq);
// Bind buffer with a source.
alGenSources(1, &Source);
if (alGetError() != AL_NO_ERROR)
return AL_FALSE;
alSourcei (Source, AL_BUFFER, Buffer );
alSourcef (Source, AL_PITCH, 1.0f );
alSourcef (Source, AL_GAIN, 1.0f );
alSourcefv(Source, AL_POSITION, SourcePos);
alSourcefv(Source, AL_VELOCITY, SourceVel);
alSourcei (Source, AL_LOOPING, AL_TRUE );
// Do another error check and return.
if (alGetError() == AL_NO_ERROR)
return AL_TRUE;
return AL_FALSE;
}
void SetListenerValues()
{
alListenerfv(AL_POSITION, ListenerPos);
alListenerfv(AL_VELOCITY, ListenerVel);
alListenerfv(AL_ORIENTATION, ListenerOri);
}
void KillALData()
{
alDeleteBuffers(1, &Buffer);
alDeleteSources(1, &Source);
alutExit();
}
// Excerpt from the main() function.
alutInit(NULL, 0);
alGetError();
if (LoadALData() == AL_FALSE)
return -1;
SetListenerValues();
alSourcePlay(Source);
// Excerpt from the keyboard control function.
if (key == 'p')
alSourcePlay(Source);
if (key == 'o')
alSourceStop(Source);
if (key == 27) { KillALData(); exit(0); }
The program uses GLUT to draw a window and OpenGL to draw primitives (it's just my simulator thingy where I test mathematical stuff).
That should work, right? I have included OpenAL32.lib and alut.lib in the Linker. And the phaser.wav file is in the correct location. Have I missed something?
#3
Posted 07 May 2005 - 09:40 AM
It seems that the OpenAL32.dll that comes with the OpenAL SDK is errorful. When I use that one, I get no sounds, but programs can be quit without problems. If I use the one I already had (no idea where it came from, but probably either with Windows, the soundcard or some driver), I get sounds but an error whenever I close any program using OpenAL.
Has anyone else experienced a similar problem?
#4
Posted 28 October 2005 - 12:50 PM
When I run the example binary it plays sounds, if I build it from the source code... I get no errors but also no sound.
Can you send me the lib file that works for you, so I can try it?
#5
Posted 26 November 2005 - 04:20 AM
I had the same problem afer updating the library. It looks the problem is in the alutInit function which doesn't seem to work properly anymore.
You have to initialize the device and context directly, for example, like this:
>>>>>>>>>>>>>>>>>
ALCcontext *Context;
ALCdevice *Device;
Device = alcOpenDevice((ALchar*)"DirectSound3D");
if (Device == NULL)
{
exit(-1);
}
//Create context(s)
Context=alcCreateContext(Device,NULL);
//Set active context
alcMakeContextCurrent(Context);
alGetError();
<<<<<<<<<<<<<<<<<<
we'd also note that the alutLoadWavfile function is now deprecated (but still works fine in current version).
Hope this helps.
cheers,
Roberto
#6
Posted 26 November 2005 - 11:32 AM
rdillon said:
ALut now comes in its own dll/lib (don't know which as I do not actually use it, I load all the sound data myself), so alutLoadWav is probably in there, rather than actually being depreciated.
Spree
#7
Posted 27 November 2005 - 05:19 AM
I am not sure what you mean by "depreciated".... actually, the ALUT specification published on the official OpenAL site (http://www.openal.or...specs/alut.html) clearly states that AlutLoadWavFile, ALutLoadWavMemory and AlutUnloadWav are now deprecated but still available for backward compatibility.
Interestingly, the same document doesn't say anything particular about the AlutInit function which was the one causing the problem here reported (at least on my machine).
All best!
Roberto
#8
Posted 27 November 2005 - 11:54 AM
Reading the OpenAL developers mailing list doesn't really make this clear though, as there seems to be a lot of too'ing and fro'ing about it.
But it looks like it has been replaced with alutCreateBufferFromFile (and the various variations that come with it), which seems to work in a similar way.
Spree
#9
Posted 25 January 2006 - 01:36 AM
#10
Posted 04 February 2006 - 10:37 AM
Device = alcOpenDevice((ALchar*)"DirectSound3D");
I just use:
Device= alcOpenDevice(NULL);
and it does the trick for me using the new 1.1 lib. I seem to remember not getting any love from the DirectSound3D flag.
Also, the SDK documentation just recommended initializing this way as well IIRC..
#11
Posted 20 February 2006 - 04:16 AM
Plays on the onboard nvidia sound, but my Audigy won't play sounds.
OpenAL initialises, inits buffers, sources, plays the source, i get no sound, and no error.
I dont know if its a driver issue, or just openal being crap. Driving me insaine.
#12
Posted 20 February 2006 - 05:19 AM
#13
Posted 20 February 2006 - 10:36 AM
was almost going to convert my sound handling class to fmod
#14
Posted 06 April 2007 - 04:16 AM
if (!fp)
MessageBox(NULL, "Error loading sound!", "Error", MB_OK);
else
fclose(fp);"
REMOVE THIS, FIRST LOAD THE WAV, THEN USE FOPEN ....
#15
Posted 06 April 2007 - 06:10 AM
#16
Posted 08 April 2007 - 03:19 AM
-.-''
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











