Csound6: Old Code Renewed
Total Page:16
File Type:pdf, Size:1020Kb
View metadata, citation and similar papers at core.ac.uk brought to you by CORE provided by MURAL - Maynooth University Research Archive Library Csound6: old code renewed John FITCH and Victor LAZZARINI and Steven YI Department of Music National University of Ireland Maynooth, Ireland, fjpff@codemist.co.uk, [email protected], [email protected] Abstract Miller, 1964]. Following the introduction of This paper describes the current status of the de- the PDP-11 minicomputer, a modified version velopment of a new major version of Csound. We of the software appeared as MUSIC 11[Vercoe, begin by introducing the software and its historical 1981]. Later, with the availability of C (and significance. We then detail the important aspects UNIX), this program was re-written in that lan- of Csound 5 and the motivation for version 6. Fol- guage as Csound[Boulanger, 2000], allowing a lowing, this we discuss the changes to the software simpler cycle of development and portability, in that have already been implemented. The final sec- comparison to its predecessor. tion explores the expected developments prior to the first release and the planned additions that will be The system, in its first released version, em- coming on stream in later updates of the system. bodied a largely successful attempt at provid- ing a cross-platform program for sound syn- Keywords thesis and signal processing. Csound was then Music Programming Languages, Sound Synthesis, adopted by a large development community in Audio Signal Processing the mid 90s, after being translated into the ANSI C standard by John ffitch in the early 1 Introduction half of the decade. In the early 2000s, the final In March 2012, a decision was taken to move releases of version 4 attempted to retrofit an ap- the development of Csound from version 5 to plication programming interface (API), so that a new major version, 6. This meant that most the system could be used as a library. of the major changes and improvements to the 1.1.2 Csound 5 software would cease to be made in Csound The need for the further development of the 5, and while new versions would be released, Csound API, as well as other innovations, these will consist mainly of bug fixes and mi- prompted a code freeze and a complete overhaul nor changes (possibly including new opcodes). of the system into version 5[ffitch, 2005]. Much Moving to a new version allowed developers to of this development included updating 1970s rethink key aspects of the system, without the programming practices by applying more mod- requirement of keeping ABI or API compatibil- ern standards. One of the major aims was to ity with earlier iterations. The only restriction, make the code reentrant, so that its use as a li- which is a fundamental one for Csound, is to brary could be made more robust. In 2006, ver- provide backwards language compatibility, en- sion 5.00 was released. The developments em- suring that music composed with the software bodied by this and subsequent releases allowed will continue to be preserved. a varied use of the software, with a number of This paper describes the motivation for the third-party projects benefitting from them. changes, current state of development and prospective plans for the system. 1.2 Csound operation in a nutshell As a MUSIC-N language, Csound incorporates 1.1 Short History of Csound a compiler for instruments. During perfor- 1.1.1 Early History mance, these can be activated (instantiated) by Csound has had a long history of development, various means, the traditional one being the which can be traced back to Barry Vercoe's standard numeric score. In Csound 5, compi- MUSIC 360[Vercoe, 1973] package for computer lation can only be done once per performance music, which was itself a variant of Max Math- run, so new instruments cannot be added to ews' and Joan Miller's MUSIC IV[Mathews and an already running engine (for this performance needs to be interrupted so the compilation can of older components (such as the old parser), take place). and a reorganisation of the API. It was also an The steps involved in the compiler can be opportunity to code-walk, and with that find divided into two: parsing, and compilation inconsistencies and bugs that would normally proper. The first creates an abstract syntax tree be hidden. In particular, changes related to re- (AST) representing the instruments. The com- peated loading and compilation of new instru- pilation then creates data structures in memory ments would require (and indeed force) a wel- that correspond to the AST. When an instru- come separation of language and synthesis en- ment is instantiated, an init-pass loop is per- gine, which is well underway at present. formed, executing all the once-off operations for that instance. This is then inserted in a list of 3 Developments to date active instruments, and its performance code is 3.1 Build System and Tests executed sequentially, processing vectors (audio In Csound 5, the official build system is SCons1. signals), scalars (control signals) or frames of Over time, a CMake-based2 build was intro- spectral data. The list orders instruments by duced and used for local developer use, as well ascending number, so higher-order ones will al- as later for Debian packaging and iOS builds. ways be executed last. All of the key aspects of In Csound 6, the official build system is now Csound operation are exposed by the API. the CMake-based build. Moving to CMake in- 2 Motivation troduced some hurdles and changes in workflow, but it also brought with it generation of build In the six years since its release, Csound 5 con- system files, such as Makefiles, XCode projects, tinued to develop in many ways, mostly in re- and Eclipse projects. This solved a problem of sponse to user needs, as well as providing fur- IDE-based projects for building Csound becom- ther processing capabilities in the form of new ing out of sync with changes in the SConstruct opcodes. After a long gestation, early in 2012, file for SCons, as well as brought more ways the new flex-bison parser was completed and for developers to approach building and working added as a standard option. This was the final with Csound code, particularly through IDE's. major step of development for Csound, where Using the CTest feature in CMake, unit and the last big chunk of 1970s code, the old ad- functional tests have been added to Csound 6's hoc parser, was replaced by a modern, main- codebase. CTest is the test running utility used tainable, and extendable parser. Following the to execute the individual C-code tests. In ad- 2011 Csound Conference in Hannover, it was dition, CUnit3 is employed to create the indi- clear that there were a number of user requests vidual tests and test-suites within the test code that would be more easily achievable with a re- files. In addition to C-code testing, the suite think of the system. Such suggestions included: of CSD's used for application/integration test- ing continues to grow, and a new set of Python • the capacity of new orchestra code, tests has also been added for testing API usage ie. instruments and user-defined opcodes from a host language. (UDOs), to be added to a running instance of the engine 3.2 Code reorganisation • additions to the orchestra language, for in- The Csound code base is passing through a sig- stance, generic arrays nificant reorganisation. Firstly, parts of it that are now obsolete, such as the old parser, have • rationalisation of the API to allow further been removed. Some opcodes with special li- features in frontends censing conditions that have been deemed not • loadable binary formats, API construction to be conducive to further development have of instruments been completely rewritten (also with some ef- ficiency and generality improvements). The • further development of parallelism CSOUND struct has been rationalised and re- • facilities for live coding organised, with many modifications due to the various changes outlined in the next sections. The time was ripe for major changes to be 1http://www.scons.org made. User suggestions prompted developers to 2http://www.cmake.org begin an internal cleanup of code, the removal 3http://cunit.sourceforge.net Finally, the public API is going through a re- and csoundCompileTree(), as well as by the design process (details of which are discussed addition of a general csoundStart() function below). to get the engine going. The parsing function creates an abstract syntax tree (AST) from a 3.3 Type system string containing Csound code. The compi- The Csound Orchestra language uses strongly lation function then creates the internal data typed variables and enforces these at compile- structures that the AST represents, ready for time. This type information is used to deter- engine instantiation(see figure 1). mine the size of memory to allocate for a vari- able as well as for specifying the in- and out- arg types for opcodes. The system of types used prior to Csound 6 was hard-coded into the parser and compiler. Adding new types would require adding code in many places. In Csound 6, a generic type system was imple- mented as well as tracking of variable names to types. The new system provides a mechanism to create and handle types, such that new types can be easily added to the language. The sys- tem also helps clarify how types are used during compilation. Another feature is that variable definitions and types were previously discarded after compile-time; in Csound 6, this informa- tion is kept after compilation.