0
0

Hi folks.

We’re looking at using FMOD for our audio playback in a game we’re porting to iPhone. We already use FMOD for the Windows version. Whenever we try to play back a MIDI file, however, we get a crash (EXC_BAD_ACCESS) in FMOD_DSP_Connection_MixMonoToStereo_SIMD almost immediately after playback begins:

FMOD_DSP_Connection_MixMonoToStereo_SIMD
FMOD::DSPConnectionI::mix
FMOD::DSPFilter::execute
FMOD::DSPSoundCard::execute
FMOD::CodecMIDI::readInternal
FMOD::Codec::read
FMOD::SoundI::readData
FMOD::SoundI::read
FMOD::Stream::fill
FMOD::ChannelStream::updateStream
FMOD::SystemI::updateStreams
FMOD::Thread::callback

An almost identical crash occurs if we use createSound rather than createStream. In the iPhone Simulator, the code works fine. As well, playback of MP3 audio works without issue (but we can do that without the use of FMOD anyway.) Any idea what might be the cause of the problem?

Here’s the code we’re using.
[code:13z9ob56]#import "PFFMODMusic_.h"

if HAVE_FMOD

include "fmod.hpp"

include "fmod_errors.h"

@implementation PFFMODMusic_

define R(STATEMENT) ({ FMOD_RESULT r = (STATEMENT); if (r != FMOD_OK) GTLogError(@"error %i in FMOD statement %s: %s", r, #STATEMENT, FMOD_ErrorString(r)); (r == FMOD_OK); })

static FMOD::System *sys = NULL;
static const char *dlsPath = NULL;

  • (void)initialize {
    if (self != [PFFMODMusic_ class])
    return;

    if (R(FMOD::System_Create(&sys))) {
    R(sys->setOutput(FMOD_OUTPUTTYPE_AUTODETECT));
    R(sys->setDriver(FMOD_DEFAULT));
    R(sys->setDSPBufferSize(1024, 10));
    if (R(sys->init(8, FMOD_INIT_VOL0_BECOMES_VIRTUAL | FMOD_INIT_SOFTWARE_REVERB_LOWMEM, NULL))) {
    unsigned int v = 0;
    sys->getVersion(&v);
    GTLog(@"FMOD v%x", v);

        /* Get the sound font (iPhone has none by default.) */
        NSString *dls = [[NSBundle mainBundle] pathForResource: @"gm" ofType: @"dls"];
        if (dls)
            dlsPath = strdup([dls fileSystemRepresentation]);
    } else {
        /* Init failed, no playback possible. */
        sys->release();
        sys = NULL;
    }
    

    }
    }

  • (id)initWithURL: (NSURL *)aURL {
    self = [super initWithURL: aURL];
    if (self) {
    if ([aURL isFileURL]) {
    const char *path = [[aURL path] fileSystemRepresentation];

        FMOD_CREATESOUNDEXINFO info;
        memset(&info, 0, sizeof(info));
        info.cbsize = sizeof(info);
        info.dlsname = dlsPath;
    
        FMOD::Sound *s = NULL;
        if (sys && R(sys->createStream(path, FMOD_DEFAULT | FMOD_2D | FMOD_LOOP_OFF | FMOD_LOWMEM, &info, &s))) {
            self->pSound = (void *)s;
        } else {
            [self release];
            self = nil;
        }
    } else {
        GTLogError(@"%@ only supports file:// URLs", [self class]);
        [self release];
        self = nil;
    }
    

    }

    return self;
    }

  • (void)dealloc {
    [self stop];

    FMOD::Sound *s = (FMOD::Sound *)self->pSound;
    if (s)
    s->release();

    [super dealloc];
    }

  • (void)play {
    /* Ensure we’re not playing twice. */
    [self stop];

    FMOD::Sound *s = (FMOD::Sound *)self->pSound;
    if (s) {
    FMOD::Channel *c = NULL;
    if (R(sys->playSound(FMOD_CHANNEL_FREE, s, false, &c))) {
    self->pChannel = (void *)c;
    }
    }
    }

  • (void)stop {
    FMOD::Channel *c = (FMOD::Channel *)self->pChannel;
    if (c) {
    self->pChannel = NULL;
    c->stop();
    }
    }
    @end

endif /* HAVE_FMOD */[/code:13z9ob56]

If you’re not familiar with Objective-C, the System object is set up when our wrapper class (PFFMODMusic_) is first used (in +initialize) and the sound is created using createStream() when PFFMODMusic_ is instantiated.

  • You must to post comments
0
0

The crash also occurs when attempting to play module files.

  • You must to post comments
0
0

This issue has been tracked down via e-mail and resolved.

An updated release of the iPhone package (v4.21.04) will be uploaded shortly.

  • You must to post comments
0
0

Thanks for the quick assistance!

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.