# Abnormal sound when using FMOD\_OPENUSER

**URL:** <https://qa.fmod.com/t/abnormal-sound-when-using-fmod-openuser/21621>\
**Category:** FMOD Engine\
**Created:** [May 14, 2024, 6:54am UTC](https://qa.fmod.com/t/abnormal-sound-when-using-fmod-openuser/21621 "2024-05-14T06:54:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![xrf\_ks](https://avatars.discourse-cdn.com/v4/letter/x/e68b1a/32.png) [@xrf\_ks](https://qa.fmod.com/u/xrf_ks)\
**Post date:** [May 14, 2024, 6:54am UTC](https://qa.fmod.com/t/abnormal-sound-when-using-fmod-openuser/21621/1 "2024-05-14T06:54:37Z")

</div>

I want to make a case of using fmod as a component instead of using fmod as an engine and then implement the engine operation control by myself.  
I referred to the sample user\_created\_sound.cpp and used FMOD\_OPENUSER to create a user-defined sound as input, but the sound I got always had a slight “whisper” sound. By saving the dsp of pcm, the audio waveform obtained is as shown in the figure. The waveform protrudes without warning and has no frequency support:

 ![Dingtalk_20240514133627](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/d/d2e9f436d3c0709eb0633332154d42296544e168.jpeg)

If you zoom in on the waveform again, you will find that there are abnormal protrusions at the two sampling points before 14.240 seconds. The frame length I used is 40ms/frame. The position of 14.240 seconds is exactly an integer multiple of 40ms. (I wanted to post a screenshot, but new users can only upload one.)

When viewing the stack of the demo, two threads appear “FMOD stream thread” and “FMOD mixer thread”.  
If you do not use FMOD\_OPENUSER to create a stream but use an audio file to create a stream, there are also two threads “FMOD mixer thread” and “FMOD stream thread”, and one thread “FMOD file thread”. At this time, there is no problem with the listening effect, it is a normal effect.

The following is my demo code:

```auto
#include <fstream>
#include <iostream>

#include <fmod.hpp>
#include <fmod_errors.h>

#ifdef _WIN64
    #ifndef _DEBUG
        #pragma comment(lib, "fmod_vc.lib")
    #else
        #pragma comment(lib, "fmodL_vc.lib")
    #endif // _DEBUG
#endif // _WIN64

static std::ifstream* soundFile = new std::ifstream();

int main()
{
    const int kMaxChannelCount = 32;
    FMOD::System* system = nullptr;
    FMOD::Sound* sound = nullptr;
    FMOD::Channel* channel = nullptr;
    FMOD_RESULT nResult = FMOD_OK;
    nResult = FMOD::System_Create(&system);
    nResult = system->init(kMaxChannelCount, FMOD_INIT_NORMAL, nullptr);

    soundFile->open("LISA-16k.pcm", std::ios::binary);

    FMOD_CREATESOUNDEXINFO tFmodCreateSoundExInfo;
    std::memset(&tFmodCreateSoundExInfo, 0, sizeof(tFmodCreateSoundExInfo));
    tFmodCreateSoundExInfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
    tFmodCreateSoundExInfo.numchannels = 1;
    tFmodCreateSoundExInfo.defaultfrequency = 16000;
    tFmodCreateSoundExInfo.decodebuffersize = 640;
    tFmodCreateSoundExInfo.length = -1;
    tFmodCreateSoundExInfo.format = FMOD_SOUND_FORMAT_PCM16;
    tFmodCreateSoundExInfo.pcmreadcallback = [](FMOD_SOUND* pSound, void* pData, unsigned int nDataLen) -> FMOD_RESULT {
        std::cout << "read data " << nDataLen << std::endl;
        unsigned int read = 0;
        //auto ret = soundFile->readData(pData, nDataLen, &read);
        soundFile->read((char*)pData, nDataLen);
        if (soundFile->gcount() != nDataLen) {
            memset(pData, 0, nDataLen);
        }
        return FMOD_OK;
    };
    tFmodCreateSoundExInfo.userdata = nullptr;

    FMOD::ChannelGroup* channelGroup = nullptr;
    FMOD::Sound* pSound = nullptr;

    // Note: User flows created using FMOD_OPENUSER will experience abnormal noises
    // If the mode is set to FMOD_LOOP_NORMAL, the effect will be even more different.
    system->createStream(nullptr, FMOD_OPENUSER /*| FMOD_LOOP_NORMAL*/, &tFmodCreateSoundExInfo, &pSound);
    // Note: This method can achieve normal sound effects
    //system->createStream("good.mp3", FMOD_LOOP_NORMAL, nullptr, &pSound);

    system->createChannelGroup("test", &channelGroup);
    system->playSound(pSound, channelGroup, true, &channel);

    channel->setPaused(false);
    system->update();

    while (true) {
        bool isPlaying = false;
        channel->isPlaying(&isPlaying);
        if (!isPlaying) {
            std::cout << "play end" << std::endl;
            break;
        }
    }
    std::cout << "play completed" << std::endl;

    return 0;
}

```

---

<div class="post-metadata">

**Author:** ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)\
**Post date:** [May 15, 2024, 11:54pm UTC](https://qa.fmod.com/t/abnormal-sound-when-using-fmod-openuser/21621/2 "2024-05-15T23:54:19Z")

</div>

I think this is because your [`decodebuffersize`](https://fmod.com/docs/2.02/api/core-api-system.html#fmod_createsoundexinfo_decodebuffersize) is too small. Small stream buffer sizes can cause buffer starvation, leading to stuttering. More information on this issue can be found in the [Stream | Streaming Issues](https://fmod.com/docs/2.02/api/glossary.html#streaming-issues) section of our API documentation.

I think the reason this isn’t occurring with your “good.mp3” file is that the [system default buffer size](https://fmod.com/docs/2.02/api/core-api-system.html#fmod_advancedsettings_defaultdecodebuffersize) of 400ms is being used, which is much larger than the 640 samples (~14ms) buffer size you are explicitly setting in your exinfo. A buffer size of `19200` should give you the same 400ms buffer size that “good.mp3” has.

Can you please try setting a larger `decodebuffersize` and let me know if that eliminates the signal discontinuities?

---

<div class="post-metadata">

**Author:** ![xrf\_ks](https://avatars.discourse-cdn.com/v4/letter/x/e68b1a/32.png) [@xrf\_ks](https://qa.fmod.com/u/xrf_ks)\
**Post date:** [May 16, 2024, 1:30pm UTC](https://qa.fmod.com/t/abnormal-sound-when-using-fmod-openuser/21621/3 "2024-05-16T13:30:42Z")

</div>

Thanks for the guidance!  
I have tried decoding buffersize with large memory, but I want to use it in real-time scenarios. It is best to process the amount of data that needs to be accumulated to be the same as the size passed from the upstream.  
I use `FMOD_OPENUSER`, `FMOD_OUTPUTTYPE_NOSOUND_NRT` and `system->update()` to achieve external control needs.

---

<div class="post-metadata">

**Author:** ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)\
**Post date:** [May 17, 2024, 5:56am UTC](https://qa.fmod.com/t/abnormal-sound-when-using-fmod-openuser/21621/4 "2024-05-17T05:56:54Z")

</div>

I can see how a buffer size of 400ms would be too much latency for you. 14ms is definitely too small because it is only slightly larger than our mixer update speed of 10ms, so you are likely to get stream stuttering with a buffer of this size.  
Generally a latency of 50ms is sufficient for real time purposes, so perhaps a buffer size of `1920` would suit your needs better?
