Под Linux следующий исходник работает без проблем:
/* Open and play WAV-file. */
#include <al.h>
#include <alc.h>
#include <stdlib.h>
#include <stdio.h>
#ifdef __WIN32__
#include <windows.h> /* Sleep() */
#else
#include <unistd.h>
#endif
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};
int main (int argc, char **argv) {
ALCdevice *device;
ALCcontext *context;
char *filename;
ALuint source;
ALfloat mPos[3];
ALfloat mVel[3];
unsigned int buffer;
ALvoid *_p;
ALsizei _size;
ALsizei _rate; /* sizei? */
ALenum _format;
ALboolean _loop;
if (argc < 2) {
printf ("Need arguments: [filename]\n");
return 0;
}
filename = argv[1];
/* Инициализировали устройство, default */
/* либо строка с названием устройства */
device = alcOpenDevice (NULL);
if (!device) { printf ("Error opening device.\n"); return -1; }
context = alcCreateContext (device, NULL);
if (!context) { printf ("Error create context.\n"); return -1; }
alcMakeContextCurrent (context);
alListenerfv (AL_POSITION, ListenerPos);
alListenerfv (AL_VELOCITY, ListenerVel);
alListenerfv (AL_ORIENTATION, ListenerOri);
alGenSources (1, &source);
/* Тон звука; Усиление с расстоянием */
alSourcef (source, AL_PITCH, 1.0f);
alSourcef (source, AL_GAIN, 1.0f);
alSourcefv (source, AL_POSITION, mPos);
alSourcefv (source, AL_VELOCITY, mVel);
/* Зациклен ли? */
alSourcef (source, AL_LOOPING, 0);
/* Загрузить данные */
alGenBuffers (1, &buffer);
alutLoadWAVFile ((ALbyte *) filename, &_format, &_p, &_size, &_rate, &_loop);
alBufferData (buffer, _format, _p, _size, _rate);
alutUnloadWAV (_format, _p, _size, _rate);
alSourcei (source, AL_BUFFER, buffer);
printf ("Ready.\n");
alSourcePlay (source);
ALint status;
do {
alutSleep (0.1f);
alGetSourcei (source, AL_SOURCE_STATE, &status);
} while (status == AL_PLAYING);
#ifdef __WIN32__
Sleep (200);
#else
usleep (1000*200);
#endif
alSourceStop (source);
alDeleteSources (1, &source);
alDeleteBuffers (1, &buffer);
alcMakeContextCurrent (NULL);
alcDestroyContext (context);
alcCloseDevice (device);
printf ("Quit.\n");
return 0;
}
@ECHO OFF
SET NAME=alplay
C:\Dev-Cpp\bin\gcc.exe -O3 -Iinclude %NAME%.c -c -o _%NAME%.obj
C:\Dev-Cpp\bin\gcc.exe _%NAME%.obj -o _%NAME% OpenAL32.dll alut.dll
_alplay.exe Message.wav
DLL'ки с includes брал здесь, http://connect.creativelabs.com/openal/Downloads/Forms/AllItems.aspx