[Openal] Capture problems under Windows

Laszlo Menczel menczel at mailbox.hu
Thu Jul 12 05:29:57 PDT 2007


Hi,

I have simplified my test program to the bare minimum (code follows message
body) and have done a couple of tests. The result is rather strange. On my
home system which runs Windows 2000 and has a Realtek AC97 audio system the
test works. On the system I use at work (Windows ME, C-Media audio system)
the test runs but the number of captured samples is zero. Interestingly, the
same result is obtained when I run 'CaptureWin32.exe' distributed with the
SDK. (There was a mistake in my previous post stating that it worked under
Win ME / C-Media, sorry).

Subsequently I have tried both tests programs on a couple of machines with
the following results:

WinME, SiS 7012 controller, Xear3D -> failed to open playback device
Win2K, SoundBlaster Audio PCI 128 -> failed to open playback device
Win XP, Intel 82801BA controller -> failed to open playback device

The sound systems of these machines appear to be fully functional (other
programs e.g. Skype have no problem with sound).

I have also compiled my test program using MS Visual C++ 6.0 instead of
MinGW, but the result is the same.

Dan: I have tried what you suggested (changed the frequency and buffer size
settings) but it did not make any difference :-(

Question: Has anybody compiled the OpenAL library under MinGW? If yes, I
would appreciate getting a copy of the Makefile. If I could compile the lib,
I would be able to do some serious testing (but I would rather not spend a
lot of time setting up the build system myself :-)

Laszlo Menczel

menczel at mailbox dot hu

/*------------------- code follows ----------------------*/

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <AL/al.h>
#include <AL/alc.h>

#define BUF_SIZE	3200
#define SOUND_FREQ	8000
#define FRAME_SIZE	800

static ALCdevice *mic = NULL;
static ALCdevice *speaker = NULL;
static ALCcontext *ctx = NULL;
static char *logname = "altest.log";
static short buf[32000];
static DWORD rec_start, rec_time;

static void time_reset_period(void)
{
  timeEndPeriod(1);
}

static void time_init(void)	// needed under Win2K for accurate timing
{
  if (timeBeginPeriod(1) == TIMERR_NOERROR)
    atexit(time_reset_period);
}

static void logprintf(char *fmt, ...)
{
  FILE *f;
  char buf[512];
  va_list arglist;

  f = fopen(logname, "at");
  if (f != NULL)
  {
    va_start(arglist, fmt);
    vsprintf(buf, fmt, arglist);
    fprintf(f, "%s", buf);
    fclose(f);
  }
}

static int al_init(void)
{
  const ALchar *dev_name;

  dev_name = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
  if (dev_name == NULL)
  {
    printf("Failed to get default playback device.\n");
    return 0;
  }

  printf("Opening playback device '%s'", dev_name);
  speaker = alcOpenDevice(dev_name);
  if (speaker == NULL)
  {
    printf(" -- failed.\n");
    return 0;
  }
  else
    printf(" -- OK\n");

  ctx = alcCreateContext(speaker, NULL);
  if (ctx == NULL)
  {
    printf("OpenAL context creation failed.");
    return 0;
  }

  alcMakeContextCurrent(ctx);
    
  if (alcIsExtensionPresent(speaker, "ALC_EXT_CAPTURE") == AL_FALSE)
  {
    printf("No capture extension.\n");
    return 0;
  }

  dev_name = alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER);
  if (dev_name == NULL)
  {
    printf("Failed to get default capture device.\n");
    return 0;
  }

  printf("Opening capture device '%s'", dev_name);
  mic = alcCaptureOpenDevice(dev_name, SOUND_FREQ, AL_FORMAT_MONO16,
BUF_SIZE);
  if (mic == NULL)
  {
    printf(" -- failed.\n");
    return 0;
  }
  else
    printf(" -- OK\n");

  return 1;
}

static void record_sound(void)
{
  ALCint num;
      
  alcGetIntegerv(mic, ALC_CAPTURE_SAMPLES, 1, &num);
  logprintf("time = %d msec   sample count = %d\n", (int) rec_time, num);

  if (num >= FRAME_SIZE)
    alcCaptureSamples(mic, buf, FRAME_SIZE);

  Sleep(10);
}  

int main(int argc, char *argv[])
{
  printf("OpenAL capture test\n\n");
  
  if (! al_init())
    return 1;
  
  unlink(logname);
  time_init();
  printf("\nPress ENTER to start the test...");
  getchar();
  
  rec_start = timeGetTime();
  rec_time = 0;
  alcCaptureStart(mic);
  
  while (rec_time < 1000)
  {
    record_sound();
    rec_time = timeGetTime() - rec_start;
  }
    
  alcCaptureStop(mic);
  printf("\nDone. Press ENTER...\n");
  getchar();
  return 0;
}

-- 
View this message in context: http://www.nabble.com/Capture-problems-under-Windows-tf4062207.html#a11558688
Sent from the OpenAL - User mailing list archive at Nabble.com.



More information about the Openal mailing list