N
Hi zsammen.
Ich bin noch ein ziemlicher anfänger was openAl angeht.
Dennoch hab ich mir schon eine einfache klasse dazu geschrieben.
Mein Code ist folgender:
Engine.h
#include <string>
#include <iostream>
#include <AL/al.h>
#include <AL/alut.h>
#include <vector>
class SoundNode
{
public:
SoundNode();
~SoundNode();
void setSound(char *new_sound);
void setSourcePosition(ALfloat new_x, ALfloat new_y, ALfloat new_z);
void play(void);
char *Sound;
private:
ALfloat ListenerPosition[3];
ALfloat ListenerVelocity[3];
ALfloat ListenerOrientation[6];
void KillAlData(void);
void setListenerValues(void);
ALuint *Buffer;
ALuint *Source;
ALenum *format;
ALsizei *size;
ALvoid* data;
ALsizei *freq;
ALboolean *loop;
};
Engine.cpp:
#include <string>
#include <AL/al.h>
#include <AL/alut.h>
#include <vector>
#include "Engine.h"
SoundNode::SoundNode(void)
{
this->ListenerPosition[0]=0.0;
this->ListenerPosition[1]=0.0;
this->ListenerPosition[2]=0.0;
this->Sound=NULL;
}
SoundNode::~SoundNode(void)
{
delete [] this->Sound;
delete this->Buffer;
delete this->Source;
delete this->format;
delete this->size;
delete this->data;
delete this->freq;
delete this->loop;
delete this;
}
void SoundNode::setSourcePosition(ALfloat new_x, ALfloat new_y, ALfloat new_z)
{
this->ListenerPosition[0]=new_x;
this->ListenerPosition[1]=new_y;
this->ListenerPosition[2]=new_z;
}
void SoundNode::setSound(char* new_sound)
{
this->Sound = new char[strlen(new_sound) + 1];
strcpy(this->Sound,new_sound);
}
void SoundNode::play(void)
{
alutInit(0,0);
setListenerValues();
alSourcePlay(*this->Source);
}
void SoundNode::setListenerValues(void)
{
alListenerfv(AL_POSITION, this->ListenerPosition);
alListenerfv(AL_VELOCITY, this->ListenerVelocity);
alListenerfv(AL_ORIENTATION, this->ListenerOrientation);
}
Main.cpp:
#include <string>
#include <iostream>
#include <AL/al.h>
#include <AL/alut.h>
#include <vector>
#include "Engine.h"
int main(int argc, char *argv[])
{
SoundNode *sound;
sound->setSound("C:/a.wav");
sound->play();
}
Das Programm lässt sich ohne fehlermeldung kompileren,
Aber der sound(von dem ich weiss das er existiert) wird nicht abgespielt.
Ich habe den verdacht ,dass es an der funktion alutInit liegt der ich keine
Parameter von main() übergeben kann.
Bitte helft mir!