Sign in to follow this  
jake_Ghost

openAL problem

Recommended Posts

i just started using openAL yesterday. I've made a dll for it because i am using vb for this part of my game. I can play the sounds, and i no there is a limit on them. But i have loaded all the sounds at the beginning of my game which does not work. Is there a way to get around that because i have 400+ sounds and i need a non-laggy way to load and play them. any help would be great thx jake

Share this post


Link to post
Share on other sites
What goes wrong when you load all 400+ sounds at the beginning? I would have thought that, as long as you weren't trying to play very many at the same time, that would be a reasonable way to do it.

I must admit I'm curious how you've got so many sound effects though. If they're for every possible scenario in the game, perhaps you could divide them up a bit, say by level, so that you don't have to load so many at once?

Share this post


Link to post
Share on other sites
There is only a memory imposed limit on the number of buffers you can create. There is a (relatively low, between 32-128 depending on platform) implementation defined limit on the number of sources you can create. You do not need a unique source for each buffer, they should be shared as needed.

Share this post


Link to post
Share on other sites
Quote:
Original post by jake_Ghost
i just started using openAL yesterday. I've made a dll for it because i am using vb for this part of my game. I can play the sounds, and i no there is a limit on them. But i have loaded all the sounds at the beginning of my game which does not work. Is there a way to get around that because i have 400+ sounds and i need a non-laggy way to load and play them.

any help would be great thx
jake


you should have a look at Creative labs OpenAL SDK it comes with a OpenAL32.dll and redistribution files for commercial or private use for free. heres the link:

OpenAL SDK for Windows

I have not used OpenAL yet but plan on using it. After you load the files into a buffer you should make sure you free the .wav files from memory, this could be the problem you are having.

Also 400+ sound excessively high for a any level of a game, you should rethink using a brute force approach to loading the sound files. If you have twenty levels in your game you would not load up all your 3D geometry for all the levels at once, you would only load what is necessary for the current level. Same goes for sounds.

Share this post


Link to post
Share on other sites
ok ill try that shared buffer thing. see if it works. and for all those sounds, ther really isnt 400 different sounds there is mostly gun sounds, music, and multiples of footsteps and bullet richocettes (cant spell it), ect.

Share this post


Link to post
Share on other sites
i also forgot to tell u guys that my single player part of my game is all one level. Also most of the sounds are used very often. Here is my code

//Sound.cpp : Defines the entry point for the DLL application.//

#include "stdafx.h"
#include <al.h>
#include "alc.h"
#include <alut.h>

char* alBuffer; //data for the buffer
ALenum alFormatBuffer; //for the buffer format
ALsizei alFreqBuffer; //for the frequency of the buffer
long alBufferLen; //the bit depth
ALboolean alLoop; //looped
unsigned int alSource; //buffer source
unsigned int alSampleSet;

ALCcontext *Context;
ALCdevice *Device;


BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}

bool _stdcall InitSound()
{

Device = alcOpenDevice((ALubyte*)"DirectSound3D");
if (Device == NULL)
{
return false;
}

//Create context(s)
Context=alcCreateContext(Device,NULL);

//Set active context
alcMakeContextCurrent(Context);

// Clear Error Code
alGetError();

return true;
}

unsigned int _stdcall LoadSound(char fileName[256],bool looping)
{
ALboolean loop;
loop = looping;

//load the wave file
alutLoadWAVFile(fileName,&alFormatBuffer, (void **) &alBuffer,(unsigned int *)&alBufferLen, &alFreqBuffer, &loop);

//create 1 source
alGenSources(1, &alSource);

//create 1 buffer
alGenBuffers(1, &alSampleSet);

//put the data into our sampleset buffer
alBufferData(alSampleSet, alFormatBuffer, alBuffer, alBufferLen, alFreqBuffer);

//assign the buffer to this source
alSourcei(alSource, AL_BUFFER, alSampleSet);

//release the data
alutUnloadWAV(alFormatBuffer, alBuffer, alBufferLen, alFreqBuffer);

return alSource;
}

unsigned int _stdcall Play3DSound(float xpositionSound, float ypositionSound, float zpositionSound, float xvelocitySound, float yvelocitySound, float zvelocitySound ,float fx, float fy, float fz, float ux, float uy, float uz, float x, float y, float z,bool LOOPS, unsigned int Source)
{
//load our sound
alSource = Source;

//set source position
alSource3f(alSource,AL_POSITION, xpositionSound, ypositionSound, zpositionSound);

//set source velocity
alSource3f(alSource,AL_VELOCITY, xvelocitySound, yvelocitySound, zvelocitySound);

//set current listener position
alListener3f(AL_POSITION, x, y, z);

//set the orientation using an array of floats
float vec[6];
vec[0] = fx;
vec[1] = fy;
vec[2] = fz;
vec[3] = ux;
vec[4] = uy;
vec[5] = uz;
alListenerfv(AL_ORIENTATION, vec);

if (LOOPS)
{
//tell the sound to loop continuously
alSourcei(alSource,AL_LOOPING,AL_TRUE);
}
else
{
//tell the sound to play once
alSourcei(alSource,false,AL_TRUE);
}

//play the sound
alSourcePlay(alSource);

return true;
}


bool _stdcall Stop3DSound(unsigned int Source)
{
alSource = Source;
alSourceStop(alSource);
if ((alGetError()) != AL_NO_ERROR)
{
return false;
}

return true;
}

