Fmod Repeating Behavior


(Ayesha) #1

Hi

Im using FMOD to play RTP packets. Everything works fine but when RTP packets stop FMOD keeps playing the last packet/buffer over and over again until we stop the FMOD session manually. Can I get rid of this looping behavior?? Setting I’ve used are:

         systemHeadPhone.init(100, FMOD_INIT_NORMAL, null);

         exinfo = FMOD_CREATESOUNDEXINFO.allocate();
         exinfo.setNumChannels(1);
         exinfo.setFormat(FMOD_SOUND_FORMAT_PCM16);
         exinfo.setDefaultFrequency(SAMPLE_RATE); //8000
         exinfo.setLength(FMOD_FRAME_SIZE_IN_BYTES * FMOD_FRAMES_IN_SOUND); //1280*2

         errorCheck(system.createSound((String) null, FMOD_2D | FMOD_OPENUSER | FMOD_SOFTWARE | FMOD_LOOP_NORMAL, exinfo, sound));
         errorCheck(system.playSound(FMOD_CHANNEL_FREE, sound, false, channel));




     playFunction{
       lastPosHeadPhone = lastPlayPositionHeadPhone;
        if (channel != null)
        {

            errorcheck(channel.getPosition(currentPositionHeadPhone, FMOD_TIMEUNIT_PCM));                
            errorCheck(sound.getLength(soundLHeadPhone, FMOD_TIMEUNIT_PCM));
            currPosHeadPhone = currentPositionHeadPhone.get(0);
            soundLengthHeadPhone = soundLHeadPhone.get(0);
            currPosHeadPhone -= currPosHeadPhone % (FMOD_FRAME_SIZE_IN_BYTES / sampleSizeHP);
            if (currPosHeadPhone != lastPosHeadPhone)
            {
                blockLengthHeadphone = currPosHeadPhone - lastPosHeadPhone;
                if (blockLengthHeadphone < 0)
                {
                    blockLengthHeadphone += soundLengthHeadPhone;
                }
                errorCheck(sound.lock(lastPosHeadPhone * sampleSizeHP, blockLengthHeadphone * sampleSizeHP, ptr1Headphone, ptr2Headphone, len1Headphone, len2Headphone),);
                 inputStreamHeadPhone.read(bufHP);

                if (ptr1Headphone[0] != null && len1Headphone.get(0) > 0)
                {
                    ptr1Headphone[0].put(bufHP);
                }
                if (ptr2Headphone[0] != null && len2Headphone.get(0) > 0)
                {
                    ptr2Headphone[0].put(bufHP);
                }
                errorCheck(sound.unlock(ptr1Headphone[0], ptr2Headphone[0], len1Headphone.get(0), len2Headphone.get(0)));
                
            }
            lastPlayPositionHeadPhone = currPosHeadPhone;

}


(リチャード清水) #2

Hi Ayesha,

From the look of your code, you are looping an FMOD Sound and feeding audio (RTP packets) into it. So once the RTP packets stop, the loop will just keep looping the last bits of audio fed into this Sound. This is the expected behaviour.

You will need to place some more logic into your code to detect when the RTP packets have stopped and and either feed silence into the Sound or mute it.

I hope this has helped.

Thanks,
Richard


(Ayesha) #3

Hi Richard,

Thank you for your response.
Isn’t there any other way to control this behavior from FMOD?


(リチャード清水) #4

Hi Ayesha,

You can use createStream instead of createSound, however this will require you to rewrite the rest of the code to fit it. FMOD sounds are meant to be static but the way you have it set up currently is fine. As mentioned earlier, the only thing needed is to feed in silence once the RTP packets have stopped coming in.


(Ayesha) #5

Hi Richard,

Thank you for your response. I tried your approach and did mute the sound on silence detection, It worked fine.
Can you kindly send me sample code for createStream that works in RTP scenario?

Thank you.


(リチャード清水) #6

Hi Ayesha,

Unfortunately we are pressed for time with upcoming releases so we cannot provide sample code for you. Please read through our stream documentation and check out the playStream example project in our low-level API for more information.

Thanks,
Richard