Jump to content


OpenAL: "No sound" problem


15 replies to this topic

#1 eldritch

    New Member

  • Members
  • Pip
  • 3 posts

Posted 06 May 2005 - 01:56 PM

Hello there, new here :)

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 eldritch

    New Member

  • Members
  • Pip
  • 3 posts

Posted 06 May 2005 - 05:44 PM

I'll post the parts of the code where I have put the OpenAL stuff, though it is pretty intact from the tutorial, and I have compared the code a million times (and it does not really lie there since the very same file works perfectly with the original project file (.DSW/.DSP).

// 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 eldritch

    New Member

  • Members
  • Pip
  • 3 posts

Posted 07 May 2005 - 09:40 AM

Okey.. I managed to find out what was causing these anomalies.

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 DragonCode

    New Member

  • Members
  • Pip
  • 3 posts

Posted 28 October 2005 - 12:50 PM

Hey Eldritch, I am experiencing the same problem. I have gone over my code many times and it looks right. I am using the most recent SDK from the Creative web sight.

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 rdillon

    New Member

  • Members
  • Pip
  • 2 posts

Posted 26 November 2005 - 04:20 AM

I think your code'd work fine in OpenAL1.0 but now you are using the new release 1.1, right?
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 SpreeTree

    Valued Member

  • Members
  • PipPipPip
  • 265 posts

Posted 26 November 2005 - 11:32 AM

rdillon said:

we'd also note that the alutLoadWavfile function is now deprecated (but still works fine in current version).

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 rdillon

    New Member

  • Members
  • Pip
  • 2 posts

Posted 27 November 2005 - 05:19 AM

Hello,
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 SpreeTree

    Valued Member

  • Members
  • PipPipPip
  • 265 posts

Posted 27 November 2005 - 11:54 AM

As I said, I do not use alut, so I am not an authority here. But as I said, AlutLoadWavFile has been moved to the alut library, and whilst it looks like ti has been 'officially' depreciated, is still available.

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 Citizen Erased

    New Member

  • Members
  • Pip
  • 1 posts

Posted 25 January 2006 - 01:36 AM

I'm having the same 1.1 SDK problem. I'm pretty new to programming in general and completly new to OpenAL. Copy pasting rdillions code doesn't seem to solve the problem (although I'm probably doing something wrong), could someone quickly explain how to get the code in the first OpenAL tutorial on this site to work with the 1.1 release? Thanks.

#10 wazoo

    New Member

  • Members
  • PipPip
  • 27 posts

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 Zeussy

    New Member

  • Members
  • Pip
  • 3 posts

Posted 20 February 2006 - 04:16 AM

i cant get OpenAL to play a sound on my creative card.

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 Reedbeta

    DevMaster Staff

  • Administrators
  • 4974 posts
  • LocationBellevue, WA

Posted 20 February 2006 - 05:19 AM

Zeussy, have you tried making sure the volume is turned up? (I don't just mean the volume in your speakers, but the OpenAL volume control. You never know, it might default to zero or something dumb like that.)
reedbeta.com - developer blog, OpenGL demos, and other projects

#13 Zeussy

    New Member

  • Members
  • Pip
  • 3 posts

Posted 20 February 2006 - 10:36 AM

thanks Reedbeta, listener gain was set to 1, upped it to like 1000.f as well as the 1000 gain on the source, makes it audible.

was almost going to convert my sound handling class to fmod

#14 L1zb3th

    New Member

  • Members
  • PipPip
  • 10 posts

Posted 06 April 2007 - 04:16 AM

"FILE *fp = fopen("wavdata/phaser.wav", "r");
if (!fp)
MessageBox(NULL, "Error loading sound!", "Error", MB_OK);
else
fclose(fp);"

REMOVE THIS, FIRST LOAD THE WAV, THEN USE FOPEN ....

#15 Reedbeta

    DevMaster Staff

  • Administrators
  • 4974 posts
  • LocationBellevue, WA

Posted 06 April 2007 - 06:10 AM

L1zb3th, that is just a check that the file exists before passing it to ALUT.
reedbeta.com - developer blog, OpenGL demos, and other projects

#16 L1zb3th

    New Member

  • Members
  • PipPip
  • 10 posts

Posted 08 April 2007 - 03:19 AM

ahh , i didnt read well xDDDDDDDD
-.-''





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users