I’m trying to reuse a sound engine I built in a previous game, that is built on top of FMod. All the FMod initialization code is exactly the same from the old game, but it won’t start in the new project. If I use the old Mac-Intel-only dylib that I used in the old project, I get ERR_INVALID_SPEAKER, and if I use any of the versions downloadable from the site, I get FMOD_ERR_INVALID_PARAM. This is the code in question, with the error on createStream:


    this->Base::init(ds, speakerMode, speakerConfiguration, sampleRate, bufferSize, channelBlending);

    e(_fmod->init(32, FMOD_INIT_NORMAL, 0));

    LogDebug1("Sound", "channels: %d mode: %d", _channels, _speakerMode);

        csi.cbsize = sizeof(csi);
        csi.length = _bufferSize*sizeof(pcm_t);
        csi.fileoffset = 0;
        csi.numchannels = _channels;
        csi.defaultfrequency = _sampleRate;
        csi.format = FMOD_SOUND_FORMAT_PCM16;
        csi.decodebuffersize = _bufferSize*sizeof(pcm_t);
        csi.initialsubsound = 0;
        csi.numsubsounds = 0;
        csi.inclusionlist = 0;
        csi.inclusionlistnum = 0;
        csi.pcmreadcallback = RMS::Sound::Playback::FMODRawPlaybackCallback;
        csi.pcmsetposcallback = 0;
        csi.nonblockcallback = 0;
        csi.dlsname = 0;
        csi.encryptionkey = 0;
        csi.maxpolyphony = 0;
        csi.userdata =(void*)(this);
        csi.suggestedsoundtype = FMOD_SOUND_TYPE_USER;

    FMOD::Channel *generatorChannel;

    e(_fmod->createStream("FMODRaw", FMOD_OPENUSER | FMOD_LOOP_NORMAL | FMOD_2D | FMOD_SOFTWARE, &csi, &_generator));


In the output, I get "Sound[Dbg1] channels: 2 mode: 2", so numchannels in the soundexinfo corresponds to the same as the speaker mode I’ve initialized the fmod subsystem with (FMOD_SPEAKERMODE_STEREO).

Any clues as to what is going wrong? Any help is greatly appreciated :)

  • You must to post comments

You could also use memzero() for readability:
[code:19wn8lf5]memzero( csi, sizeof( FMOD_CREATESOUNDEXINFO ) );[/code:19wn8lf5]

  • You must to post comments

[quote="Dogbert":1h56unu4]You could also use memzero() for readability:
[code:1h56unu4]memzero( csi, sizeof( FMOD_CREATESOUNDEXINFO ) );[/code:1h56unu4][/quote:1h56unu4]

Yeah, realized that the second after I posted… :) Or rather, memset, since memzero isn’t cross-platform. Thanks, though.

  • You must to post comments

memset to sizeof struct is the most futureproof way to handle any extra members being added in the future. We always make 0 the default ignore/noop value.

  • You must to post comments

Ack, found it. It seems the FMOD_CREATESOUNDEXINFO struct has either grown since last I used it, or it was magically zeroed somehow before. Making sure I zero every field in the struct before sending it to createStream makes everything work A-OK.

csi.useropen = 0;
csi.userclose = 0;
csi.userread = 0;
csi.userseek = 0;
csi.initialsoundgroup = 0;
csi.initialseekposition = 0;
csi.initialseekpostype = 0;

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.