初始化FMOD时出错

时间:2014-06-12 03:29:59

标签: c++ winapi fmod

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

1 个答案:

答案 0 :(得分:0)

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

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

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