Joseph Duchesne
2004.07.30, 02:04 PM
Does anyone know of any good openAL tutorials or examples of using openAL in XCode? I am using C.
skyhawk
2004.07.30, 02:48 PM
I'll send you the official OpenAL manual when I get home tonight. it documents every function...
but... with openal, it is really better to have a CLASS to abstract all the sounds away from your game so you just say soundmanager->playsound(x,y,xvel,yvel,sound_id,NO_LOOP); and not have to worry in the rest of your game how sound happens.
also, very basic openal tutorials can be found searching gamedev.net
Joseph Duchesne
2004.07.30, 02:51 PM
Thanks for the tips, I'm trying to write a few basic openAL finctions like the one you suggested right now. Can openAL run in a console window?
AnotherJake
2004.07.30, 11:43 PM
"Can openAL run in a console window?"
Yes.
I listed this stuff in another thread but here it is again.
Here's an OS X tutorial:
http://www.edenwaith.com/products/pige/tutorials/openal.php
You'll most likely need to fiddle with it to get it to load the sound file properly, but even without running it you should be able to see what's going on. OpenAL is just a very simple state machine API with no frills.
To package the OpenAL lib with your application instead of making the user install it:
http://cocoadevcentral.com/articles/000042.php
Don't forget the main OpenAL sites:
http://www.openal.org/
http://developer.creative.com/landing.asp?cat=1&sbcat=31&top=38
Skyhawk is totally right about the abstraction. Start thinking about easier ways to set up sounds in OpenAL as soon as you get the main concepts down. There's really not much to it and the whole library can be mastered within days if not hours, so don't get frustrated if it doesn't click right away.
Here are some simple ideas from my own code on how to abstract it in straight C. I didn't include LoadSound since that's written in Cocoa. Call InitSounds() first, and then SpawnAThingy() is what would get called from the game code. You can put the listener with your init code or your camera.
#import <OpenAl/alut.h>
enum
{
kBoom = 0,
kPop,
kBang,
kNumSounds
};
static ALuint buffer[kNumSounds];
//---------------------------------------------------------------------------
void InitSounds( void )
{
alGetError();
alGenBuffers( kNumSounds, buffer );
if( alGetError() != AL_NO_ERROR )
FatalError( "InitSounds: alGenBuffers failed." );
LoadSound( "PopSound.wav", buffer[kPop] );
LoadSound( "MyBangSound.wav", buffer[kBang] );
LoadSound( "SomeOtherSound.wav", buffer[kBoom] );
}
//---------------------------------------------------------------------------
void SpawnAThingy( void )
{
ALuint soundSource;
float thingyPosX, thingyPosY;
// spawn the "thingy" for your game here
// ...
// make believe a 2D position for thingy
thingyPosX = 0.2f;
thingyPosY = 0.6f;
// make a new source that plays "PopSound.wav"
MakeNewSource( &soundSource, buffer[kPop] );
// - if you don't want the default "looping, false" in MakeNewSource, override
// it here like this
// - do the same thing for other attributes
alSourcei( soundSource, AL_LOOPING, AL_TRUE );
PlaySound( soundSource, thingyPosX, thingyPosY, 0.0f );
}
//---------------------------------------------------------------------------
void PlaySound( ALuint source, float x, float y, float z )
{
ALfloat soundPos[3];
soundPos[0] = x;
soundPos[1] = y;
soundPos[2] = z;
alSourcefv( source, AL_POSITION, soundPos );
alSourcePlay( source );
// could add the sound to a linked list here to automatically handle
// deleting of sounds after completion and pausing
}
//---------------------------------------------------------------------------
void MakeNewSource( ALuint *source, ALuint inBuffer )
{
ALfloat soundPos[] = { 0.5f, 0.5f, 0.0f };
ALfloat soundVel[] = { 0.0f, 0.0f, 0.0f };
alGetError();
alGenSources( 1, source );
if( alGetError() != AL_NO_ERROR )
FatalError( "OpenAL was unable to create a new sound source." );
alSourcef ( *source, AL_PITCH, 1.0f );
alSourcef ( *source, AL_GAIN, 1.0f );
alSourcefv( *source, AL_POSITION, soundPos );
alSourcefv( *source, AL_VELOCITY, soundVel );
alSourcei ( *source, AL_BUFFER, inBuffer );
alSourcei ( *source, AL_LOOPING, AL_FALSE );
}
vBulletin® v3.8.4, Copyright ©2000-2010, Jelsoft Enterprises Ltd.