Sign in to follow this  
Damocles

OpenAL - there are no sounds to hear

Recommended Posts

Hear that? Hear what? Precisely. And you know why you can't hear anything? No. Because there are no sounds to hear. (cookie for the reference) and now my problem - I decided to start learning openAL - seems like a good, robust system and it's free (always nice). So I'm following a tutorial, I have my code, it compiles fine and seems like it should work, but when I run it, there is no sound at all. It should be playing a looping wav file, but it isn't. The code:
    alutInit(NULL, NULL);
    alGetError();

    // set listener location/values
    alListenerfv(AL_POSITION,    ListenerPos);
    alListenerfv(AL_VELOCITY,    ListenerVel);
    alListenerfv(AL_ORIENTATION, ListenerOri);

    ALenum format;
    ALsizei size;
    ALvoid* data;
    ALsizei freq;
    ALboolean loop;
    ALuint Buffer;
    ALuint Source;


    // Load wav data into a buffer.
    alGenBuffers(1, &Buffer);
    if (alGetError() != AL_NO_ERROR)
        return false;

    alutLoadWAVFile(file, &format, &data, &size, &freq, &loop);
    alBufferData(Buffer, format, data, size, freq);
    alutUnloadWAV(format, data, size, freq);

    if (alGetError() != AL_NO_ERROR)
        return false;

    // Bind buffer with a source.
    alGenSources(1, &Source);

    if (alGetError() != AL_NO_ERROR)
        return 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,  TRUE    );

    alSourcePlay(Source);


I've stripped out all the error checking I had in place to make it readable. I have it so after EVERY OpenAL function call, I do an error check, and every single function is coming back saying no error. The sample being loaded has been converted to a simple 22KHz mono wav file - I'm pretty sure OpenAL supports that. There should be sound. There is no sound. There are no errors or warnings or any other indication something is wrong. I have the 1.1 SDK installed, the DLLs are in the right place (and it would throw up some juicy erros if they weren't). I'm at a complete loss here. I can only assume I'm doing something really stupid and obvious to everyone but me. Lil' help?

Share this post


Link to post
Share on other sites
Red Dwarf.

As for the error, in the past I have had issues when introducting OpenAL code that if you don't clean up upon exit properly, the AL system can be left in an unusable state (therefore not acting as it should). This means the next time you run the app it won't produce any sound. So my question is are you releasing all your resources properly on exit?

Share this post


Link to post
Share on other sites
Hi,

Try other data files yet?

I know this code works:
http://www.devmaster.net/articles/openal-tutorials/lesson1.php

I just found some random wave file on my drive and it worked. I looked over your code and couldn't find anything obvious standing out but I just woke up so I could have likely missed a lot :) Then again you said you were checking each function.

Anyways I'd recommend using the above code to test your setup, if it works then you know it's something in your code and you can compare the two together maybe to find your issue (wow I still use issue, 1.5 years after leaving HP tech support...).

Mike

Share this post


Link to post
Share on other sites
What are you setting the listener and source positions to? Are they resonably similar (why not make them identical to test)?

Edit: I dunno why it posted twice.

[Edited by - BradDaBug on November 11, 2005 1:33:12 PM]

Share this post


Link to post
Share on other sites
Quote:
As for the error, in the past I have had issues when introducting OpenAL code that if you don't clean up upon exit properly, the AL system can be left in an unusable state (therefore not acting as it should). This means the next time you run the app it won't produce any sound. So my question is are you releasing all your resources properly on exit?


I thought the same thing and tried restarting my machine before running the code, and still nothing. As far as I know I'm cleaning up properly (delete the source, delete the buffer, call alutExit)

Quote:

Try other data files yet?

I know this code works:
http://www.devmaster.net/articles/openal-tutorials/lesson1.php


Tried several data files, all mono wavs of varying formats. None work. And that's the exact tutorial I'm following. My code is virtually a copy/paste of that tutorial.

Quote:
What are you setting the listener and source positions to? Are they resonably similar (why not make them identical to test)?


Both are set to 0,0,0.

What I'd like to know is: when did programming stop being simple? I remember when you could simply write the functions you were told to write, and they would just work.

And I'd also quite like to know why this code doesn't work :)

Share this post


Link to post
Share on other sites
I have the same problem. I just got the newest OpenAL off of www.openal.org and creative's website. I've already tried it on 3 computers, all running Windows XP, and still nothing. I am using Visual C++ .NET 2005 (the free version). I tried compiling the OpenAL demo that comes with the SDK, and it compiled fine, but crashes when run. I've tried using alutInit and initializing myself, no effect.

I've tried many different versions of the OpenAL dll, .lib, etc... Still no effect accept crashes. I have to get the problem resolved soon, and google doesn't have anything about it (except a few unresolved threads similar to this one).

I would appriciate it if someone here that has OpenAL working would post the OpenAL32.dll, ALut.lib, OpenAL32.lib, wrap_oal.dll (what does this dll do?), and the headers you have.

Edit: By the way, this is a port of my project to Windows from Unix. I had it working in Windows, went to Linux and worked on it for a while (didn't change any of the sound code), and then came back to Windows, now it wont work. The only thing I can guess is that it is VC++, which I wasn't using in Windows before.

Share this post


Link to post
Share on other sites
alutInit doesn't work for me. I had to manuelly create a context, then it worked fine. I think that is the way it does it in the devmaster tutorials. In linux however, if I create a context manuelly it won't work, I need to use alutInit. Very odd glitch.

Share this post


Link to post
Share on other sites
OpenAL works fine for me in Linux. Here's my initialization code, if it helps:
m_device = alcOpenDevice(NULL);

if (!m_device)
{
WRITE_ERROR("Unable to open OpenAL device!");
return -1;
}

m_context = alcCreateContext(m_device, NULL);

if (!m_context)
{
WRITE_ERROR("Unable to create OpenAL context!");
alcCloseDevice(m_device);
return -1;
}

alcMakeContextCurrent(m_context);

if (alcGetError(m_device) != ALC_NO_ERROR)
logger.WriteWarning("OMG!");

logger.WriteLine("OpenAL successfully initialized");

Share this post


Link to post
Share on other sites
Quote:
Original post by Richy2k
alutInit doesn't work for me. I had to manuelly create a context, then it worked fine. I think that is the way it does it in the devmaster tutorials. In linux however, if I create a context manuelly it won't work, I need to use alutInit. Very odd glitch.


That is exactly the problem I had under windows. I just did the context myself and it worked fine. I don't use any linux so I can't vouch for that one though.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this