Skip to content

Instantly share code, notes, and snippets.

@danielflira
Created September 8, 2017 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielflira/0c9ba9a595a14db7253cce8cf0e986cf to your computer and use it in GitHub Desktop.
Save danielflira/0c9ba9a595a14db7253cce8cf0e986cf to your computer and use it in GitHub Desktop.
do nothing capture with openal
#include <AL/al.h>
#include <AL/alc.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#define BUFF_SIZE 44100
#define FREQUENCY 44100
int running;
// just stop with ctrl+c
void stoprunning(int signum)
{
running = 0;
}
int main(void)
{
const ALCchar *device_list;
const ALCchar *device_default;
ALCdevice *device;
ALCubyte buffer[BUFF_SIZE];
ALCint sample;
int i, j, max_devices, selected_device;
alGetError();
// get devices informations
device_default = alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER);
device_list = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
max_devices = 0;
// list devices and mark default with '**'
for ( i=0, j=0; device_list[i] != '\0'; i++)
{
printf("%d - %s", j, &device_list[i]);
if (strcmp(&device_list[i], device_default) == 0)
{
puts(" **");
}
else
{
puts("");
}
for ( ; device_list[i] != '\0'; i++);
max_devices++;
j++;
}
// let select device
puts("\nselect your device");
scanf("%d", &selected_device);
// valid selected device
if ( selected_device < 0 || selected_device >= max_devices)
{
printf("invalid device selection!\n");
return 1;
}
// position on selected device
for ( i=0, j=0; j<=selected_device; j++)
{
device_default = &device_list[i];
for ( ; device_list[i] != '\0'; i++);
i++;
}
// output device name confirmation
printf("\n%s selected\n", device_default);
// open device with 44100 frequence and same buffersize
device = alcCaptureOpenDevice(device_default, FREQUENCY, AL_FORMAT_MONO8, BUFF_SIZE);
if ( device == 0 )
{
printf("could not open device, with error: %d\n", alGetError());
return 1;
}
alcCaptureStart(device);
// attach signal handler
running = 1;
signal(SIGINT, stoprunning);
puts("\nstarting...");
while ( running )
{
// check how much was read
alcGetIntegerv(device, ALC_CAPTURE_SAMPLES, (ALCsizei) sizeof(ALCint), &sample);
// copy internal framebuffer to external
alcCaptureSamples(device, (ALCvoid*) buffer, sample);
// do something with buffer
}
alcCaptureStop(device);
alcCaptureCloseDevice(device);
printf("finalizing...");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment