Flint Particle System Forum - ParticleFactory with sound spectrum Sat, 25 Dec 2010 18:49:49 +0000 http://flintparticles.org/forum/ Lussumo Vanilla 1.1.10 & Feed Publisher ParticleFactory with sound spectrum http://flintparticles.org/forum/comments.php?DiscussionID=58&Focus=269#Comment_269 http://flintparticles.org/forum/comments.php?DiscussionID=58&Focus=269#Comment_269 Thu, 24 Jul 2008 17:31:58 +0100 icd2k3
Basically what I'm trying to do is tie in the sound spectrum to a particle generator, so every frame 256 values are calculated and based on the value the program will decide spawn a particle or not. So basic structure:

Enter Frame {
for(var i:uint=0; i<256; i++) {
soundVar
spawn Particle based on soundVar
}
}

any help would be greatly appreciated, thanks! ]]>
ParticleFactory with sound spectrum http://flintparticles.org/forum/comments.php?DiscussionID=58&Focus=271#Comment_271 http://flintparticles.org/forum/comments.php?DiscussionID=58&Focus=271#Comment_271 Fri, 25 Jul 2008 11:51:12 +0100 Richard
The particle factory is used internally by the Emitter. It just manages the reuse of particles which speeds up the system.

It sounds like what you're after is developing a custom Counter. Each frame, the counter tells the emitter how many particles to create.

Your custom counter needs to implement the Counter interface, which means it has two methods - startEmitter and updateEmitter. startEmitter is called once, when the emitter starts, and updateEmitter is called every frame while the emitter is running. Each method returns a uint to indicate to the emitter how many particles to create at this time. So in your custom counter, startEmitter would return 0 and updateEmitter would calculate how many particles to spawn based on the sound spectrum and return that value. ]]>
ParticleFactory with sound spectrum http://flintparticles.org/forum/comments.php?DiscussionID=58&Focus=275#Comment_275 http://flintparticles.org/forum/comments.php?DiscussionID=58&Focus=275#Comment_275 Fri, 25 Jul 2008 20:20:30 +0100 icd2k3
Just to clarify, you mean using something like Steady.as as a starting point and modifying it for my idea correct?

Your dedication to this class is insane, I really want to understand it from top to bottom ]]>
ParticleFactory with sound spectrum http://flintparticles.org/forum/comments.php?DiscussionID=58&Focus=276#Comment_276 http://flintparticles.org/forum/comments.php?DiscussionID=58&Focus=276#Comment_276 Fri, 25 Jul 2008 21:52:42 +0100 icd2k3
public function updateEmitter( emitter:Emitter, time:Number ):uint
{
if( _stop ) { return 0; }
SoundMixer.computeSpectrum(ba, false);
var count:uint = 0;
for(var i:uint=0; i<256; i++) {
var baNum:Number = ba.readFloat()*200+200;
++count;
// adjust each particle based on baNum
}
return count;
}

I've tried things like: emitter.particles[i].energy = baNum; but I guess I'm just not familiar with how it handles things. Thanks again for any help/direction ]]>
ParticleFactory with sound spectrum http://flintparticles.org/forum/comments.php?DiscussionID=58&Focus=277#Comment_277 http://flintparticles.org/forum/comments.php?DiscussionID=58&Focus=277#Comment_277 Fri, 25 Jul 2008 22:00:22 +0100 icd2k3 ParticleFactory with sound spectrum http://flintparticles.org/forum/comments.php?DiscussionID=58&Focus=280#Comment_280 http://flintparticles.org/forum/comments.php?DiscussionID=58&Focus=280#Comment_280 Sun, 27 Jul 2008 20:19:13 +0100 Richard
The counter simply tells the emitter how many particles to create. The emitter then creates all the particles and initializes them in turn by passing each particle to each initializer so the initializer can set its properties.

If you're going to create 256 particles every frame, as you seem to be doing above, then your counter can simply be

public function updateEmitter( emitter:Emitter, time:Number ):uint
{
if( _stop ) { return 0; }
return 256;
}


Then do the compute spectrum in a custom initializer to initialize each particle. You will probably need a static property or two in the initializer to track what's going on from one call to the next. Perhaps just a static ByteArray, which you check in the initialize and if it's empty do another compute spectrum. Then remove a float from the front of the ByteArray and use it each time you initialize a particle. Something like this

public function initialize( emitter:Emitter, particle:Particle ):void
{
if( ba.length == 0 )
{
SoundMixer.computeSpectrum(ba, false);
}
var baNum:Number = ba.readFloat()*200+200;
// adjust particle based on baNum
}


N.B. I haven't tested this at all. ]]>