Csound Csound-dev Csound-tekno Search About

[Cs-dev] f Statement manual page

Date2012-02-21 11:14
Frompeiman khosravi
Subject[Cs-dev] f Statement manual page
AttachmentsNone  None  
Hello,

This is really confusing me! Is it saying that when table size is a power of two then an additional index is automatically added to provide the guard point? So table size is always going to be power of two + 1?

One confusion is that the first sentence starts with "For arrays whose length is a power of 2" and the second sentence contains "if size is an exact power of 2". So what is the difference between power of two and an exact power of two? Why is 'size' italicised here?

Also what is meant by extending the contour of the function? As in continuing in the same direction beyond index N-1?    

Thanks

Peiman

For arrays whose length is a power of 2, space allocation always provides for 2n points plus an additional guard point. The guard point value, used during interpolated lookup, can be automatically set to reflect the table's purpose: If size is an exact power of 2, the guard point will be a copy of the first point; this is appropriate for interpolated wrap-around lookup as in oscili, etc., and should even be used for non-interpolating oscil for safe consistency. If size is set to 2 n + 1, the guard point value automatically extends the contour of table values; this is appropriate for single-scan functions such in envplx, oscil1, oscil1i, etc.

The size of the table is used as a code to tell Csound how to fill this guard-point. If the size is exactly power-of-two, then the guard point contains a copy of the first point on the table. If the size is power-of-two plus one, Csound will extend the contour of the function stored in the table for one extra point.



Date2012-02-21 11:21
FromAdam Puckett
SubjectRe: [Cs-dev] f Statement manual page
Peiman,

Size means the number you write as the fourth argument of the f
statement. For example:

f1 0 4096 10 1

is a table whose size is an exact power of two. Replacing 4096 with
4097 will make the table have a size of a power of two plus one.

I'm not sure, however, what "contour" is. I'll have a look at fgens.c
and get back to you if you like.

Hope this helps,

Adam

On 2/21/12, peiman khosravi  wrote:
> Hello,
>
> This is really confusing me! Is it saying that when table size is a power
> of two then an additional index is automatically added to provide the guard
> point? So table size is always going to be power of two + 1?
>
> One confusion is that the first sentence starts with "For arrays whose
> length is a power of 2" and the second sentence contains "if *size* is an
> exact power of 2". So what is the difference between power of two and an
> exact power of two? Why is 'size' *italicised* here?
>
> Also what is meant by extending the contour of the function? As in
> continuing in the same direction beyond index N-1?
>
> Thanks
>
> Peiman
>
> For arrays whose length is a power of 2, space allocation always provides
>> for 2n points plus an additional *guard point*. The guard point value,
>> used during interpolated lookup, can be automatically set to reflect the
>> table's purpose: If *size* is an exact power of 2, the guard point will
>> be a copy of the first point; this is appropriate for *interpolated
>> wrap-around lookup* as in *oscili*, etc., and should even be used for
>> non-interpolating *oscil* for safe consistency. If *size* is set to 2 n +
>> 1, the guard point value automatically extends the contour of table
>> values;
>> this is appropriate for single-scan functions such in *envplx*, *oscil1*,
>> *oscil1i*, etc.
>>
>> The size of the table is used as a code to tell Csound how to fill this
>> guard-point. If the size is exactly power-of-two, then the guard point
>> contains a copy of the first point on the table. If the size is
>> power-of-two plus one, Csound will extend the contour of the function
>> stored in the table for one extra point.
>>
>

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2012-02-21 11:36
Frompeiman khosravi
SubjectRe: [Cs-dev] f Statement manual page
AttachmentsNone  None  
Hi Adam,

On 21 February 2012 11:21, Adam Puckett <adotsdothmusic@gmail.com> wrote:
Peiman,

Size means the number you write as the fourth argument of the f
statement. For example: 

Yes understand this but why is it italicised in the manual? (just nitpicking here!)
 

f1 0 4096 10 1

is a table whose size is an exact power of two. Replacing 4096 with
4097 will make the table have a size of a power of two plus one.

But my question is, is this done automatically? (replacing the table size with power of two + 1 that is). That's what the manual seems to suggest.

Thanks

Peiman
 
I'm not sure, however, what "contour" is. I'll have a look at fgens.c
and get back to you if you like.

Hope this helps,

Adam

On 2/21/12, peiman khosravi <peimankhosravi@gmail.com> wrote:
> Hello,
>
> This is really confusing me! Is it saying that when table size is a power
> of two then an additional index is automatically added to provide the guard
> point? So table size is always going to be power of two + 1?
>
> One confusion is that the first sentence starts with "For arrays whose
> length is a power of 2" and the second sentence contains "if *size* is an
> exact power of 2". So what is the difference between power of two and an
> exact power of two? Why is 'size' *italicised* here?
>
> Also what is meant by extending the contour of the function? As in
> continuing in the same direction beyond index N-1?
>
> Thanks
>
> Peiman
>
> For arrays whose length is a power of 2, space allocation always provides
>> for 2n points plus an additional *guard point*. The guard point value,
>> used during interpolated lookup, can be automatically set to reflect the
>> table's purpose: If *size* is an exact power of 2, the guard point will
>> be a copy of the first point; this is appropriate for *interpolated
>> wrap-around lookup* as in *oscili*, etc., and should even be used for
>> non-interpolating *oscil* for safe consistency. If *size* is set to 2 n +
>> 1, the guard point value automatically extends the contour of table
>> values;
>> this is appropriate for single-scan functions such in *envplx*, *oscil1*,
>> *oscil1i*, etc.
>>
>> The size of the table is used as a code to tell Csound how to fill this
>> guard-point. If the size is exactly power-of-two, then the guard point
>> contains a copy of the first point on the table. If the size is
>> power-of-two plus one, Csound will extend the contour of the function
>> stored in the table for one extra point.
>>
>

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel


Date2012-02-21 12:08
FromRichard Dobson
SubjectRe: [Cs-dev] f Statement manual page
Actually, you have pretty much got it.

On 21/02/2012 11:14, peiman khosravi wrote:
> Hello,
>
> This is really confusing me! Is it saying that when table size is a
> power of two then an additional index is automatically added to provide
> the guard point? So table size is always going to be power of two + 1?
>

Yes. Or rather, now that we have arbitrary-sized tables too, the cases 
of a power of two size or power of two plus 1 are "special" (unless they 
have themselves been subverted by the changes).


> One confusion is that the first sentence starts with "For arrays whose
> length is a power of 2"


This should perhaps more precisely (but more verbosely) say:

"For arrays whose length is specified as a power of two or a power of 
two plus 1..."

and the second sentence contains "if /size/ is
> an exact power of 2". So what is the difference between power of two and
> an exact power of two? Why is 'size' /italicised/ here?
>

Because there it is referring to the GEN "size" argument name, rather 
than its ordinary semantic meaning.


> Also what is meant by extending the contour of the function? As in
> continuing in the same direction beyond index N-1?
>

Yes.


For the sake of  (a) further interest and (b) more sales(!): I put  a 
standalone example of the Csound ftable oscili code  in the Audio 
Programming Book (DVD Chapter 3); but only considering the periodic 
waveform lookup with interpolation, not the single-shot usage, which I 
guess you could say was left as the proverbial exercise. The "guard 
point" idea is by no means confined to Csound, and in one form or 
another is very widely used in audio dsp, especially in hardware dsp 
systems. For higher-order interpolation (cubic, etc), multiple guard 
points are used, and there are even situations where a lookup table is 
basically drawn twice, so the number of guard points is the same as the 
nominal size of the table. It is all in the cause of speed, avoiding 
lots of conditional tests per sample. With a single oscillator you will 
not notice the difference, but with 512 of them you will!


Richard Dobson



------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2012-02-21 12:24
Frompeiman khosravi
SubjectRe: [Cs-dev] f Statement manual page
AttachmentsNone  None  
Thanks Richard,

On 21 February 2012 12:08, Richard Dobson <richarddobson@blueyonder.co.uk> wrote:
Actually, you have pretty much got it.

On 21/02/2012 11:14, peiman khosravi wrote:
> Hello,
>
> This is really confusing me! Is it saying that when table size is a
> power of two then an additional index is automatically added to provide
> the guard point? So table size is always going to be power of two + 1?
>

Yes. Or rather, now that we have arbitrary-sized tables too, the cases
of a power of two size or power of two plus 1 are "special" (unless they
have themselves been subverted by the changes).


So just to be really clear if one defines table size as a power-of-two then it will be automatically extended by one guard point? In this case returning the table size in the orchestra would still return the defined power-of-two size but internally the table is processed as power-of-two+1?

Then using tab_i with ixmode 1 and a table size of power-of-two should not return an error because of that internally added guard point. I'm sure I'm missing something here!      
 

> One confusion is that the first sentence starts with "For arrays whose
> length is a power of 2"


This should perhaps more precisely (but more verbosely) say:

"For arrays whose length is specified as a power of two or a power of
two plus 1..."

and the second sentence contains "if /size/ is
> an exact power of 2". So what is the difference between power of two and
> an exact power of two? Why is 'size' /italicised/ here?
>

