Das die Dateien gleich sind, das kann nicht sein, da ich wie bereits geschrieben, das Projekt auch mehrmals bereinigt habe, so dass keine exe-Datei mehr da war. Bitte nicht erschrecken, hier der etwas wust kommentierte Code. :lol:
main.cpp
Code: Alles auswählen
void vInitOpenAL(void)
{
cout << "Initialising OpenAL!" << endl;
alutInit(NULL, 0);
cout << "Clearing error bit!" << endl;
alGetError();
}
void vKillOpenAL(void)
{
alutExit();
}
int main(int argc, char *argv[])
{
CSound *mySound = NULL, *secSound = NULL;
vInitOpenAL();
// kill OpenAL when exiting the program
atexit(vKillOpenAL);
mySound = new CSound();
secSound = new CSound();
// Load .wav-Files and give the possibility play it
if(mySound->bLoadWAV("wavdata/Gun2.wav", false))
{
mySound->vPlaySound();
}
if(secSound->bLoadWAV("wavdata/Gun2.wav", false))
{
secSound->vPlaySound();
}
getchar();
delete mySound;
delete secSound;
return(0);
}
Hier noch ein Ausschnitt aus den Methoden der Klassen (Konstruktor, Destruktor, laden und abspielen + die klasse an sich):
Code: Alles auswählen
class CSound
{
private:
// Sound Buffer und Source
ALuint m_Buffer;
ALuint m_Source;
// Position und Velocity
ALfloat m_SourcePos[3];
ALfloat m_SourceVel[3];
public:
CSound();
~CSound();
bool bLoadWAV(const string sPath, bool bLoop = false);
void vPlaySound(void);
void vPauseSound();
void vStopSound();
void vSetSourcePosition(ALfloat x, ALfloat y, ALfloat z);
void vSetSourceVelocity(ALfloat x, ALfloat y, ALfloat z);
};
CSound::CSound()
{
cout << "Constructor called!" << endl;
// generate source and buffer
alGenSources(1, &m_Source);
alGenBuffers(1, &m_Buffer);
// set position and velocity
vSetSourcePosition(0.0f, 0.0f, 0.0f);
vSetSourceVelocity(0.0f, 0.0f, 0.0f);
}
CSound::~CSound()
{
cout << "Destructor called!" << endl;
// Delete buffers and source
alDeleteBuffers(1, &m_Buffer);
alDeleteSources(1, &m_Source);
}
bool CSound::bLoadWAV(const string sPath, bool bLoop)
{
// error flag löschen
alGetError();
ALenum error;
ALenum format;
ALsizei size;
ALsizei freq;
ALboolean loop;
ALvoid* data;
alutLoadWAVFile("wavdata/Battle.wav", &format, &data, &size, &freq, &loop);
if ((error = alGetError()) != AL_NO_ERROR)
{
cout << "[ERROR] alutLoadWAVFile exciting_sound.wav : " << error;
return(false);
}
alBufferData(m_Buffer, format, data, size, freq);
alutUnloadWAV(format, data, size, freq);
alSourcei (m_Source, AL_BUFFER, m_Buffer );
if((error = alGetError()) == AL_INVALID_NAME)
cout << "[ERROR] AL_INVALID_NAME!" << endl;
alSourcef (m_Source, AL_PITCH, 1.0f );
alSourcef (m_Source, AL_GAIN, 1.0f );
alSourcefv(m_Source, AL_POSITION, m_SourcePos );
alSourcefv(m_Source, AL_VELOCITY, m_SourceVel );
alSourcei (m_Source, AL_LOOPING, bLoop );
if((error = alGetError()) != AL_NO_ERROR)
{
cout << "[ERROR] Unknown error occured : " << error;
return(false);
}
return(true);
}
void CSound::vPlaySound(void)
{
ALenum error;
alGetError();
// spielen
cout << "m_Source = " << m_Source << "\tm_Buffer = " << m_Buffer << endl;
alSourcePlay(m_Source);
// Fehler aufgetreten? => Anzeigen!
if((error = alGetError()) != AL_NO_ERROR)
{
cout << "[ERROR] Unknown error occured : " << error;
}
}
void CSound::vSetSourcePosition(ALfloat x, ALfloat y, ALfloat z)
{
// set position
m_SourcePos[0] = x;
m_SourcePos[1] = y;
m_SourcePos[2] = z;
// Apply changes
alSourcefv(m_Source, AL_POSITION, m_SourcePos );
}
void CSound::vSetSourceVelocity(ALfloat x, ALfloat y, ALfloat z)
{
// set velocity
m_SourceVel[0] = x;
m_SourceVel[1] = y;
m_SourceVel[2] = z;
// Apply changes
alSourcefv(m_Source, AL_VELOCITY, m_SourceVel );
}
Kann es sein, dass mir da irgendwo ein fehler beim laden unterlaufen ist, oder ich etwas nicht mehr richtig frei gebe?
EDIT:
Ich habe noch ein paar Debugausgaben eingebaut. Diese zeigen, dass der übergebene Pfad stimmt. Allerdings wird irgendwie trotzdem immer das falsche wiedergegeben...