[Openal] Capture problems under Windows

Laszlo Menczel menczel at mailbox.hu
Wed Jul 11 07:15:36 PDT 2007


Hi,

I'm using OpenAL 1.1 on the following system:

Windows ME
DirectX 9.0
C-Media audio (VIA 3059 controller, Xear 3D audio engine with DS3D and EAX
2.0)

I have problems with audio capture. The capture device list does not show
generic hardware and software devices (according to what I have read in the
docs and in forum messages these should be present). The only device shown
is the C-Media Wave device. Generic devices ("Generic Hardware" or "Generic
Software") cannot be opened (an error is reported). When I open the C-Media
device and try to capture sound, there are no samples in the capture buffer,
the call

alcGetIntegerv(device, ALC_CAPTURE_SAMPLES, 1, &num)

returns zero in 'num'. At every step in my test program I check if any error
occurs, but I never get an error message, so the code seems to be working. I
have included the relevant parts of my test program (the code is below,
after the message body). My development system is MinGW (GCC compiler ported
to Win32). I use the OpenAL DLL downloaded from openal.org (probably created
using Visual C++). It is directly linked to my test program (this is
possible under MinGW, and has worked for me so far with several other Visual
C++ DLLs).

The sound system is fully functional and the capture demo included in the
SDK does work. Also, the sound playing part of my test program works w/o
problems.

I would appreciate if someone would check the code below and give advice on
how to solve the problem. Thanks!

Laszlo Menczel

menczel at mailbox dot hu

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

#define AL_BUF_SIZE       16000
#define MAX_NUM_DEV     16
#define FRAME_COUNT     800

static int al_init = 0;
static int recording = 0;

static ALCdevice *mic = NULL;
static ALCdevice *speaker = NULL;
static ALCcontext *al_ctx = NULL;

static int al_init_sys(void)
{
  int numdev, dev_id;
  char dev_name[MAX_NUM_DEV][64];
  const ALchar *dev_list;

  //=========== Display list of playback devices & get user selection
  
  dev_list = alcGetString(NULL, ALC_DEVICE_SPECIFIER);
  
  if (dev_list == NULL)
  {
    printf("Failed to get playback device list.\n");
    return 0;
  }

  numdev = 0;
  printf("Playback devices:\n");

  while (*dev_list && numdev < MAX_NUM_DEV)
  {
    printf("  %d %s\n", numdev + 1, dev_list);
    strncpy(dev_name[numdev], dev_list, 63);
    dev_list += strlen(dev_list) + 1;
    numdev++;
  }

  ......
  code to get the ID 'dev_id' of selected device
  .....
      
  //=========== open the selected playback device

  speaker = alcOpenDevice(dev_name[dev_id]);

  if (speaker == NULL)
  {
    printf("Opening the selected playback device failed.\n");
    return 0;
  }

  //=========== create context for output device

  al_ctx = alcCreateContext(speaker, NULL);

  if (al_ctx == NULL)
  {
    printf("OpenAL context creation failed.\n");
    return 0;
  }

  alcMakeContextCurrent(al_ctx);
    
  //=========== Check for Capture Extension support

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

  //=========== Display list of capture devices & get user selection
  
  dev_list = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
  
  if (dev_list == NULL)
  {
    printf("Failed to get capture device list.\n");
    return 0;
  }

  numdev = 0;
  printf("Capture devices:\n");

  while (*dev_list && numdev < MAX_NUM_DEV)
  {
    printf("  %d %s\n", numdev + 1, dev_list);
    strncpy(dev_name[numdev], dev_list, 63);
    dev_list += strlen(dev_list) + 1;
    numdev++;
  }

  ......
  code to get the ID 'dev_id' of selected device
  .....
      
  //=========== open the selected capture device

  mic = alcCaptureOpenDevice(dev_name[dev_id], 8000, AL_FORMAT_MONO16,
AL_BUF_SIZE);

  if (mic == NULL)
  {
    printf("Opening the selected capture device failed.\n");
    return 0;
  }

  .......
  code to create source and buffers
  .......

  al_init = 1;
  return 1;
}

// This is the sound recording function repeatedly called from the main
loop:
//  ....
//  if (recording)
//    record_next_sound();
//  .... 
// Samples are saved to the ring buffer 'recbuf'. Chunk size is FRAME_COUNT
// (about 0.1 second of sound).

static void record_next_sound(void)
{
  ALCvoid *sound;
  ALCint num;
      
  if (stop_rec || recbuf.count >= rec_count)
  {
    printf("Finished recording.\n");
    alcCaptureStop(mic);
    recording = 0;
    return;
  }

  if (get_system_time() - rec_start < 1000)        // wait for one second
before testing
    return;

  alcGetIntegerv(mic, ALC_CAPTURE_SAMPLES, 1, &num);

  if (num >= FRAME_COUNT)
  {
    sound = (ALCvoid *) (recbuf.data + recbuf.head);
    alcCaptureSamples(mic, sound, FRAME_COUNT);
    incr_bufptr(&recbuf, HEAD_PTR);
  }
  else
  {
    printf("No samples captured during the first second.\n");
    alcCaptureStop(mic);
    recording = 0;
  }    
}  

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



More information about the Openal mailing list