changeset 21549:4a6d3fa76982

Set frequency and correct frequency getting
author reimar
date Sun, 10 Dec 2006 01:08:32 +0000
parents bf65ffcf0cdb
children 9d9e0f1ef0e9
files libao2/ao_openal.c
diffstat 1 files changed, 7 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/libao2/ao_openal.c	Sun Dec 10 00:50:38 2006 +0000
+++ b/libao2/ao_openal.c	Sun Dec 10 01:08:32 2006 +0000
@@ -69,7 +69,8 @@
   };
   ALCdevice *dev = NULL;
   ALCcontext *ctx = NULL;
-  ALint bufrate;
+  ALCint freq = 0;
+  ALCint attribs[] = {ALC_FREQUENCY, rate, 0, 0};
   int i;
   opt_t subopts[] = {
     {NULL}
@@ -87,7 +88,7 @@
     mp_msg(MSGT_AO, MSGL_FATAL, "[OpenAL] could not open device\n");
     goto err_out;
   }
-  ctx = alcCreateContext(dev, NULL);
+  ctx = alcCreateContext(dev, &attribs);
   alcMakeContextCurrent(ctx);
   alListenerfv(AL_POSITION, position);
   alListenerfv(AL_ORIENTATION, direction);
@@ -102,8 +103,10 @@
   if (channels == 1)
     alSource3f(sources[0], AL_POSITION, 0, 0, 1);
   ao_data.channels = channels;
-  alGetBufferi(buffers[0][0], AL_FREQUENCY, &bufrate);
-  ao_data.samplerate = rate = bufrate;
+  alcGetIntegerv(dev, ALC_FREQUENCY, 1, &freq);
+  if (alcGetError(dev) == ALC_NO_ERROR && freq)
+    rate = freq;
+  ao_data.samplerate = rate;
   ao_data.format = AF_FORMAT_S16_NE;
   ao_data.bps = channels * rate * 2;
   ao_data.buffersize = CHUNK_SIZE * NUM_BUF;