Advertisement

openAL problem

Started by December 05, 2004 01:56 PM
9 comments, last by Ademan555 20 years, 1 month ago
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
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?
Advertisement
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.
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.

-------------Become part of developing the specifications of a new language. Visit CodeBASIC.org
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.
o and yes i am i freein the files after i am done with them. Does ne one no how to load sounds into the same buffer?
Advertisement
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;
}
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
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."
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 bufferALenum alFormatBuffer; //for the buffer formatALsizei alFreqBuffer; //for the frequency of the bufferlong alBufferLen; //the bit depthALboolean alLoop; //loopedunsigned int alSource; //buffer sourceunsigned 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 contextalcMakeContextCurrent(Context);// Clear Error CodealGetError();return true;}unsigned int _stdcall LoadSound(char fileName[256],bool looping){ALboolean loop;loop = looping;//load the wave filealutLoadWAVFile(fileName,&alFormatBuffer, (void **) &alBuffer,(unsigned int *)&alBufferLen, &alFreqBuffer, &loop);//create 1 sourcealGenSources(1, &alSource);//create 1 bufferalGenBuffers(1, &alSampleSet);//put the data into our sampleset bufferalBufferData(alSampleSet, alFormatBuffer, alBuffer, alBufferLen, alFreqBuffer);//assign the buffer to this sourcealSourcei(alSource, AL_BUFFER, alSampleSet);//release the dataalutUnloadWAV(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 soundalSource = Source;//set source positionalSource3f(alSource,AL_POSITION, xpositionSound, ypositionSound, zpositionSound);//set source velocityalSource3f(alSource,AL_VELOCITY, xvelocitySound, yvelocitySound, zvelocitySound);//set current listener positionalListener3f(AL_POSITION, x, y, z);//set the orientation using an array of floatsfloat 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 continuouslyalSourcei(alSource,AL_LOOPING,AL_TRUE);}else{//tell the sound to play oncealSourcei(alSource,false,AL_TRUE); }//play the soundalSourcePlay(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 sourcealDeleteSources(1,&alSource);//delete our bufferalDeleteBuffers(1,&alSampleSet);//Get active contextContext=alcGetCurrentContext();//Get device for active contextDevice=alcGetContextsDevice(Context);//Disable contextalcMakeContextCurrent(NULL);//Release context(s)alcDestroyContext(Context);//Close devicealcCloseDevice(Device);return true;}
i have just found out that i have a problem with the stopping of the sound. It wont stop! ihave no clue y. Any suggestions?

This topic is closed to new replies.

Advertisement