gpt4 book ai didi

c++ - OpenAL 捕获音频时出错

转载 作者:行者123 更新时间:2023-11-30 05:13:34 25 4
gpt4 key购买 nike

我正在使用 OpenAL 框架 ( https://github.com/kcat/openal-soft ) 从麦克风捕获音频。主文件是(在 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;
}

我使用以下 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)

编译工作正常,但是当我运行 ./main 时,我得到了这个:

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

你知道为什么吗?

最佳答案

第一个警告很容易解决:如果之前没有调用过 OpenAL 函数,请不要调用 alGetError

那么请看一下https://openal.org/documentation/openal-1.1-specification.pdf中的6.4.2节。 .

您可以看到 alcCaptureOpenDevice 在失败时返回 NULL。您应该检查返回值。

此外,这里您将 NULL 作为 alcCaptureOpenDevice 的第一个参数,回退到您可能没有的默认设备。建议查询可用设备列表,然后打开其中一个(pdf中也有说明)。

关于c++ - OpenAL 捕获音频时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43887173/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com