PDA

View Full Version : Bachgroun sound



glcrazy
12-18-2003, 11:06 AM
Hi

I add a bachgroun sound to my game to work since the player use the game ..

So I use OPENAL to do that but what I notice that the sound musn't be in a loop orelse it will repeat itself even the sound not yet finished .. and the result is noise instead of music http://www.opengl.org/discussion_boards/ubb/frown.gif ..

Here the code I used in my main routine:

alutInit(NULL, 0); alGetError ();
if(alGetError() != AL_NO_ERROR) return ;
alGenBuffers(1, &SoundBuffer);
if(alGetError() != AL_NO_ERROR) return ;
alutLoadWAVFile("MONO.wav", &formats, &datas, &sizes, &frequencys, &loops);

alBufferData(SoundBuffer, formats, datas, sizes, frequencys);

alutUnloadWAV(formats, datas, sizes, frequencys);
alGenSources(1, &Source); if(alGetError() != AL_NO_ERROR) return;
alSourcei(Source, AL_BUFFER, SoundBuffer);
alSourcef(Source, AL_PITCH, 1.0);
alSourcef(Source, AL_GAIN, 1.0);
alSourcefv(Source, AL_POSITION, SourcePosition);
alSourcefv(Source, AL_VELOCITY, SourceVelocity);

alSourcei(Source, AL_LOOPING, loops);
if(alGetError() != AL_NO_ERROR) return ;
alListenerfv(AL_POSITION, ListenerPosition);
alListenerfv(AL_VELOCITY, ListenerVelocity);
alListenerfv(AL_ORIENTATION, ListenerOrientation);
if(alGetError() != AL_NO_ERROR) return ; // Error checking...
.
.
.
.

and in my dispkay routine I put the following which I think make the mistake ..

alSourcePlay(Source);

But where else I can put that function to play the sound .. ?

Thanks in advance for any help ..

12-18-2003, 11:07 AM
Why don't you ask this in the OpenAL forum?

12-18-2003, 01:05 PM
As you may have guessed, you only need to call the sound once, and not at every frame.

Start all background sounds once at initialisation, on the first frame. Check and set a boolean if you want to keep the call in the display callback.

(I did not see any OpenAL forum ??)

12-18-2003, 03:14 PM
Originally posted by zbuffer_:
(I did not see any OpenAL forum ??)

And thats makes the OpenGL forum the right place to ask sound related problems?

nexusone
12-18-2003, 04:41 PM
You should not call the sound every time display is called.


Remember to use states.

When one ball ball hits another call the sound.

if (ball_1 == ball2) Hit = 1;

if ( Hit )
{
playsound(); Sound should play some duration and stop on it own.
Hit = 0; We reset Hit so it is not called next pass.
}

glcrazy
12-19-2003, 06:55 AM
Hi..

Qwerty77 .. I don't know if there is an openal forum but I think that the skills of that fourm's members is enough to answer me simple questions .. http://www.opengl.org/discussion_boards/ubb/smile.gif.. Thanks for your advice.

glcrazy
12-19-2003, 06:57 AM
Hi zbuffer ..

I discovered that there is a facility in openal that tell the sound to loop continuosly .

that is :
alSourcei(Source, AL_LOOPING, loops);
instead of loops pu AL_TRUE .. so the sound will loop as the game there .. you don't have to put in display routine .. all must be in the main routine http://www.opengl.org/discussion_boards/ubb/smile.gif.. thanks

glcrazy
12-19-2003, 06:59 AM
Originally posted by wbuffer_:
And thats makes the OpenGL forum the right place to ask sound related problems?



So .. I'm in the right place .. am I .. ? http://www.opengl.org/discussion_boards/ubb/smile.gif

glcrazy
12-19-2003, 07:02 AM
Originally posted by nexusone:
You should not call the sound every time display is called.


Remember to use states.

When one ball ball hits another call the sound.

if (ball_1 == ball2) Hit = 1;

if ( Hit )
{
playsound(); Sound should play some duration and stop on it own.
Hit = 0; We reset Hit so it is not called next pass.
}



Hi nexusone ..

Thank you for youe valuable advice .. Yeah 'I use playsound in the condition of bouncing .. I'm trying now as you said to me to put states for the events of the game so I can initliaze the variables whenever it need ..

Thanks a gain http://www.opengl.org/discussion_boards/ubb/smile.gif

dorbie
12-19-2003, 07:20 AM
This is OT for OpenGL. I was gonna let it go without mentioning it, but since you've bumped the thread 4 times, please let the thread go. You got an answer, but you should look elsewhere online for audio dev questions, perhaps ask in the openML forum here:
http://www.khronos.org/openml/index.html

or more generic audio questions here:
http://www.gamedev.net/community/forums/

In reference to another thread there is a math and algos forum that can handle questions not directly related to rendering.

nexusone
12-19-2003, 07:36 AM
I don't think you guy's should be so hard on him, this is a BEGINNERS forum.

I think that you would find a mixed bag of diffrent questions in this forum.

Math and audio also is part of openGL coding and I think basic questions of a beginner, who maybe also new to use of forums and other web stuff could be lump into a general beginner openGL questions.



Originally posted by dorbie:
This is OT for OpenGL. I was gonna let it go without mentioning it, but since you've bumped the thread 4 times, please let the thread go. You got an answer, but you should look elsewhere online for audio dev questions, perhaps ask in the openML forum here:
http://www.khronos.org/openml/index.html

or more generic audio questions here:
http://www.gamedev.net/community/forums/

In reference to another thread there is a math and algos forum that can handle questions not directly related to rendering.



[This message has been edited by nexusone (edited 12-19-2003).]

dorbie
12-19-2003, 07:44 AM
I'm not being hard on anyone, this is an OpenGL forum, and this is just off topic. Plain and simple. There's nothing to debate here.

glcrazy
12-19-2003, 12:02 PM
Ok dorbie ..

Since you're a moderator here you can delete this topic as easy and simple as that !!

dorbie
12-19-2003, 12:33 PM
I can but it seems excessive for a simple OT thread that garnered a useful answer, maybe I will if it keeps getting bumped. I cannot close threads, which would have been my preference in this case. All I'm saying is NEXT time think about the forum context, that's reasonable. Problem is warning about this being OT causes as much noise as the problem when we start chit chatting about it. It's part of my task to warn about OT posts so that done, let's move on.

Die thread die!... err.. sleep thread sleep.


[This message has been edited by dorbie (edited 12-19-2003).]