bool _stdcall CleanUp(unsigned int Source, unsigned int Sample)
{
alSource = Source;
alSampleSet = Sample;

//delete our source
alDeleteSources(1,&alSource);

//delete our buffer
alDeleteBuffers(1,&alSampleSet);

//Get active context
Context=alcGetCurrentContext();

//Get device for active context
Device=alcGetContextsDevice(Context);

//Disable context
alcMakeContextCurrent(NULL);

//Release context(s)
alcDestroyContext(Context);

//Close device
alcCloseDevice(Device);

return true;
}

Share this post


Link to post
Share on other sites
im not going to look at that for the moment, put it in [_source_] [_/source_] (without the underscores) tags and i will, its easier on the eyes and it preserves whitespaces and does syntax highlighting. But i really find it hard to believe that you have 400 sounds that you absolutely need. . . and as someone else said, you only need to create a source when your actually going to play a sound, you could in theory re-use your sources too, so once you move away from one sound and towards another, yo ucould take taht source and use it for this new sound, but if you need mulpiple sounds playing at once you need multiple sources. simply create all your buffers, then as needed, create sources for each sound that will be playing, ie: a source for the waterfall, a source for the footsteps and a source for the gunfire

hope that helps
-Dan

Share this post


Link to post
Share on other sites
sry bout not writin using the source thing. Just signed on and ive never used it b4

//Sound.cpp : Defines the entry point for the DLL application.//

#include "stdafx.h"
#include <al.h>
#include "alc.h"
#include <alut.h>

char* alBuffer; //data for the buffer
ALenum alFormatBuffer; //for the buffer format
ALsizei alFreqBuffer; //for the frequency of the buffer
long alBufferLen; //the bit depth
ALboolean alLoop; //looped
unsigned int alSource; //buffer source
unsigned int alSampleSet;

ALCcontext *Context;
ALCdevice *Device;


BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}

bool _stdcall InitSound()
{

Device = alcOpenDevice((ALubyte*)"DirectSound3D");
if (Device == NULL)
{
return false;
}

//Create context(s)
Context=alcCreateContext(Device,NULL);

//Set active context
alcMakeContextCurrent(Context);

// Clear Error Code
alGetError();

return true;
}

unsigned int _stdcall LoadSound(char fileName[256],bool looping)
{
ALboolean loop;
loop = looping;

//load the wave file
alutLoadWAVFile(fileName,&alFormatBuffer, (void **) &alBuffer,(unsigned int *)&alBufferLen, &alFreqBuffer, &loop);

//create 1 source
alGenSources(1, &alSource);

//create 1 buffer
alGenBuffers(1, &alSampleSet);

//put the data into our sampleset buffer
alBufferData(alSampleSet, alFormatBuffer, alBuffer, alBufferLen, alFreqBuffer);

//assign the buffer to this source
alSourcei(alSource, AL_BUFFER, alSampleSet);

//release the data
alutUnloadWAV(alFormatBuffer, alBuffer, alBufferLen, alFreqBuffer);

return alSource;
}

unsigned int _stdcall Play3DSound(float xpositionSound, float ypositionSound, float zpositionSound, float xvelocitySound, float yvelocitySound, float zvelocitySound ,float fx, float fy, float fz, float ux, float uy, float uz, float x, float y, float z,bool LOOPS, unsigned int Source)
{
//load our sound
alSource = Source;

//set source position
alSource3f(alSource,AL_POSITION, xpositionSound, ypositionSound, zpositionSound);

//set source velocity
alSource3f(alSource,AL_VELOCITY, xvelocitySound, yvelocitySound, zvelocitySound);

//set current listener position
alListener3f(AL_POSITION, x, y, z);

//set the orientation using an array of floats
float vec[6];
vec[0] = fx;
vec[1] = fy;
vec[2] = fz;
vec[3] = ux;
vec[4] = uy;
vec[5] = uz;
alListenerfv(AL_ORIENTATION, vec);

if (LOOPS)
{
//tell the sound to loop continuously
alSourcei(alSource,AL_LOOPING,AL_TRUE);
}
else
{
//tell the sound to play once
alSourcei(alSource,false,AL_TRUE);
}

//play the sound
alSourcePlay(alSource);

return true;
}


bool _stdcall Stop3DSound(unsigned int Source)
{
alSource = Source;
alSourceStop(alSource);
if ((alGetError()) != AL_NO_ERROR)
{
return false;
}

return true;
}

bool _stdcall CleanUp(unsigned int Source, unsigned int Sample)
{
alSource = Source;
alSampleSet = Sample;

//delete our source
alDeleteSources(1,&alSource);

//delete our buffer
alDeleteBuffers(1,&alSampleSet);

//Get active context
Context=alcGetCurrentContext();

//Get device for active context
Device=alcGetContextsDevice(Context);

//Disable context
alcMakeContextCurrent(NULL);

//Release context(s)
alcDestroyContext(Context);

//Close device
alcCloseDevice(Device);

return true;
}

Share this post


Link to post
Share on other sites
This is just a guess sorry im STILL not gonna look at the code though (i have about 10 pages of notes to write for tommorow :-P shoudlnt even be doing this) but is it possible your not passing the right value for the source when you stop it? also, copying the source ID into the alsource variable is kinda redundant

hope that helps
-Dan

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