# Fmod默认的是(指数衰减)，怎么设置线性衰减？

**URL:** <https://qa.fmod.com/t/fmod/18154>\
**Category:** FMOD Engine\
**Tags:** android\
**Created:** [December 30, 2021, 6:11am UTC](https://qa.fmod.com/t/fmod/18154 "2021-12-30T06:11:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![115452661](https://avatars.discourse-cdn.com/v4/letter/1/f08c70/32.png) [@115452661](https://qa.fmod.com/u/115452661)\
**Post date:** [December 30, 2021, 6:11am UTC](https://qa.fmod.com/t/fmod/18154/1 "2021-12-30T06:11:05Z")

</div>

大佬们，请教一个问题啊，fmod默认的是(指数衰减)，怎么设置线性衰减？setMode(FMOD\_3D\_LINEARROLLOFF);好像没有效果  
QQ：115452661

---

<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:** [December 30, 2021, 11:05pm UTC](https://qa.fmod.com/t/fmod/18154/2 "2021-12-30T23:05:32Z")

</div>

What version of FMOD are you using? `Sound::setMode(FMOD_3D_LINEARROLLOFF)` should result in linear decay. If you do not hear a difference, try setting a lower maximum distance using [`Sound::set3DMinMaxDistance`](https://fmod.com/resources/documentation-api?version=2.02&page=core-api-sound.html#sound_set3dminmaxdistance) and see if that makes the effect more noticeable.

---

<div class="post-metadata">

**Author:** ![115452661](https://avatars.discourse-cdn.com/v4/letter/1/f08c70/32.png) [@115452661](https://qa.fmod.com/u/115452661)\
**Post date:** [December 31, 2021, 2:15am UTC](https://qa.fmod.com/t/fmod/18154/3 "2021-12-31T02:15:33Z")

</div>

jeff\_fmod你好，可以留一个联系方式吗？FMOD是最新版本， 线性衰减调试总是不起作用

---

<div class="post-metadata">

**Author:** ![115452661](https://avatars.discourse-cdn.com/v4/letter/1/f08c70/32.png) [@115452661](https://qa.fmod.com/u/115452661)\
**Post date:** [December 31, 2021, 2:18am UTC](https://qa.fmod.com/t/fmod/18154/5 "2021-12-31T02:18:51Z")

</div>

代码我复制上面了。

---

<div class="post-metadata">

**Author:** ![115452661](https://avatars.discourse-cdn.com/v4/letter/1/f08c70/32.png) [@115452661](https://qa.fmod.com/u/115452661)\
**Post date:** [December 31, 2021, 2:21am UTC](https://qa.fmod.com/t/fmod/18154/7 "2021-12-31T02:21:32Z")

</div>

jeff\_fmod你好，fmode = FMOD\_3D\_LINEARROLLOFF ;默认为线性，还是不好使  
int PLAudio::play(std::string soundPath, std::string mode, std::string groupName, bool isLoop) {  
std::shared\_ptr s(new Source());  
FMOD\_MODE fmode = FMOD\_DEFAULT;  
FMOD::ChannelGroup\* cGroup = nullptr;  
FMOD\_RESULT r = FMOD\_OK;  
if (mode == “3d” || mode == “2d”){  
fmode = FMOD\_3D\_LINEARROLLOFF ;  
LOGI("-c+±PLAudio play1111");  
}else if (mode == “music”){  
fmode = FMOD\_DEFAULT;  
LOGI("-c+±PLAudio play222");  
}  
#ifdef COCOS2DX  
unsigned char\* data = 0;  
ssize\_t len = 0;  
//data = CCFileUtils::sharedFileUtils()-\>getFileData(cocos2d::CCFileUtils::sharedFileUtils()-\>fullPathForFilename(soundName.c\_str()), “r”, &len);  
data = cocos2d::FileUtils::getInstance()-\>getFileData(cocos2d::FileUtils::getInstance()-\>fullPathForFilename(soundPath.c\_str()), “r”, &len);  
FMOD\_CREATESOUNDEXINFO exinfo;  
memset(&exinfo, 0, sizeof(FMOD\_CREATESOUNDEXINFO));  
exinfo.cbsize = sizeof(FMOD\_CREATESOUNDEXINFO);  
exinfo.length = len;  
LOGI("-c+±PLAudio play2");  
r = \_fmodSys-\>createStream((const char\*)data, FMOD\_OPENMEMORY | fmode, &exinfo, &s-\>s);  
#else  
LOGI("-c+±PLAudio play3");  
r = \_fmodSys-\>createStream(soundPath.c\_str(), fmode, 0, &s-\>s);  
#endif

```
if (r != FMOD_OK)
	return 0;
s->mode = mode;
_sources[_id] = s;

if (groupName != "") {
	FMOD::ChannelGroup* masterGroup;
	_fmodSys->createChannelGroup(groupName.c_str(), &cGroup);
	_fmodSys->getMasterChannelGroup(&masterGroup);
	masterGroup->addGroup(cGroup);
	_channelGroups[groupName] = cGroup;
}
else
	_fmodSys->getMasterChannelGroup(&cGroup);

if (isLoop)
	s->s->setMode(FMOD_LOOP_NORMAL);
_fmodSys->playSound(s->s, 0, true, &s->c);
s->c->setChannelGroup(cGroup);
s->c->setPaused(false);
onUpdate();

return this->_id++;

```

}

---

<div class="post-metadata">

**Author:** ![115452661](https://avatars.discourse-cdn.com/v4/letter/1/f08c70/32.png) [@115452661](https://qa.fmod.com/u/115452661)\
**Post date:** [December 31, 2021, 2:25am UTC](https://qa.fmod.com/t/fmod/18154/8 "2021-12-31T02:25:25Z")

</div>

jeff\_fmod:请教一下，先设置setMode（FMOD\_3D\_LINEARROLLOFF），还是先设置 [`Sound：：set3DMinMaxDistance`]

---

<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:** [January 4, 2022, 6:10am UTC](https://qa.fmod.com/t/fmod/18154/9 "2022-01-04T06:10:10Z")

</div>

> [@115452661](#):
>
> 请教一下，先设置setMode（FMOD\_3D\_LINEARROLLOFF），还是先设置 [`Sound::set3DMinMaxDistance`]

Calling the functions in a different order should not change the outcome.

I suggest you try running the FMOD 3d example with the following changes around line number 40;

```cpp
    /*
        Load some sounds
    */
    result = system->createSound(Common_MediaPath("drumloop.wav"), FMOD_3D, 0, &sound1);
    ERRCHECK(result);
    result = sound1->set3DMinMaxDistance(0.5f * DISTANCEFACTOR, 20.0f * DISTANCEFACTOR); // 1. Set a lower max distance
    ERRCHECK(result);
    result = sound1->setMode(FMOD_LOOP_NORMAL | FMOD_3D_LINEARROLLOFF); // 2. Set mode to Linear Rolloff
    ERRCHECK(result);

```

That way you can hear the difference between linear and exponential roll off, and then apply it to your own project.

```cpp
...
	s->s->set3DMinMaxDistance(0.5f, 20.0f); // 1. Set a lower max distance
	if (isLoop)
		s->s->setMode(FMOD_LOOP_NORMAL | FMOD_3D_LINEARROLLOFF); // 2. Set mode to Linear Roll off

	_fmodSys->playSound(s->s, 0, true, &s->c);
	s->c->setChannelGroup(cGroup);
	s->c->setPaused(false);
	onUpdate();
...

```
