turning off looping causes a playback glitch

On OSX, when I turn off looping in the middle of a looping mp3 sound opened with CREATECOMPRESSEDSAMPLE (or CREATESTREAM) and FMOD_ACCURATETIME, I can hear a glitch in the playback at the moment it is turned off.
This does not happen with wav files.

I found my issue. When turning off / on looping, I was doing the following as per the documentation when streaming sounds to flush.

unsigned int position;
this->mChannel->getPosition (&position, FMOD_TIMEUNIT_MS );
this->mChannel->setPosition (position, FMOD_TIMEUNIT_MS );

Are there special consideration to take when streaming sounds ?

-s

just to be sure, do you call setMode(FMOD_LOOP_OFF) ? As i said before, doing that actually does nothing if you’re in the middle of the sound. What sort of glitch are you talking about?

Yes I call that on the channel.
You can hear the sound skipping for a few milli seconds. Enough to notice a beat skip when it’s drums.

I really can’t see how a call to setMode which just sets a flag could have anything to do with stalling the mixer so that it stutters.
I would suspect something else being called at the same time that i dont know about here, which happens to coincide with your call to setMode.

I have modified the play_sound example to make the drumloop wav loop by default, then you press 4 to turn off looping. Let me know if the behaviour reproduces with the change below to FMOD_Main

int FMOD_Main()
{
    FMOD::System     *system;
    FMOD::Sound      *sound1, *sound2, *sound3;
    FMOD::Channel    *channel = 0;
    FMOD_RESULT       result;
    unsigned int      version;
    void             *extradriverdata = 0;
    
    Common_Init(&extradriverdata);

    /*
        Create a System object and initialize
    */
    result = FMOD::System_Create(&system);
    ERRCHECK(result);

    result = system->getVersion(&version);
    ERRCHECK(result);

    if (version < FMOD_VERSION)
    {
        Common_Fatal("FMOD lib version %08x doesn't match header version %08x", version, FMOD_VERSION);
    }

    result = system->init(32, FMOD_INIT_NORMAL, extradriverdata);
    ERRCHECK(result);

    result = system->createSound(Common_MediaPath("drumloop.wav"), FMOD_LOOP_NORMAL, 0, &sound1);
    ERRCHECK(result);

    //result = sound1->setMode(FMOD_LOOP_OFF);    /* drumloop.wav has embedded loop points which automatically makes looping turn on, */
    //ERRCHECK(result);                           /* so turn it off here.  We could have also just put FMOD_LOOP_OFF in the above CreateSound call. */

    result = system->createSound(Common_MediaPath("jaguar.wav"), FMOD_DEFAULT, 0, &sound2);
    ERRCHECK(result);

    result = system->createSound(Common_MediaPath("swish.wav"), FMOD_DEFAULT, 0, &sound3);
    ERRCHECK(result);

    /*
        Main loop
    */
    do
    {
        Common_Update();

        if (Common_BtnPress(BTN_ACTION1))
        {
            result = system->playSound(sound1, 0, false, &channel);
            ERRCHECK(result);
        }

        if (Common_BtnPress(BTN_ACTION2))
        {
            result = system->playSound(sound2, 0, false, &channel);
            ERRCHECK(result);
        }

        if (Common_BtnPress(BTN_ACTION3))
        {
            result = system->playSound(sound3, 0, false, &channel);
            ERRCHECK(result);
        }
        if (Common_BtnPress(BTN_ACTION4))
        {
            result = channel->setMode(FMOD_LOOP_OFF);
            ERRCHECK(result);
        }

        result = system->update();
        ERRCHECK(result);

        {
            unsigned int ms = 0;
            unsigned int lenms = 0;
            bool         playing = 0;
            bool         paused = 0;
            int          channelsplaying = 0;

            if (channel)
            {
                FMOD::Sound *currentsound = 0;

                result = channel->isPlaying(&playing);
                if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
                {
                    ERRCHECK(result);
                }

                result = channel->getPaused(&paused);
                if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
                {
                    ERRCHECK(result);
                }

                result = channel->getPosition(&ms, FMOD_TIMEUNIT_MS);
                if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
                {
                    ERRCHECK(result);
                }
               
                channel->getCurrentSound(&currentsound);
                if (currentsound)
                {
                    result = currentsound->getLength(&lenms, FMOD_TIMEUNIT_MS);
                    if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
                    {
                        ERRCHECK(result);
                    }
                }
            }

            system->getChannelsPlaying(&channelsplaying);

            Common_Draw("==================================================");
            Common_Draw("Play Sound Example.");
            Common_Draw("Copyright (c) Firelight Technologies 2004-2014.");
            Common_Draw("==================================================");
            Common_Draw("");
            Common_Draw("Press %s to play a mono sound (drumloop)", Common_BtnStr(BTN_ACTION1));
            Common_Draw("Press %s to play a mono sound (jaguar)", Common_BtnStr(BTN_ACTION2));
            Common_Draw("Press %s to play a stereo sound (swish)", Common_BtnStr(BTN_ACTION3));
            Common_Draw("Press %s to turn off looping for drumloop", Common_BtnStr(BTN_ACTION4));
            Common_Draw("Press %s to quit", Common_BtnStr(BTN_QUIT));
            Common_Draw("");
            Common_Draw("Time %02d:%02d:%02d/%02d:%02d:%02d : %s", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped");
            Common_Draw("Channels Playing %d", channelsplaying);
        }

        Common_Sleep(50);
    } while (!Common_BtnPress(BTN_QUIT));

    /*
        Shut down
    */
    result = sound1->release();
    ERRCHECK(result);
    result = sound2->release();
    ERRCHECK(result);
    result = sound3->release();
    ERRCHECK(result);
    result = system->close();
    ERRCHECK(result);
    result = system->release();
    ERRCHECK(result);

    Common_Close();

    return 0;
}

do you mean you hear a glitch as soon as you issue the setMode command? Considering this does nothing but set a flag for the next time the sound reaches its end point, i would find this very surprising.

If not, does your sound have silence at the end then a lot of signal at the start? (so its not actually a smoothly looping sample). If you dont load a sound as one shot, but load it as looping, the sound can be prepared internally to read past the end of the sound and not click when it loops. It depends on the sound, but if it is a sound that doesnt actually loop, then without re-preparing the sound to be one shot, there might be a small click as the resampler interpolates past the end of the sound.

The sound is a looping sound with no silence. The glitch happens in the middle of the sound not at the end and immediately when the mode is changed.
It’s on OSX 10.9. The problem does not happen with wav files. It happens with mp3 files when opened with FMOD_CREATECOMPRESSEDSAMPLE.