Archived

This topic is now archived and is closed to further replies.

Nameless

Tutorials + OpenAL

Recommended Posts

I''ve been experimenting with OpenAL and I''ve got it working fine under glut. When I try to import the same code into Nehe''s tutorial (the one with the 3d world) things don''t work so fine anymore. Here''s some code from an example program I found: int main(int argc, char** argv) { glutInit ( &argc, argv ); glutInitDisplayMode ( GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH ); glutInitWindowSize ( window_Width, window_Height ); glutCreateWindow ( argv[0] ); glutDisplayFunc ( display ); glutIdleFunc ( display ); glutReshapeFunc ( reshape ); glutKeyboardFunc ( keyboard ); glutSpecialFunc ( specialkeyboard ); init_OpenIL ( ); alphabet_image = ilutOglLoadImage( "alphabet.bmp" ); init_openGL(); alutInit ( &argc,argv ); init_openAL(); glutMainLoop(); return 0; } However, Nehe''s tutorials dont'' have a main() -- and thus no &argc, argv. My question is how could I get this sample of code working in a tutorial (and also, what exactly are argc, and argv?) Secondly, the sample application plays wav files. Is there any way to play an .mp3 with OpenAL? I''d really much rather play a 2Mb MP3 than a 50Mb WAV. Thanks in Advance!!

Share this post


Link to post
Share on other sites
The parameter argc is the number of items that are in argv, argv is is set of strings specifying the parameters that were passed to the program. You don''t have to use alutInit with OpenAL though. Look at the code (I assume you downloaded OpenAL''s code, if not, do so) behind alutInit, and just do what it does with the argc/argv part. Here''s what my engine does to initialize OpenAL:
  
riFunction riBool ri_intern_InitOpenAL(riVoid) {
#ifndef RI_OPENAL_DEVICE
#error An OpenAL device must be specified.
#else
ri_intern_Audio.Device = alcOpenDevice( (riByte *) RI_OPENAL_DEVICE );
ri_intern_Audio.Context = alcCreateContext(ri_intern_Audio.Device,NULL);
alcMakeContextCurrent(ri_intern_Audio.Context);
alGetError();

ri_intern_Audio.ListPos = riTriplet <riFloat> (0.0f, 0.0f, 0.0f);
ri_intern_Audio.ListVel = riTriplet <riFloat> (0.0f, 0.0f, 0.0f);
ri_intern_Audio.ListOrigin[0] = ri_intern_Audio.ListOrigin[1] = ri_intern_Audio.ListOrigin[3] = ri_intern_Audio.ListOrigin[5] = 0.0f;
ri_intern_Audio.ListOrigin[2] = -1.0f;
ri_intern_Audio.ListOrigin[4] = 1.0f;

{
riFloat ListPos[3];
ri_intern_Audio.ListPos.GetArray(ListPos);

alListenerfv(AL_POSITION,ListPos);
if(alGetError() != AL_NO_ERROR) return RI_FALSE;
}

{
riFloat ListVel[3];
ri_intern_Audio.ListVel.GetArray(ListVel);

alListenerfv(AL_VELOCITY,ListVel);
if(alGetError() != AL_NO_ERROR) return RI_FALSE;
}

alListenerfv(AL_ORIENTATION,ri_intern_Audio.ListOrigin);
if(alGetError() != AL_NO_ERROR) return RI_FALSE;

return RI_TRUE;
#endif
}

Just alter that to your own needs.

Resist Windows XP''s Invasive Production Activation Technology!
http://druidgames.cjb.net/ (If my website isn''t down, it''s a miracle!)

Share this post


Link to post
Share on other sites
Ok Thanks! I''ll look into it!

More importantly -- what about the MP3 playback? If there''s no easy way to do it in OpenAL can anybody point me to a good DirectSound tutorial on it?

Share this post


Link to post
Share on other sites
This is probably the wrong place to post a question, but since both of you are running OpenAl, I thought I''ll give it a try.

Do you know where I can find an OpenAL tutorial that works for
win98?

Ive tried to download the ones from the OpenAL homepage, but I
can''t get them to run....

/Very thankful for any help,..

Share this post


Link to post
Share on other sites
Thank you for the link!!

Hope It works now, this ain''t the first OpenAL demo/lib that
I''m downloading ... would really like to code for it

Read somewhere that you are writing an engine for
OpenGL/OpenAL - Opensource rocks!!
I haven''t written any sound code at all for my engine,
since I was trying to get OpenAL going..

BTW. Do you know the name of the company who made a prototype
of a hardware-accelerated-(real)3D soundcard, for OpenAL..

Anyways Big Thanks to NULL AND VOID

Share this post


Link to post
Share on other sites
I haven''t seen anything about that, but if it''s anyone, it''s probably Creative that''s trying to make one. OpenAL gets accelerated in Windows anyway, since it just uses DirectSound. I still haven''t even got OpenGL acceleration working under Linux, so I haven''t had to worry about anything non-windows yet .

Resist Windows XP''s Invasive Production Activation Technology!
http://druidgames.cjb.net/ (If my website isn''t down, it''s a miracle!)

Share this post


Link to post
Share on other sites