You can refer to several attributes of objects that are visible in the List of Objects. To do so, use the type and the name of the object, connected with an underscore. Thus,
Sound_hallo refers to an existing Sound object whose name is "hallo" (if there is more than one such object, it refers to the one that was created last). You can also use the unique ID instead of the name. Thus,
Object_113 refers to the 113th object that you created in the list.
To refer to an attribute, you use the period ( `.'). Thus,
Sound_hallo.nx is the number of samples of Sound_hallo, and
1 / Sound_hallo.dx is the sampling frequency of Sound_hallo.
Record a Sound (read the Intro if you do not know how to do that), name it "mysound" (or anything else), and type the following formula into the calculator:
After you click OK, the Info window will show the number of samples. Since you could have got this result by simply choosing Get number of samples from the Query menu, these attribute tricks are not very useful in the calculator. We will see that they are much more useful in creation and modification formulas and in scripts.
The following attributes are available:
In formulas for creating a new object, you can refer to the attributes of any object, but you will often want to refer to the attributes of the object that is just being created. You can do that in two ways.
The first way is to use the name of the object, as above. Choose Create Sound from formula..., supply hello for its name, supply arbitrary values for the starting and finishing time, and type the following formula:
(x - Sound_hello.xmin) / (Sound_hello.xmax - Sound_hello.xmin)
When you edit this sound, you can see that it creates a straight line that rises from 0 to 1 within the time domain.
The formula above will also work if the Sound under creation is called goodbye, and a Sound called hello already exists; of course, in such a case
Sound_hello.xmax refers to a property of the already existing sound.
If a formula refers to an object under creation, there is a shorter way: you do not have to supply the name of the object at all, so you can simply write
(x - xmin) / (xmax - xmin)
The attributes that you can use in this implicit way are xmin, xmax, ncol, nrow, nx, dx, ny, and dy. To disambiguate in case there exists a script variable xmin as well, you can write Self.xmin.
In formulas for modifying an existing object, you refer to attributes in the same way as in creation formulas, i.e., you do not have to specify the name of the object that is being modified. The formula
self * 20 ^ (- (x - xmin) / (xmax - xmin))
causes the sound to decay exponentially in such a way that it has only 5 percent of its initial amplitude at the end. If you apply this formula to multiple Sound objects at the same time, xmax will refer to the finishing time of each Sound separately as it is modified. To disambiguate in case there exists a script variable xmin as well, you can write Self.xmin.
More examples of the use of attributes are on the next page.
© ppgb, February 25, 2007