Hi! I am pretty new to programming, and i am trying to make a simple sound class for my project using openAL. The problem is that i cant seem to get the sounds to play when i split the class =S
It is supposed to have more audio files, but i've shorted it down for more simplicity. Does anyone know what i am doing wrong?
thanks in advance =)
/////////////////////////// sound.h ///////////////////////////
#ifndef SOUND_H
#define SOUND_H
#include <iostream>
#include <al.h>
#include <alc.h>
#include <alut.h>
#define NUM_BUFFERS 1
#define NUM_SOURCES 1
#define game 0
class cSound
{
public:
cSound();
~cSound();
void SetListenerValues();
int format;
int size;
void* data;
int freq;
char loop;
unsigned int Buffers[NUM_BUFFERS];
unsigned int Sources[NUM_SOURCES];
};
#endif
/////////////////////////// sound.cpp ///////////////////////////
#include "sound.h"
float SourcesPos[NUM_SOURCES][3];
float SourcesVel[NUM_SOURCES][3];
float ListenerPos[] = { 0.0, 0.0, 0.0 };
float ListenerVel[] = { 0.0, 0.0, 0.0 };
float ListenerOri[] = { 0.0, 0.0, -1.0, 0.0, 1.0, 0.0 };
cSound::cSound()
{
alGenBuffers(NUM_BUFFERS, Buffers);
alutLoadWAVFile("jump.wav", &format, &data, &size, &freq, &loop);
alBufferData(Buffers[game], format, data, size, freq);
alutUnloadWAV(format, data, size, freq);
alGenSources(NUM_SOURCES, Sources);
alSourcei (Sources[game], AL_BUFFER, Buffers[game] );
alSourcef (Sources[game], AL_PITCH, 1.0f );
alSourcefv(Sources[game], AL_VELOCITY, SourcesVel[game]);
alSourcef (Sources[game], AL_GAIN, 1.0f );
alSourcefv(Sources[game], AL_POSITION, SourcesPos[game]);
alSourcei (Sources[game], AL_LOOPING, AL_TRUE );
}
cSound::~cSound()
{
alDeleteBuffers(NUM_BUFFERS, Buffers);
alDeleteSources(NUM_SOURCES, Sources);
alutExit();
}
void cSound::SetListenerValues()
{
alListenerfv(AL_POSITION, ListenerPos);
alListenerfv(AL_VELOCITY, ListenerVel);
alListenerfv(AL_ORIENTATION, ListenerOri);
}
/////////////////////////// main.cpp ///////////////////////////
#include "sound.h"
int main()
{
cSound cS;
alutInit(NULL, 0);
alGetError();
cS.SetListenerValues();
while(true)
{
//random code
alSourcePlay(cS.Sources[game]);
//more random code
}
system("pause");
return 0;
}
openAL sound class problem
Started by whotaces, Apr 09 2011 03:20 PM
3 replies to this topic
#1
Posted 09 April 2011 - 03:20 PM
#2
Posted 09 April 2011 - 10:53 PM
What do you mean by "when I split the class"?
Despite your bizarre coding structure, a quick glance over your code shows your audio buffer initialization routine is fine. Check that OpenAL is correctly generating IDs for you. I would also advise against using ALUT because the API is deprecated, and I think there was even problems with their WAV loading method. It's been a while so I can't remember exact details, but I remember staying far away from it. You should be initializing OpenAL using the official API methods alcOpenDevice, alcCreateContext, and alcMakeContextCurrent.
Also, just a heads up, but if you're going to be using velocity, make sure to set the doppler value (alDopplerFactor).
Despite your bizarre coding structure, a quick glance over your code shows your audio buffer initialization routine is fine. Check that OpenAL is correctly generating IDs for you. I would also advise against using ALUT because the API is deprecated, and I think there was even problems with their WAV loading method. It's been a while so I can't remember exact details, but I remember staying far away from it. You should be initializing OpenAL using the official API methods alcOpenDevice, alcCreateContext, and alcMakeContextCurrent.
Also, just a heads up, but if you're going to be using velocity, make sure to set the doppler value (alDopplerFactor).
http://www.nutty.ca - Being a nut has its advantages.
#3
Posted 06 February 2012 - 11:15 AM
I'm not sure what you mean by "split the class" either. Have you looked in the [OpenAL SDK install folder]\samples directory for some sample code to compare against?
C++, 3D OpenGL and Game Programming video tutorials:
www.MarekKnows.com
Play my free games: Ghost Toast, Zing
www.MarekKnows.com
Play my free games: Ghost Toast, Zing
#4
Posted 27 March 2012 - 07:09 AM
Can you clarify it more?
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











