| Thanks for your thoughts.
You are correct that any well-written Csound program will not depend
on a particular value of ksmps, so it can simply be set congruent with
Jack. Of course, this assumes that the Csound user will know about
this optimization and do this work.
In fact, if we write a csoundjack program that uses the API as Victor
suggests, then that program can interrogate Jack for the buffer size
and override ksmps to that value or something suitable.
Regards,
Mike
On 8/21/09, Fons Adriaensen wrote:
> On Thu, Aug 20, 2009 at 07:49:03PM -0400, michael.gogins@gmail.com wrote:
>
>> It's not necessary to use intermediate buffers to get Csound to work as
>> Jack
>> is designed to work.
>>
>> Csound's Jack driver can be modified to work as the CsoundVST::process
>> function already works (VST hosts call back for audio as Jack does). It's
>> identical to your proposed design, except that the Csound output buffer
>> (spout) and the Jack callback buffer may be different sizes. The Jack
>> driver
>> needs two buffer indexes that persist across Jack callbacks, that's all.
>> Every time the Csound spout buffer index gets to the end of the spout
>> buffer, the Jack driver calls csoundPerformKsmps and resets the spout
>> buffer
>> index to 0. Every time the Jack buffer index gets to the end of the Jack
>> buffer, the Jack callback resets the Jack buffer index to 0 and returns.
>> Otherwise, the Jack callback just increments both indexes and copies the
>> respective frames from spout to the Jack buffer in a loop.
>
> It is exactly that which can make Csound into a badly behaved
> Jack app. How bad it gets depends on the ratio of Jack's period
> size (P) and the one which is used by Csound (K, probably K ==
> ksmps).
>
> 1. K == P, no problem and no buffering needed.
>
> 2. K > P. This is one of the bad cases. The ratio could
> be integer or not, it doesn't matter much. As an example
> assume K = 4 * P. Csound's process function will be called
> every fourth Jack callback. Assume the average load by
> Csound is 20%, so if Csound would process P samples on
> each callback it would consume 20% of each period, and
> leave 80% to other audio apps. If Csound runs only every
> forth period it takes 80% of that period, leaving just
> 20% to other clients. That is leaves 100% to others during
> the three skipped periods doesn't help - the other app have
> to complete their work during the current period, so they
> can't take more the 20%.
>
> Of course this works if you consider only Csound and
> disregard all the rest (*). But that is not how a well-
> behaved Jack app is supposed to work.
>
> For possible solutions to this see below.
>
> 3. K < P. In this case all depends on the ratio r = P/K.
> If this is an integer there is no problem, you just call
> Csound's process that number of times in each callback.
> If it is not integer, let n = floor(r). This situation
> will require either n or n+1 calls in each period, and
> a relatively small amount of extra buffering. If n is
> large enough (say n >= 5) the load imbalance is tolerable,
> and this should just work. For small n, we get a situation
> similar to (2) but less extreme.
>
>
> Possible solutions to (2).
>
> The same problem occurs in apps that have to perform
> e.g. large FFT's or any other algorithm that requires
> large block sizes for efficiency.
> One example of these is Jconv (convolution engine using
> mixed partition sizes). It performs a small part of the
> work at Jack's period size P, and the rest using period
> sizes 2^k * P; there can be up to five such levels.
>
> The rules to make this work, and to allow multiple apps
> doing the same to be scheduled fairly, are simple:
>
> A. The processing done for period size 2^k * P is done
> in a thread that has priority -k w.r.t. to Jack's
> thread. In other words the priority is decreased by
> one for each doubling of the period size.
>
> B. The callback does never wait for work done at lower
> priotiry to be ready. If it isn't ready when the next
> period of that size is started, then the expected
> output is replaced by silence, and skipped when it
> arrives later. If this happens too many times in a
> row it means the system is overloaded, and in that
> case the app should quit rather than freeze the
> machine.
>
> So, to be a well-behaved Jack client Csound should
> either
>
> - Limit the allowed values of ksmps to Jack's period
> or an integer divider of it, and exclude larger
> values.
> As far as I can tell any well-written Csound program
> should not depend on any exact value of ksmps (it will
> be a power of 2 anyway), and should still be working
> correctly if ksmps is decreased.
>
> - Or implement the kind of multi-threaded, multi-priority
> scheme pointed out above.
>
> - Or change its internal design so it can use a period
> size that is different from ksmps without generating
> large irregular CPU loads. Csound will of course always
> have a load that fluctuates depending on the number of
> active notes, grains, etc., but that is no excuse to
> make it even worse.
>
> (*) A tendency do to that is one aspect of seeing Jack
> as just 'a soundcard'.
>
> --
> FA
>
> Io lo dico sempre: l'Italia è troppo stretta e lunga.
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus
> on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now. http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel
>
--
Michael Gogins
Irreducible Productions
http://www.michael-gogins.com
Michael dot Gogins at gmail dot com
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net |