I use FMOD to play Midi files that my app generates, but when I use system->playSound the playback starts at a tiny offset in the file. The consequence being that for instance the drums on the very first beat are inaudible.

When I play the same midi file in QuickTime or Logic , it sounds fine.

The system-init code is as follows:

[code:38hfmia4]FMOD_IPHONE_EXTRADRIVERDATA extradriverdata;
memset(&extradriverdata, 0, sizeof(FMOD_IPHONE_EXTRADRIVERDATA));
extradriverdata.forceSpeakerOutput = forceOutput;
result = systemFMOD->init(kMaxChannels, FMOD_INIT_NORMAL, &extradriverdata);

Fyi, I use FMOD_IPHONE_SESSIONCATEGORY_PLAYANDRECORD because I record audio on top of the Midi playback.

The createSound looks like this:

[code:38hfmia4]FMOD_CREATESOUNDEXINFO midiSoundExInfo;
memset(&midiSoundExInfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
midiSoundExInfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);

// Specify the .dls file

NSString *dls_path = [[NSBundle mainBundle] pathForResource:@"gs_instruments" ofType:@"dls"];
midiSoundExInfo.dlsname = [dls_path cStringUsingEncoding:NSASCIIStringEncoding];

// Create sound

if (midiSound) midiSound = NULL;

result = systemFMOD->createSound(buffer, FMOD_SOFTWARE, &midiSoundExInfo, &midiSound);

The playSound code looks like this:

[code:38hfmia4]result = systemFMOD->playSound(FMOD_CHANNEL_REUSE, midiSound, false, &midiChannel);[/code:38hfmia4]

I’ve tried to pause the sound for a while and then unpause with midiChannel->setPaused, but it made no difference.

If I repeat the midi file using NSTimer with repeat set, all subsequent iterations are fine. It’s only the first beat of the first run-through that is a problem.

Ideas anyone? Pleeeease? :-)

thx & brgds[/code]

  • You must to post comments

Hi again,

I found a workaround if anyone is interested.

I simply start playing the midi sound in silence for almost 1 beat, then I start it with NSTimer 1 beat later with the volume set to 1.0. Like this:

[code:1k6vb2w9]- (void)playMidiSoundinSilence:(BOOL)silence {

float fGain = 1.0;
if (silence) fGain = 0.0;

// Play midiSound

if (midiSound) {
if (midiChannel) midiChannel->stop();
result = systemFMOD->playSound(FMOD_CHANNEL_REUSE, midiSound, false, &midiChannel);
result = midiChannel->setVolume(fGain);

Dirty, but it works. :-)


  • You must to post comments

Can you provide a link to the MIDI file that you are having trouble with or e-mail it to support@fmod.org. We can have a look and find out why it skips the first beat when played the first time.

  • You must to post comments

Thanks for the bug report, I have found a subtle bug in our MIDI playback engine. It seems the very start of the MIDI file would play incorrectly, essentially it would ignore the first 5ms or so of the file.

I have corrected the issue and it will be fixed for our next release.

  • You must to post comments

Wow, that was quick! :-)

Thx Mathew.


  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.