// Sound.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include <al.h>
#include "alc.h"
#include <alut.h>
char* alBuffer; //data for the buffer
ALenum alFormatBuffer; //for the buffer format
ALsizei alFreqBuffer; //for the frequency of the buffer
long alBufferLen; //the bit depth
ALboolean alLoop; //looped
unsigned int alSource; //buffer source
unsigned int alSampleSet;
ALCcontext *Context;
ALCdevice *Device;
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
unsigned int _stdcall InitSound()
{
Device = alcOpenDevice((ALubyte*)"DirectSound3D");
if (Device == NULL)
{
return false;
}
//Create context(s)
Context=alcCreateContext(Device,NULL);
//Set active context
alcMakeContextCurrent(Context);
// Clear Error Code
alGetError();
return true;
}
unsigned int _stdcall LoadSound(char fileName[256],bool looping)
{
ALboolean loop;
loop = looping;
//load the wave file
alutLoadWAVFile(fileName,&alFormatBuffer, (void **) &alBuffer,(unsigned int *)&alBufferLen, &alFreqBuffer, &loop);
if ((alGetError()) != AL_NO_ERROR)
{
return 0;
}
//create 1 source
alGenSources(1, &alSource);
//create 1 buffer
alGenBuffers(1, &alSampleSet);
//put the data into our sampleset buffer
alBufferData(alSampleSet, alFormatBuffer, alBuffer, alBufferLen, alFreqBuffer);
//assign the buffer to this source
alSourcei(alSource, AL_BUFFER, alSampleSet);
//release the data
alutUnloadWAV(alFormatBuffer, alBuffer, alBufferLen, alFreqBuffer);
return alSource;
}
unsigned int _stdcall Play3DSound(float xpositionSound, float ypositionSound, float zpositionSound, float xvelocitySound,
float yvelocitySound, float zvelocitySound ,float fx, float fy, float fz, float ux, float uy,
float uz, float x, float y, float z,bool LOOPS, unsigned int Source)
{
//load our sound
alSource = Source;
//set source position
alSource3f(alSource,AL_POSITION, xpositionSound, ypositionSound, zpositionSound);
//set source velocity
alSource3f(alSource,AL_VELOCITY, xvelocitySound, yvelocitySound, zvelocitySound);
//set current listener position
alListener3f(AL_POSITION, x, y, z);
//set the orientation using an array of floats
float vec[6];
vec[0] = fx;
vec[1] = fy;
vec[2] = fz;
vec[3] = ux;
vec[4] = uy;
vec[5] = uz;
alListenerfv(AL_ORIENTATION, vec);
if (LOOPS)
{
//tell the sound to loop continuously
alSourcei(alSource,AL_LOOPING,AL_TRUE);
}
else
{
//tell the sound to play once
alSourcei(alSource,false,AL_TRUE);
}
//play the sound
alSourcePlay(alSource);
return true;
}
bool _stdcall Stop3DSound(unsigned int Source)
{
alSource = Source;
alSourceStop(alSource);
if ((alGetError()) != AL_NO_ERROR)
{
return false;
}
return true;
}
bool _stdcall UnloadSound(unsigned int Source, unsigned int Sample)
{
alSampleSet = Sample;
alSource = Source;
//delete our source
alDeleteSources(1,&alSource);
//delete our buffer
alDeleteBuffers(1,&alSampleSet);
return true;
}
bool _stdcall CleanUp(unsigned int Source, unsigned int Sample)
{
alSource = Source;
alSampleSet = Sample;
//delete our source
alDeleteSources(1,&alSource);
//delete our buffer
alDeleteBuffers(1,&alSampleSet);
//Get active context
Context=alcGetCurrentContext();
//Get device for active context
Device=alcGetContextsDevice(Context);
//Disable context
alcMakeContextCurrent(NULL);
//Release context(s)
alcDestroyContext(Context);
//Close device
alcCloseDevice(Device);
return true;
}
[_source]
ne help would be great thx jake
problem after unloading a sound in OpenAL
i dont no if im doing this the right way. Its just an unload function that unloads a sound. That works ok, but when i try and load another sound, the first time i try it wont work but it will the second time. Heres the code. This is a dll incase u dont no wat the _stdcall is for.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement