[chuck-users] Sample Playback Efficiency

Spencer Salazar ssalazar at CS.Princeton.EDU
Tue Nov 27 02:15:04 EST 2007

If efficiency is what you are looking for, use the => and =< approach.

You can tell a Ugen to stop processing samples and only output 0  
(using 0 => ugen.op;), which saves a lot of CPU cycles over setting  
the gain to 0.  Any ugens chucked to the op-0 ugen will still be  
ticked though, so for long ugen chains this is less likely to gain you  
much in performance.

In addition to stopping it from processing samples, removing a ugen  
from the graph entirely with =< reduces the overhead of moving each  
sample to the next ugen in the graph, which is noticeable.  It also  
has the (generally desirable) side effect of automatically stopping  
any ugens further down the graph from producing samples (assuming they  
aren't connected to some other active ugen).

(All of these approaches are prone to produce pops in your resulting  
audio--use an Envelope if this is a problem!)

My recommendation is to use the approach that makes the most sense to  
you; opt for a more efficient strategy only if you've identified this  
as a bottleneck.


On Nov 26, 2007, at 3:07 PM, Juan-Pablo Caceres wrote:

> Dear list,
> Lets say I have an array of SndBuf, and I want to playback one of the
> samples each time. What is the most efficient way? What I am doing is
> just connecting everything to dac, and then setting all but one of the
> gains to non-zero, something like this:
> SndBuf buf[20];
> for ( 0 => int i; i < 20; i++ )  {
>         sample_names[i] => buf[i].read; //assuming I have an array of
> 					//string names
>         buf[i] => dac;
>         0. => buf[i].gain;
>     }
> //then to playback one at the time:
> int isamp;
> while (true) {
>         Std.rand2(0, 19 ) => isamp;
> 	0 => buf[isamp].pos;
>         0.1 => buf[isamp].gain; //set gain to something different
> 				// than zero
>         200::ms => now;
>         0. => buf[isamp].gain; //bring it back to zero
>     }
> This works, but doesn't feel right. All the DSP connections are  
> made, so
> I would guess this is inefficient. The other option will be to connect
> (=>) and disconnect (=<) dynamically but that solution also feels  
> wrong...
> Any ideas? Thanks so much again,
> Juan-Pablo
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users

More information about the chuck-users mailing list