# 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.

## 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++;
}

ALenum fileFormat;
ALsizei size, frequency;
ALboolean loops;
ALvoid* data;

alutLoadWAVFile(const_cast<char*>(fileName.c_str()), &fileFormat, &data, &size, &frequency, &loops);

uint bufferID;
alGenBuffers(1, &bufferID);
alBufferData(bufferID, 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 on other sites
If I remember right alutInit() is not longer used, check out the examples from DevMaster.Net.

I'm not sure if the first few lessons touch on this but the later ones sure do.

##### 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 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 on other sites
Quote:
 Original post by YohumbusTry 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 faultALuint 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 herealutExit ();

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 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.