Chuck: a Concurrent, On-The-Fly, Audio Programming Language

Chuck: a Concurrent, On-The-Fly, Audio Programming Language

In Proceedings of the 2003 International Computer Music Conference. ChucK: A Concurrent, On-the-fly, Audio Programming Language Ge Wang and †Perry R. Cook Computer Science Department, †(also Music) Princeton University {gewang,prc}@cs.princeton.edu Abstract shreds and concurrency in ChucK, and demonstrate multiple and simultaneous control paths and control ChucK is a new audio programming language for rates. Section 4 presents an overview of the real-time synthesis, composition, and performance, integration of many types of input/output related which runs on commodity operating systems. ChucK devices and operations into the language. Section 5 natively supports concurrency, multiple, presents a special aspect of ChucK: its ability to be simultaneous, dynamic control rates, and the ability programmed on-the-fly during run-time. ChucK is to add, remove, and modify code, on-the-fly, while the implemented as a virtual machine running with a program is running, without stopping or restarting. special run-time compiler with low-level audio It offers composers and performers a powerful and engine. Section 6 takes a step back and reasons about flexible programming tool for building and the performance benefits/drawbacks of ChucK. experimenting with complex audio synthesis programs, and real-time interactive control. 2. The ChucK Operator 1. Ideas in ChucK ChucK is a strongly-typed, imperative programming language. Its syntax and semantics are In this paper we present four key ideas that form governed by a flexible type system. ChucK includes the foundation of ChucK. The goal is to design a standard features (arithmetic, bit-wise, memory natural audio programming language (1) to operations, etc…) and control flow mechanisms ( , concurrently and accurately represent complex audio if synthesis, (2) to enable fine-grain, flexible control for, while, switch, goto, break, continue, etc…) over time, (3) to provide the capability to operate on common to most modern imperative programming multiple, dynamic and simultaneous control rates, languages. But the heart of ChucK's syntax is based and (4) to make possible an on-the-fly style of around the ChucK operator (written as =>). programming. ChucK runs on commodity operating st systems (Linux, Windows, Solaris, MacOS). 1 rule of ChucK: make use of the left-to-right ChucK operator. => originates from the slang term Four major ideas form the basis of ChucK. "chuck", meaning to throw an entity into or at another entity. The language uses this notion to help express • A unifying, massively overloaded operator. sequential operations and data flow. • A precise timing model that is capable of true concurrency and arbitrarily fine granularity. The (440 => osc) => env => filt => audio[0]; language semantic supports multiple, The above code fragment constructs a simple simultaneous, and dynamic control rates, and synthesis instrument using a series of unit generators naturally amortizes operations over time. (Mathews 1969) (their declarations are omitted for • Native language support of arbitrarily many the moment): an oscillator, an envelope, a filter, and, input/output sources, MIDI, network, serial, finally, audio channel 0. Notice that the single line USB, graphics, and any input/output device you captures the flow of the signals from left to right - the can connect to the computer. same order as we read and type. • On-the-fly programming enables dynamically modifiable programs for performance and A ChucK statement can be composed of any experimentation. appropriate types of objects (including user-defined), unit generators, operations, values, and variables. We present ChucK with respect to these four The semantic of the statement depends on the types major facets. We provide some informal 'rules' of of the objects, and the overloading of the ChucK ChucK, each of which embodies some key aspect of operator on those types. the programming language. In Section 2, we look in detail at the ChucK operator. In Section 3, we present The main ideas behind the ChucK operator are (1) the ChucK timing model, introduce the concept of it locally captures the left-to-right nature of program 1 In Proceedings of the 2003 International Computer Music Conference. flow (with the exception of nested ChucK 5 => int x; statements), representing the order of sequential operations more faithfully, (2) it can be chained to With the ChucK operator, we represent any any arbitrary length, and (3) it reacts, or behaves, sequence of operations in a left-to-right manner. As differently depending on the types of the objects shown below, a piece of code is chucked over TCP to being chucked. =>’s behavior is defined/altered a remote host (also running ChucK), waits for a through overloading using the ChucK type system. message, and prints out the result. code_seg => tcp(140.180.141.103:8888) The basic ChucK operation takes place between => local_receiver => stdout; two entities, the ChucKer and the ChucKee: The ChucK operator can also naturally x => y synchronize on events and objects. Synchronization primitives such as semaphores, condition variables, The operation performed depends on the types of and monitors (Lampson 1980) can be inserted into x (ChucKer) and of y (ChucKee), the combination of ChucK chains as clear points of synchronization. which maps to a particular action that is overloaded on the ChucK operator. For example, it might assign code_seg => mutex => machine; the value to a variable, or connect/disconnect one unit generator to/from another, or anything depending on button[0] => play_note(); the particular overloading. For example, the notion of behavioral abstraction in Nyquist (Dannenberg In the next sections, we will look at the issues of 1997) can be realized through this type of timing and concurrency, input/output, and on-the-fly overloading =>. programming, each of which employs some aspect of the ChucK operator. The following are some sample ChucK statements, where the identifiers x, y etc. can be any 3. Time, Shreds, Rates well-typed entities. The notions of time, duration, synchronization, Binary ChucK: the simplest ChucK statement, control rates, and simultaneity are captured chucking object/value x to object/value y. automatically by ChucK’s timing mechanism. ChucK allows the programmer, composer, and x => y; performer to write truly concurrent code using the framework of the timing semantic. There is no fixed Chain ChucK: ChucK statements can be a sequence notion of control rate – the control rate is a natural of ChucK operations of arbitrary length. The product of using the timing constructs. The timing operations are performed left to right, in exactly the semantic, along with concurrency leads to the ability same order as written. to dynamically change control rate, as well as have many different control rates. w => x => y => z; 3.1 Time and Duration Nested ChucK: evaluation of ChucK expressions gives local precedence to parenthesis. In the The now keyword (of type time) is defined to always hold the exact, current ChucK time. The statement below, the operation v=>w is evaluated, keyword dur refers to the duration between points in then x=>y, and the result of v=>w is chucked to the time. These allow the programmer to do precise result of x=>y. Finally, that result is chucked to z. arithmetic with time and duration as we see in the v => w => ( x => y ) => z; following examples. Cross ChucK: cross-chucking allows one or more Each duration value has a unit attached to it and is ChucKer objects/values to be chucked to more than declared in the following way: one ChucKee. In the statement below, the object/value w is chucked to x, then y, and then z. 0.01:second => dur midi_rate; (This can also be achieved by a more verbose In the above example, we chuck a value of sequence of three ChucK statements.) 0.01:second to a newly declared variable of type w => ( x, y, z ); dur, called midi_rate. The "built-in" units are samp (duration of one sample), ms, second, minute, The ChucK programming language has no hour, day, week. We can also use any variable of assignment operator (=), but unifies this operation type dur as a unit to inductively construct other under the ChucK operator, as seen here: durations: 2 In Proceedings of the 2003 International Computer Music Conference. 0.7:second => dur quarter; responsibility for deciding when to "step out" of 4:<quarter> => dur whole; suspended animation and advance time. He/she can do it in one of two ways. In the first method (chuck- The above statement constructs a duration value to-now) the programmer can allow time to advance of 4:<quarter> (quarter defined in the previous by explicitly chucking a duration value or a time statement) and chucks a relationship (symbolized by value to now, as shown above. This allows for a the angle brackets) to a new variable called whole. In natural programming approach that embeds the this case, chucking a new dur value to quarter will timing control directly in the language, giving the automatically change whole. With this system, we programmer the ability to perform computations at can easily define and use any duration greater than or arbitrary points in time, and to "move forward" in equal to the duration of a single sample. ChucK time in a precise manner. Time is defined in terms of existing time values. The second method to advance time in ChucK is We can perform arithmetic using time and duration to by waiting on some event(s). These could be obtain new time values. Here we calculate the time synchronization mechanisms (such as mutexes, value for 10:second after now, and store this value semaphores, and/or condition variables), input in a new variable called later. devices, or any asynchronous event(s) such as MIDI input or packets arriving over TCP or UDP. 10:second after now => time later; Execution will resume when the synchronization condition is fulfilled.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    8 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us