Sign in to follow this  

Vague OpenAL Troubles

This topic is 4226 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Sometime in the last week I thought it would be neat to add sound to my game framework. I decided to use OpenAL because I am already using OpenGL, meaning more portability, and I wanted to learn how to do some audio coding myself without a library doing everything for me. Finding useful resources was a little difficult but I think I have a general idea of how things should work now, except that they don't work. I am using the devpak for OpenAL in Dev-C++ with an updated libALut.a (because it was giving an irritating but toothless warning) on Windows XP home. There are no errors or angry-looking message boxes popping up when I run my app, but there's no sound played either. If I posted the actual code it would be spread out around five or six files so I'll just post the relevant AL code executed:
#include <al/alut.h>
#include <iostream>
using std::cerr;

// INITIALIZATION BLOCK
// use ALUT to initialize - no cmdline arguments so (0, 0).  Is this ok?
alutInit(0, 0);

IdCounter = 0;

// make as many sources as possible
// (GDnetters - it's only making 1 source and that source isn't valid)
int sourceCount = 0;
unsigned int newSrc = 0;

alGenSources(1, &newSrc);
// alGetError() is equal to AL_NO_ERROR here
Sources.push_back(newSrc);
sourceCount++;

cerr << newSrc;

// this loop is never entered - I've added the source to the Sources vector anyway, in case AL is misreporting it or something,
// but I suspect this is the root of my problem.
while (alIsSource(newSrc) == AL_TRUE)
{
	alGenSources(1, &newSrc);
	sourceCount++;
}

// LOAD A SOUND
ALenum fileFormat;
ALsizei size, frequency;
ALboolean loops;
ALvoid* data;

// load info from file
alutLoadWAVFile(const_cast<char*>(fileName.c_str()), &fileFormat, &data, &size, &frequency, &loops);

uint bufferID;
alGenBuffers(1, &bufferID);
alBufferData(bufferID, fileFormat, data, size, frequency);

alutUnloadWAV(fileFormat, data, size, frequency);

// PLAY SOUND
// Again, alIsSource(Sources[0]) returns false.
// I left the position/velocity/orientation of the source and listener at default, which is 0 for most things.
alSourcei(Sources[0], AL_BUFFER, SoundDb[soundId].ID);
alSourcePlay(Sources[0]);

// what? no sound? HMM?


I hope I didn't screw up the inline-ifying of the code, but anyway that's the general idea. Is this the fault of ALUT, or something I'm doing wrong? I'm not even sure where to begin. Thanks.

Share this post


Link to post
Share on other sites
I tried using ALC rather than AlutInit(). Going by the DevMasters article it should be right, but my source is still being reported as not a source. Ideas?

Share this post


Link to post
Share on other sites
Try creating a new program that does have argc and argv and try putting it this code. This should be just about the simplest code possible for OpenAL. If you can get sound out of it then try to fiddle with it until its what you want.. if you can't get sound out of it I would guess OpenAL is at fault


ALuint PrimarySource;
alutInit (&argc, argv);

alGenSources(1, &PrimarySource);

alSourcei(PrimarySource,AL_BUFFER,alutCreateBufferHelloWorld());

alSourcei(PrimarySource,AL_LOOPING,1);
alSourcePlay(PrimarySource);

//add some way to pause the code here

alutExit ();

Share this post


Link to post
Share on other sites
Quote:
Original post by Yohumbus
Try creating a new program that does have argc and argv and try putting it this code. This should be just about the simplest code possible for OpenAL. If you can get sound out of it then try to fiddle with it until its what you want.. if you can't get sound out of it I would guess OpenAL is at fault


ALuint PrimarySource;
alutInit (&argc, argv);

alGenSources(1, &PrimarySource);

alSourcei(PrimarySource,AL_BUFFER,alutCreateBufferHelloWorld());

alSourcei(PrimarySource,AL_LOOPING,1);
alSourcePlay(PrimarySource);

//add some way to pause the code here

alutExit ();


Tried it; compiler says that alutCreateBufferHelloWorld() doesn't exist. This has happened before when I've tried to use test code, thinking it was just removed from ALUT. Maybe it's time I looked around to make sure the Devpak gave the most recent OpenAL DLLs?

Thanks for the suggestion by the way.

Share this post


Link to post
Share on other sites

This topic is 4226 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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