mario::konrad
programming / C++ / sailing / nerd stuff
OpenAL Capture
© 2009 / Mario Konrad

openal-capture.cpp:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <AL/al.h>
#include <AL/alc.h>
#include <cstdio>
#include <unistd.h>

int main(int, char **)
{
    ALCdevice * dev = alcCaptureOpenDevice(NULL, 48000, AL_FORMAT_MONO16, 4096);
    if (dev == NULL) {
        printf("error: cannot open capture device\n");
        return -1;
    }
    ALubyte buffer[16384];
    alcCaptureStart(dev);
    for (int i = 0; i < 10240;) {
        ALint n = 0;
        alcGetIntegerv(dev, ALC_CAPTURE_SAMPLES, 1, &n);
        if (n <= 0) continue;
        alcCaptureSamples(dev, (ALCvoid *)buffer, n);
        i += n;
        printf("samples captured: %d (n=%d)\n", i, n);
    }
    alcCaptureStop(dev);
    alcCaptureCloseDevice(dev);
    return 0;
}