#pragma comment(lib, "openal32.lib")
#pragma comment(lib, "alut.lib")
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <al/al.h>
#include <al/alc.h>
#include <al/alut.h>
//#define USE_ALUT
int main(int argc, char *argv[])
{
#ifndef USE_ALUT
const ALCchar *defaultDevice = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
if (defaultDevice == NULL) return 1;
ALCdevice *device = alcOpenDevice(defaultDevice);
if (device == NULL) return 1;
ALCcontext *context = alcCreateContext(device, NULL);
if (context == NULL) return 1;
if (alcMakeContextCurrent(context) == AL_FALSE) return 1;
#else
alutInit(&argc, argv);
#endif
ALuint buffer, source;
ALfloat SourcePos[] = { 0.0, 0.0, 0.0 };
ALfloat SourceVel[] = { 0.0, 0.0, 0.0 };
ALfloat ListenerPos[] = { 0.0, 0.0, 0.0 };
ALfloat ListenerVel[] = { 0.0, 0.0, 0.0 };
ALfloat ListenerOri[] = { 0.0, 0.0, -1.0, 0.0, 1.0, 0.0 };
ALenum format;
ALsizei size;
ALvoid* data;
ALfloat freq;
alGenBuffers(1, &buffer);
data = alutLoadMemoryFromFile("Rupem Baraka.wav", &format, &size, &freq);
alBufferData(buffer, format, data, size, ALsizei(freq));
alutUnloadWAV(format, data, size, ALsizei(freq));
alGenSources(1, &source);
alSourcei (source, AL_BUFFER, buffer );
alSourcef (source, AL_PITCH, 1.0f );
alSourcef (source, AL_GAIN, 1.0f );
alSourcefv(source, AL_POSITION, SourcePos);
alSourcefv(source, AL_VELOCITY, SourceVel);
alSourcei (source, AL_LOOPING, 1 );
alListenerfv(AL_POSITION, ListenerPos);
alListenerfv(AL_VELOCITY, ListenerVel);
alListenerfv(AL_ORIENTATION, ListenerOri);
printf("Controls:\n");
printf("1 = play\n");
printf("2 = pause\n");
printf("3 = stop\n");
printf("0 = exit\n");
char key;
do
{
key = _getch();
if (key == '1') alSourcePlay(source);
if (key == '2') alSourcePause(source);
if (key == '3') alSourceStop(source);
}
while (key != '0');
alDeleteBuffers(1, &buffer);
alDeleteSources(1, &source);
alutExit();
return 0;
}
OpenAL Initialization Problem
Started by Spike7d5, Jul 22 2007 10:55 AM
3 replies to this topic
#1
Posted 22 July 2007 - 10:55 AM
OpenAL captured my interest a couple of days ago. So, I began looking for tutorials and I've managed to play sound by using alut, but, if I want to use AL only, the sound just doesn't hear. The code is very simple and i've looked through it many times, but still I haven't found the problem. Could you please help me? I must mention that if i define USE_ALUT it works fine.
#2
Posted 22 July 2007 - 12:19 PM
If you supply a null for alcOpenDevice(), it will automatically use the default device so you don't need to make that additional getString() call. Other than that, the rest of your code looks fine.
http://www.nutty.ca - Being a nut has its advantages.
#3
Posted 22 July 2007 - 02:21 PM
I've finally found the problem: using alut functions without prior calling of alutInit isn't going to work. So the device was correctly initialized, but nothing was buffered. I've written my own loadWAV function and everything works fine. No need for alut anymore 
Thanks for your time
Thanks for your time
#4
Posted 05 September 2007 - 12:05 PM
can u explain me better how u solved your problem?
i have problems with alut too
i have problems with alut too
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











