Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


OpenAL Sound Error C++


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 ProvenDantheman   Members   -  Reputation: 111

Like
0Likes
Like

Posted 27 January 2012 - 08:33 AM

I've been working on a game in C++. I use OpenAL for my sound library. I've been having some issues with sound playback. For some reason, my sounds will either play normally, play halfway, or stop playing all together. I would like some help with this issue. So I'm posting my code below.

//Operations to Play Sources
ALuint buffers[20];
ALuint sources[20];
int SRC_VAL = 0;
float LISTNER_X = 0;
float LISTNER_Y = 0;

void InitSources(){
alGenSources(20,sources);
}
void PlaySource(int buf,bool ambient = true,float x = 0, float y = 0, float refdist = 1.0, float maxdist = 20){
float dist = sqrt((LISTNER_X-x)*(LISTNER_X-x) + (LISTNER_Y-y)*(LISTNER_Y-y));
if(dist <= maxdist || ambient){
  alSourcei(sources[SRC_VAL], AL_SOURCE_RELATIVE, AL_FALSE);
  alSourcei(sources[SRC_VAL], AL_BUFFER, buffers[buf]);
  alSource3f(sources[SRC_VAL],AL_POSITION, x,y,0);
  alSourcei(sources[SRC_VAL], AL_REFERENCE_DISTANCE, refdist);
  alSourcei(sources[SRC_VAL], AL_MAX_DISTANCE, maxdist);
  if(ambient){
   alSourcei(sources[SRC_VAL], AL_SOURCE_RELATIVE, AL_TRUE);
   alSource3f(sources[SRC_VAL], AL_POSITION, 0.0f, 0.0f, 0.0f);
  }
  alSourcePlay(sources[SRC_VAL]);
  SRC_VAL++;
  if(SRC_VAL >= 20){
   SRC_VAL = 0;
  }
}
}

//this is inside main for initialization and buffer loading
int main(){
//code
alutInit(0, NULL);
alGetError();
alGenBuffers(20,buffers);
InitSources();
// load sounds
buffers[0] = alutCreateBufferFromFile("SFX/walk.wav");
buffers[1] = alutCreateBufferFromFile("SFX/jump.wav");
buffers[2] = alutCreateBufferFromFile("SFX/pain.wav");
buffers[3] = alutCreateBufferFromFile("SFX/break.wav");
buffers[4] = alutCreateBufferFromFile("SFX/pain.wav");
buffers[5] = alutCreateBufferFromFile("SFX/collect.wav");
buffers[6] = alutCreateBufferFromFile("SFX/zombie.wav");
buffers[7] = alutCreateBufferFromFile("SFX/splash.wav");
buffers[8] = alutCreateBufferFromFile("SFX/fall.wav");
// code
}

To play a sound I just call the function PlaySource

Sponsor:

#2 ProvenDantheman   Members   -  Reputation: 111

Like
0Likes
Like

Posted 27 January 2012 - 12:58 PM

So many people have read this topic, yet there's still no answer to my problem :/ I really would appreciate any help.

#3 inprazia   Members   -  Reputation: 107

Like
0Likes
Like

Posted 13 April 2012 - 10:37 AM

I'm not using the ALUT lib, just basic OpenAL. Didn't have any problems. Just follow the samples included in the OpenAL SDK.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS