Reputation: 391
I'm using the OpenAL framework (https://github.com/kcat/openal-soft) to capture audio from microphone. The main file is (found here on stackoverflow) :
#include <stdio.h>
#include "AL/al.h"
#include "AL/alc.h"
using namespace std;
const int SRATE = 44100;
const int SSIZE = 1102;
ALbyte buffer[220500];
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;
}
to compile the main file I use the following CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project( SharedLibrary C CXX )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -fPIC -fpermissive")
set(OPENAL_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/openal/")
set(OPENAL_LIB_DIR "${OPENAL_ROOT}build")
set(OPENAL_INCLUDE_DIR "${OPENAL_ROOT}include/AL")
include_directories(${OPENAL_INCLUDE_DIR})
link_directories(${OPENAL_LIB_DIR})
add_executable( main main.cpp )
target_link_libraries( main openal)
The compiling works fine but when I run the ./main I obtain this:
AL lib: (WW) alGetError: Querying error state on null context (implicitly 0xa004)
AL lib: (WW) jack_msg_handler: Cannot connect to server socket err = No such file or directory
AL lib: (WW) jack_msg_handler: Cannot connect to server request channel
AL lib: (WW) jack_msg_handler: jack server is not running or cannot be started
AL lib: (WW) jack_msg_handler: JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
AL lib: (WW) jack_msg_handler: JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
AL lib: (WW) ALCjackBackendFactory_init: jack_client_open() failed, 0x11
AL lib: (WW) alc_initconfig: Failed to initialize backend "jack"
AL lib: (WW) alGetError: Querying error state on null context (implicitly 0xa004)
AL lib: (EE) alc_cleanup: 1 device not closed
Do you know why?
Upvotes: 1
Views: 1619
Reputation: 1649
The first warning is trivial to solve: don't call alGetError
if no OpenAL function have been called before.
Then please have a look at section 6.4.2 in https://openal.org/documentation/openal-1.1-specification.pdf .
You can read that alcCaptureOpenDevice
returns NULL when failing. You should check for the return value.
Also, here you give NULL as first argument of alcCaptureOpenDevice
falling back to a default device you probably don't have. It is recommended to query the list of the available devices and then opening one of them (This is also described in the pdf).
Upvotes: 1