开发者

Recording Audio with OpenAL [closed]

开发者 https://www.devze.com 2023-01-03 22:00 出处:网络
开发者_C百科 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references,or expertise, but this question will likely solic
开发者_C百科 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 9 years ago.

I've been comparing various audio libraries available in C++. I was wondering, I'm kind of stuck starting with OpenAL. Can someone point out an example program how to record from a mic using OpenAL in C++.

Thanks in advance!


Open the input device and start recording using alcCaptureStart and fetch the sample using alcCaptureSamples

#include <OpenAL/al.h>
#include <OpenAL/alc.h>
#include <iostream>
using namespace std;

const int SRATE = 44100;
const int SSIZE = 1024;

ALbyte buffer[22050];
ALint sample;

int main(int argc, char *argv[]) {
    alGetError();
    ALCdevice *device = alcCaptureOpenDevice(NULL, SRATE, AL_FORMAT_STEREO16, SSIZE);
    if (alGetError() != AL_NO_ERROR) {
        return 0;
    }
    alcCaptureStart(device);

    while (true) {
        alcGetIntegerv(device, ALC_CAPTURE_SAMPLES, (ALCsizei)sizeof(ALint), &sample);
        alcCaptureSamples(device, (ALCvoid *)buffer, sample);

        // ... do something with the buffer 
    }

    alcCaptureStop(device);
    alcCaptureCloseDevice(device);

    return 0;
}


Last time I checked OpenAL it was quite simple. You create the recording device and start the recording going. You then just call the get buffer function. It will wait until there is enough data to fill the buffer and then return when there is enough data.

Why not just look at the "capture" example that comes with the OpenAL SDK ...?

0

精彩评论

暂无评论...
验证码 换一张
取 消