title: Basic OpenAL code to play a sound
body: <p>I'm new using OpenAl library. I'm following the OpenAl programming guide but i can't find.</p>
  
  <p>I have this code extracted from page 10 of the OpenAl programming guide but still have no sound. I use OSX Snow Leopard, i know OSX doesn't have ALUT defined.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/stat.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;stdlib.h&gt;
  
  #include &lt;OpenAL/al.h&gt;
  #include &lt;OpenAL/alc.h&gt;
  
  using namespace std;
  
  #define NUM_BUFFERS 3
  #define BUFFER_SIZE 4096
  
  int main(int argc, char **argv)
  {
      ALCdevice *dev;
      ALCcontext *ctx;
      struct stat statbuf;
  
      Aluint buffer[NUM_BUFFERS];
      Aluint source[NUM_SOURCES];
  
      ALsizei size, freq;
      ALenum format;
      ALvoid *data;
  
      // Initialization 
      dev = alcOpenDevice(NULL); // select the "preferred dev" 
  
      if (dev) 
      { 
          ctx = alcCreateContext(dev,NULL); 
          alcMakeContextCurrent(ctx);  
      } 
      // Check for EAX 2.0 support 
      // g_bEAX = alIsExtensionPresent("EAX2.0");
  
      // Generate Buffers 
      alGetError(); // clear error code 
      alGenBuffers(NUM_BUFFERS, buffer); 
      if ((error = alGetError()) != AL_NO_ERROR) 
      { 
          DisplayALError("alGenBuffers :", error); 
          return 1; 
      } 
      // Load test.wav 
      loadWAVFile("sample.wav", &amp;format, &amp;data, &amp;size, &amp;freq, &amp;loop); 
      if ((error = alGetError()) != AL_NO_ERROR) 
      { 
          DisplayALError("LoadWAVFile sample.wav : ", error); 
          alDeleteBuffers(NUM_BUFFERS, buffer); 
       return 1; 
      }
  
      // Copy test.wav data into AL Buffer 0 
      alBufferData(buffer[0], format, data, size, freq); 
      if ((error = alGetError()) != AL_NO_ERROR) 
      { 
       DisplayALError("alBufferData buffer 0 : ", error); 
       alDeleteBuffers(NUM_BUFFERS, buffer); 
       return 1; 
      } 
  
      // Unload test.wav 
      unloadWAV(format, data, size, freq); 
      if ((error = alGetError()) != AL_NO_ERROR) 
      { 
          DisplayALError("UnloadWAV : ", error); 
          alDeleteBuffers(NUM_BUFFERS, buffer); 
          return 1; 
      } 
      // Generate Sources 
      alGenSources(1, source); 
      if ((error = alGetError()) != AL_NO_ERROR) 
      { 
          DisplayALError("alGenSources 1 : ", error); 
          return 1; 
      } 
      // Attach buffer 0 to source
      alSourcei(source[0], AL_BUFFER, buffer[0]); 
      if ((error = alGetError()) != AL_NO_ERROR) 
      { 
          DisplayALError("alSourcei AL_BUFFER 0 : ", error); 
      } 
  
      // Exit 
      ctx = alcGetCurrentContext(); 
      dev = alcGetContextsDevice(ctx); 
      alcMakeContextCurrent(NULL); 
      alcDestroyContext(ctx); 
      alcCloseDevice(dev);
  
      return 0;
  }
  </code></pre>
  
  <p>What things I missed to make this code work ???
  What i'm doing wrong ???</p>
  
  <p>Any advice could help, thanks.</p>