Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1. #define NUM_BUFFERS 1
  2. #define NUM_SOURCES 1
  3.  
  4. ALuint buffer[NUM_BUFFERS];
  5. ALuint source[NUM_SOURCES];
  6.  
  7. void InitSound(void) {
  8.     ALfloat listenerPos[] = { 0.0f, 0.0f, 0.0f };
  9.     ALfloat listenerVel[] = { 0.0f, 0.0f, 0.0f };
  10.     ALfloat listenerOri[] = { 0.0f, 0.0f, 0.0f,  0.0f, 0.0f, 0.0f };
  11.  
  12.     ALfloat sourcePos[] = { 0.0f, 0.0f, 0.0f };
  13.     ALfloat sourceVel[] = { 0.0f, 0.0f, 0.0f };
  14.  
  15.     ALsizei size, freq;
  16.     ALenum format;
  17.     ALvoid* data;
  18.     ALboolean loop = true;
  19.  
  20.     //now with the variables set
  21.  
  22.     alListenerfv(AL_POSITION, listenerPos);
  23.     alListenerfv(AL_VELOCITY, listenerVel);
  24.     alListenerfv(AL_ORIENTATION, listenerOri);
  25.  
  26.     alGetError();
  27.  
  28.     alGenBuffers(NUM_BUFFERS, buffer);
  29.  
  30.     if(alGetError() != AL_NO_ERROR)
  31.         std::cout<< "Error creating buffers!\n";
  32.  
  33.     alutLoadWAVFile("Media/sound/dfurr.wav",&format,&data,&size,&freq, &loop);
  34.     alBufferData(buffer[0],format,data,size,freq);
  35.     alutUnloadWAV(format,data,size,freq);
  36.  
  37.     alGetError(); /* clear error */
  38.     alGenSources(NUM_SOURCES, source);
  39.  
  40.     if(alGetError() != AL_NO_ERROR)
  41.         std::cout << "- Error creating sources!\n";
  42.  
  43.     alSourcef(source[0], AL_PITCH, 1.0f);
  44.     alSourcef(source[0], AL_GAIN, 1.0f);
  45.     alSourcefv(source[0], AL_POSITION, sourcePos);
  46.     alSourcefv(source[0], AL_VELOCITY, sourceVel);
  47.     alSourcei(source[0], AL_BUFFER,buffer[0]);
  48.     alSourcei(source[0], AL_LOOPING, loop);
  49.  
  50.  
  51. }
  52.  
  53. int main(int argc, char** argv){
  54.  
  55. InitSound();
  56. alSourcePlay(source[0]);
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement