【问题标题】:Error while initializing FMOD初始化 FMOD 时出错
【发布时间】:2015-08-13 08:45:11
【问题描述】:

我在初始化 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 函数也没有说什么。

【问题讨论】:

  • 哪条实际线路导致了问题?尝试将您的代码缩减为一个简短的独立示例,只是一个包含初始化代码的主代码,看看您是否仍然遇到同样的问题。
  • 这是导致问题的行:result = fmodsyst->init(100, FMOD_INIT_NORMAL, extradriverdata); //这是导致 .dll 崩溃的行 - 我使用 WriteToLog 函数进行了一些调试,这就是它被卡住的部分。
  • 你没有提供extradriverdata的定义,但是你提供了很多不相关的代码。请将您的问题编辑到最少的完整代码以重现问题。
  • 有,我刚刚编辑了代码。

标签: c++ winapi fmod


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2016-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-02
    • 2019-02-02
    • 1970-01-01
    相关资源
    最近更新 更多