Previous: Accumulator, Up: MarSystem composites


6.3.5 Shredder

A Shredder composite MarSystem does the inverse to what an Accumulator does. While an Accumulator builds up a realvec containing the results from multiple ticks, a Shredder splits this realvec into multiple chunks, effectively increasing the rate at which data is output.

A toy example of using both a Shredder and an Accumulator together would look something like:

     MarSystem* net = mng.create("Series", "net");
     MarSystem* acc = mng.create("Accumulator", "acc");
     MarSystem* shred = mng.create("Shredder", "shred");
     
     acc->addMarSystem(mng.create("SoundFileSource", "src"));
     net->addMarSystem(acc);
     shred->addMarSystem(mng.create("AudioSink", "dest"));
     net->addMarSystem(shred);
     
     net->updctrl("Accumulator/acc/SoundFileSource/src/mrs_string/filename", sfName);
     net->updctrl("Shredder/shred/AudioSink/dest/mrs_bool/initAudio", true);
     
     net->updctrl("mrs_natural/inSamples", 256);
     
     net->updctrl("Accumulator/acc/mrs_natural/nTimes", 10);
     net->updctrl("Shredder/shred/mrs_natural/nTimes", 10);

In the above example, an Accumulator is added first to a global Series network, and then a Shredder is added to this Series. A SoundFileSource is then added to the Accumulator, and an AudioSink is added to the Shredder. The nTimes control of both the Shredder and Accumulator are then set to 10.

This network would read in data from the SoundFileSource, and the Accumulator would build up a buffer of 10 chunks of this audio. The Shredder would then take these 10 slices of audio data and would split them back into 10 chunks, which would then be output to the AudioSource.

This whole procedure would be akin to buffering a section of audio 10 times the size of the number of samples that were input. So, since we set the inSamples of the network to 256, the number of samples output by the Acccumulator would be 2560.