Because there it is referring to the GEN "size" argument name, rather
than its ordinary semantic meaning.

Yes I see. I hadn't noticed that!

> Also what is meant by extending the contour of the function? As in
> continuing in the same direction beyond index N-1?
>

Yes.


For the sake of  (a) further interest and (b) more sales(!): I put  a
standalone example of the Csound ftable oscili code  in the Audio
Programming Book (DVD Chapter 3); but only considering the periodic
waveform lookup with interpolation, not the single-shot usage, which I
guess you could say was left as the proverbial exercise. The "guard
point" idea is by no means confined to Csound, and in one form or
another is very widely used in audio dsp, especially in hardware dsp
systems. For higher-order interpolation (cubic, etc), multiple guard
points are used, and there are even situations where a lookup table is
basically drawn twice, so the number of guard points is the same as the
nominal size of the table. It is all in the cause of speed, avoiding
lots of conditional tests per sample. With a single oscillator you will
not notice the difference, but with 512 of them you will!



I have the book and it's going to be my summer read! Really looking forward to it.

Best,

Peiman
Richard Dobson



------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel


Date2012-02-21 13:02
FromRichard Dobson
SubjectRe: [Cs-dev] f Statement manual page
On 21/02/2012 12:24, peiman khosravi wrote:
..
> So just to be really clear if one defines table size as a power-of-two
> then it will be automatically extended by one guard point? In this case
> returning the table size in the orchestra would still return the defined
> power-of-two size but internally the table is processed as power-of-two+1?
>

Yes. But we do have to be careful - the guard-point is (I think) 
strictly an internal construct (e.g. assumes oscili rather than oscil, 
etc), rather than  sometning that should or could be directly addressed 
by an instrument.


> Then using tab_i with ixmode 1 and a table size of power-of-two should
> not return an error because of that internally added guard point. I'm
> sure I'm missing something here!
>

I would have to look at the code to see exactly what is done, but I 
would expect it to return an error, as that extra position is really 
internal; and even more so with arbitrary-length tables, the behaviour 
needs to be consietent across all cases. From my recollection, the 
orchestra itself does not know in what mode the table has been 
constructed (it just assumes the table has been appropriately 
specified). In any situation where the table is intended to be periodic 
(guard point is a copy of the first point), asking for it explicitly is 
logically/strategically equivalent to asking for the first point. This 
is a case where we are, for better or worse, exposed to the underlying 
implementation perhaps a little too generously! The only globally safe 
default position is, in the orchestra, to treat all tables (etc) as 
indexed from 0 to size-1, and then just leave Csound to do its clever 
thing behind the scenes. Anything else is arguably a "hack" with, in the 
usual way of such things, "undefined' results.

Richard Dobson





------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2012-02-21 19:22
Frompeiman khosravi
SubjectRe: [Cs-dev] f Statement manual page
AttachmentsNone  None  
Thanks for the explanation Richard. It all makes sense now.

It may be a good idea for us to put some of these points in the manual.

Best,

Peiman

On 21 February 2012 13:02, Richard Dobson <richarddobson@blueyonder.co.uk> wrote:
On 21/02/2012 12:24, peiman khosravi wrote:
..
> So just to be really clear if one defines table size as a power-of-two
> then it will be automatically extended by one guard point? In this case
> returning the table size in the orchestra would still return the defined
> power-of-two size but internally the table is processed as power-of-two+1?
>

Yes. But we do have to be careful - the guard-point is (I think)
strictly an internal construct (e.g. assumes oscili rather than oscil,
etc), rather than  sometning that should or could be directly addressed
by an instrument.


> Then using tab_i with ixmode 1 and a table size of power-of-two should
> not return an error because of that internally added guard point. I'm
> sure I'm missing something here!
>

I would have to look at the code to see exactly what is done, but I
would expect it to return an error, as that extra position is really
internal; and even more so with arbitrary-length tables, the behaviour
needs to be consietent across all cases. From my recollection, the
orchestra itself does not know in what mode the table has been
constructed (it just assumes the table has been appropriately
specified). In any situation where the table is intended to be periodic
(guard point is a copy of the first point), asking for it explicitly is
logically/strategically equivalent to asking for the first point. This
is a case where we are, for better or worse, exposed to the underlying
implementation perhaps a little too generously! The only globally safe
default position is, in the orchestra, to treat all tables (etc) as
indexed from 0 to size-1, and then just leave Csound to do its clever
thing behind the scenes. Anything else is arguably a "hack" with, in the
usual way of such things, "undefined' results.

Richard Dobson





------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel