简体   繁体   English

板球音频。 在播放许多CkSound效果时,最好调用销毁CkSound吗?

[英]Cricket Audio. While playing many CkSound effects, best to call destroy CkSound?

Using the Cricket Audio Sound Engine ( ios & android) how would I set up a machine gun type sound effect. 使用板球音频声音引擎 (ios&android),我将如何设置机枪式声音效果。 I need to be able to play many instances of a sound per second. 我需要每秒能够播放许多声音实例。 The sound effects need to layer on top of each other. 声音效果需要彼此叠加。

My solution is to create a new CkSound instance and forget about it. 我的解决方案是创建一个新的CkSound实例,然后忽略它。 I don't see a easy to destroy the sound, with out a complex sound tracking method. 如果没有复杂的声音跟踪方法,我认为很难消除声音。 Will this cause memory problems as I am creating thousands of CkSounds over the course of a play session? 在游戏过程中创建数千个CkSounds时,这会导致内存问题吗? I really don't want to have to keep track of individual sounds for garbage collection. 我真的不想跟踪垃圾收集的各个声音。

// Example sound effect call
void SoundManager::playEffect(const char* name){
    // I make a sound , play it , and forget about it
    sound = CkSound::newBankSound(g_bank, name);
    sound->play();
}

I don't recommend you create instances and don't destroy them, as this is a memory leak, so your app will use more and more memory as time goes on. 我不建议您创建实例并且不要破坏它们,因为这是内存泄漏,因此随着时间的流逝,您的应用程序将使用越来越多的内存。

You could try something like this… 您可以尝试这样的事情……

to initialize: 初始化:

const int k_maxSounds = 5; // maximum number of sound instances to be playing at once
CkSound* g_sounds[k_maxSounds];
for (int i = 0; i < k_maxSounds; ++i)
{
   g_sounds[i] = CkSound::newBankSound(g_bank, name);
}

to play another sound instance, find the first available instance and play it: 要播放另一个声音实例,请找到第一个可用实例并进行播放:

for (int i = 0; i < k_maxSounds; ++i)
{
   if (!g_sounds[i]->isPlaying())
   {
      g_sounds[i]->play();
      break;
   }
}

-steve - Cricket Audio Creator answered via email -steve- 板球音频创建者通过电子邮件答复

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM