gpt4 book ai didi

c++ - 初始化 FMOD 时出错

转载 作者:太空宇宙 更新时间:2023-11-04 13:49:21 25 4
gpt4 key购买 nike

我在初始化 FMOD 时遇到一个奇怪的问题,FMOD 进入某种“无限循环”并且程序停止。我做错了什么?这是函数:

FMOD::System   *fmodsyst = 0;
FMOD::Sound *sound = 0;
FMOD::Channel *channel = 0;
FMOD_RESULT result = FMOD_OK;
unsigned int version = 0;
unsigned int soundlength = 0;
bool dspenabled = false;
void *extradriverdata = 0;
unsigned int recordpos = 0;
unsigned int recorddelta = 0;
unsigned int minrecorddelta = (unsigned int)-1;
unsigned int lastrecordpos = 0;
unsigned int samplesrecorded = 0;
unsigned int playpos = 0;
float smootheddelta = 0;
int recordrate = 0;
int recordchannels = 0;
unsigned int adjustedlatency = 0;
unsigned int driftthreshold = 0;
FMOD_CREATESOUNDEXINFO exinfo;

bool Basics::InitializeFMOD()
{
FMOD_RESULT result;
unsigned int version;
result = FMOD::System_Create(&fmodsyst);
FMOD_ERRCHECK(result);
result = fmodsyst->getVersion(&version);
FMOD_ERRCHECK(result);
if (version < FMOD_VERSION)
{
return false;
}
result = fmodsyst->init(100, FMOD_INIT_NORMAL, extradriverdata); //this is the line which crashes the .dll
FMOD_ERRCHECK(result);

result = fmodsyst->getRecordDriverInfo(0, NULL, NULL, 0, 0, &recordrate, 0, &recordchannels);
FMOD_ERRCHECK(result);

adjustedlatency = (recordrate * LATENCY_MS) / 1000;
driftthreshold = adjustedlatency / 2;

memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
exinfo.numchannels = recordchannels;
exinfo.format = FMOD_SOUND_FORMAT_PCM16;
exinfo.defaultfrequency = recordrate;
exinfo.length = exinfo.defaultfrequency * sizeof(short)* exinfo.numchannels * 5; /* 5 second buffer, doesnt really matter how big this is, but not too small of course. */

result = fmodsyst->createSound(0, FMOD_LOOP_NORMAL | FMOD_OPENUSER, &exinfo, &sound);
FMOD_ERRCHECK(result);

result = fmodsyst->recordStart(0, sound, true);
FMOD_ERRCHECK(result);

result = sound->getLength(&soundlength, FMOD_TIMEUNIT_PCM);
FMOD_ERRCHECK(result);

return true;
}

此外,函数 FMOD_ERRCHECK 什么也没说。

最佳答案

您可能需要 FMOD_STUDIO_INIT_NORMAL 而不是 FMOD_INIT_NORMAL,因为您实际上是在初始化 Studio 组件而不是低级音频系统(至少不是通过该指针)。

我们可能有不同的版本,因为我的需要一个额外的参数:

_pAudioSystem->initialize(32, FMOD_STUDIO_INIT_NORMAL, FMOD_INIT_NORMAL, nullptr);

关于c++ - 初始化 FMOD 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24176015/

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