Skip to content
This repository was archived by the owner on Feb 11, 2022. It is now read-only.

AllocationTest

cardin edited this page Jun 23, 2011 · 3 revisions

This guide is based on the MP3GaplessTest demo that's in \test\BasicTest\src\AllocationTest.as
The compiled application can be found at http://cardin.github.com/SeiON/v0.3.0/demos/AllocationTest.html

Aim of Demo:

  • Showcase how quickly SeiON can manage sounds
  • Demonstrates group-level control of sounds
  • Defines the limits placed by not having enough allocations

Useful Sources:

  • Understanding SeiON - On the differences of having an autodisposable sound, and what allocations mean

Creating the Sound Objects

To keep things varied, and also to ensure the different simultaneously playing sounds would be discernible, we're using many different MP3 clips today. Here we're embedding them as Sound() objects. You might notice some discrepancies amongst the variables that we used (or didn't use) for the objects - these will be explained in a moment.

		// Retrieved from http://www.jazzhouseblues.com/
		[Embed(source = '../lib/Muffin Man Swing.mp3')]
		private var sndJazz_cls:Class;
		private var sndJazz:Sound = new sndJazz_cls() as Sound;
		private var sndJazz_SC:SeionClip;
		
		// Retrieved from http://ccmixter.org/files/hansatom/31743
		// Licensed under Creative Commons Attribution Noncommercial (3.0)
		[Embed(source = '../lib/hansatom_-_Inferno_is_a_place_on_earth [edit].mp3')]
		private var sndRock_cls:Class;
		private var sndRock:Sound = new sndRock_cls() as Sound;
		private var sndRock_SC:SeionClip;
		
		// Retrieved from http://ccmixter.org/files/unreal_dm/31740
		// Licensed under Creative Commons Attribution Noncommercial (3.0)
		[Embed(source='../lib/unreal_dm_-_Everything_I_Ever_Want [edit].mp3')]
		private var sndJazz2_cls:Class;
		private var sndJazz2:Sound = new sndJazz2_cls() as Sound;
		private var sndJazz2_SC:SeionClip;
		
		// Retrieved from http://soundcloud.com/andremichelle/void-panic
		[Embed(source = '../lib/void panic.mp3')]
		private var sndLoop:Sound = new sndLoop_cls() as Sound;
		private var sndLoop_SC:SeionSample;
		
		[Embed(source = '../lib/snd_ring.mp3')]
		private var sndRing_cls:Class;
		private var sndRing:Sound = new sndRing_cls() as Sound;
		
		[Embed(source='../lib/snd_rollover.mp3')]
		private var sndRoll_cls:Class;
		private var sndRoll:Sound = new sndRoll_cls() as Sound;

Categories and SeionGroups

There's about 3 different categories of clips here. The first is the ringing and rolling sounds which are UI sounds. Because they are UI sounds, we think they'll be appropriate as autodisposable sounds that we don't need to maintain control over. Hence they don't have their own SeionClip variable.

Next is the void panic loop. As a sound loop, we need to have gapless mP3 looping so we settled for a SeionSample instead of a SeionClip for sndLoop_SC.

The final category are BG sounds. They're fairly long clips (~25 seconds), as background sounds should be.

These categories are expressed as SeionGroup instances, one for each category. This allows us to organise logical group-level control over the sound clips. The amount of allocations chosen for each SeionGroup was decided based on how they would be able to demonstrate SeiON's allocation ability. In practical scenarios, one might have partitioned the allocations differently.

		private var sgRing:SeionGroup;
		private var sgMisc:SeionGroup;
		private var sgBG:SeionGroup;
		// ...
		sgRing = Seion.createSeionGroup("Ring", 10);
		sgMisc = Seion.createSeionGroup("Misc + UI", 2);
		sgBG = Seion.createSeionGroup("Background", 2);
		// spare allocations = 18

Spamming Rings

The first demo objective is to stress-test SeiON's allocation ability. Although ringing sounds are UI sounds, in this demo, we chose not to include it under UI, but under a separate category. We will spam-create ringing sounds to stress-test SeiON's ability to handle a large amount of object instantiation with limited allocations.

This is done by having a boolean flag triggerRing keep track of the user's decision to start the spamming test. If triggered, an event listener will instantiate a ringing sound for every frame of the movie. The constructor states that such a clip will belong to the SeionGroup sgRing, sourced from the Sound object sndRing, play only once without looping, and be an autodisposable sound.

			container.root.addEventListener(Event.ENTER_FRAME, update_stats);
			//...
			private function update_stats(e:Event):void
			{
				// ...
				if (triggerRing)
					SeionClip.create("", sgRing, sndRing, 0, true);
			}

Note

If you try to create an autodisposable sound with infinite looping, the static constructor will throw an error. After all, since autodisposable sounds have no reference returned, you cannot control the clip, and such a clip would be a runaway sound.

How SeiON handles the spamming


The ringing sound is handled by the SeionGroup sgRing which only has 10 allocations. Yet when you run the demo, you see sgRing chalking up beyond 10 allocations, and hovers around ~14. What happens is that sgRing is borrowing allocations from the Seion master class. This is allowed as Seion still has plenty of unused allocations (~18) and the ringing sound was defined as an autodisposable sound. After all, autodisposable sounds are allowed to borrow up to the spare capacity of Seion. Of course, they are in their own way rather disadvantaged too, which is detailed in Understanding SeiON.

Even though we are creating the ringing sounds are such a rapid rate, the ringing sound is short enough that it finishes playing quickly in time that SeiON is not overwhelmed with insufficient allocations. As an autodisposable sound, the sound instantly is cleared from SeiON's memory upon finishing. Hence the allocation value for sgRing consistently hovers around 14/10.

Controlling Group-level Volume/Panning

The next objective of the demo is to show group-level control of volume and panning. This one is pretty straightforward actually.

		ISeionControl(this[name]).volume = vol;
		ISeionControl(this[name]).pan = pan;

If a SeionClip/SeionSample's vol/pan was set, it would just affect itself. If a SeionGroup's was set, it would propagate down to all the clips under its control. We use ISeionControl for convenience's sake, since all of them inherit from ISeionControl.

Playing Without Allocations

The final demonstration shows the problem of relying on non-autodisposable sounds, and not having allocated enough slots for the affected SeionGroup. The category sgBG is the manager for 3 different sounds: sndJazz, sndJazz2 and sndRock. Yet we only allocated 3 slots for sgBG, so it's not going to be enough to play all three sounds simultaneously.

Indeed, when we try to play a third BG sound in the demo, it refuses to play. This highlights the importance of properly planning how many allocations to ration out. In addition, it emphasises the constraints placed on non-autodisposable sounds. While such sounds are controllable and will not be prematurely disposed, once the allocation is full you'd not be able to play any more of them indefinitely.

Clone this wiki locally