Page 1 of 1

Playback stops

Posted: Tue Sep 14, 2010 9:17 pm
by surffer3d
Hi,

I've encapsulted in my own classes some calls of Maxmod, but I found a problem that I'm not sure where it comes from. By experimenting, it looks like if my classes have virtual functions, the sound system will not work as expected. Let me show you a working example of using MaxMod directly and the test I checked (in the examples I load the soundbank from FAT with a call like this mmInitDefault("nitro:/audio/soundbank.bin") ):

MaxMod version:

Code: Select all

mmLoad (MOD_TEST1);
mmStart (MOD_TEST1, MM_PLAY_LOOP);

// After 2 seconds
mmStop();
mmUnload (MOD_TEST1);
mmLoad (MOD_TEST2);
mmStart (MOD_TEST2, MM_PLAY_LOOP);
The above version behaves as expected. Then I wraped the calls in a minimal class like this:

Code: Select all

class SoundModule
{
public:
    SoundModule()
    {
    }

    ~SoundModule() { }

    int GetId () const
    {
        return _id;
    }

    void Load (const int id)
    {
        _id = id;
        mmLoad (id);
    }

    void Unload ()
    {
        mmUnload (_id);
    }

    void Play ()
    {
        mmStart(_id, MM_PLAY_LOOP);
    }

    void Stop ()
    {
        mmStop();
    }

protected:
    int _id;
};


// Later in the code
SoundModule* sound1 = new SoundModule;
sound1->Load (MOD_TEST1);
sound1->Play();

// And some seconds later
sound1->Stop();
sound1->Unload();
sound1->Load (MOD_TEST2);
sound1->Play();
That version also works fine, but if I make any method virtual, the first time the sound will be played, but later I get the following error "Stopping channel 4 due to zero length". Am I doing something wrong in here?

Re: Playback stops

Posted: Wed Sep 15, 2010 6:12 am
by zeromus
The casual reader might be interested in the fact that "Stopping channel 4 due to zero length" is a desmume error message.

I think the virtual functions are just a red herring. Humor me and try something: add a swiWaitForVblank() call between every single maxmod function call and see if that fixes it.