SAMPL Project Report Mike Glass Mike Haskel Navarun Jagatpal Morgan Rhodes May 7 2007 Contents 1 Introduction and Motivation 1 1 Introduction 1 2 Functional 1 3 Strictly Typed 1 4 Control Flow 1 5 Possible Applications 3 3 3 4 4 5 2 Tutorial 6 2 1 Hello world 6 2 2 Functions 6 2 2 1 Higher order functions Currying and partial application 7 2 3 Operators and types other than intensity 7 2 3 1 Constants 8 2 4 Useful functions and an example program 8 3 Manual 3 1 Lexical Conventions 3 1 1 Identifiers 3 1 2 Keywords 3 1 3 Numbers 3 2 Behavior of Generated Programs 3 3 Expressions 3 3 1 Types 3 3 2 Values 3 3 3 Unit Values 3 4 Definitions 3 4 1 Interpretation of Definitions 3 4 2 Type specifiers 1 10 10 10 10 11 11 11 12 12 12 13 13 14 3 5 Notation of Expressions 3 5 1 Conditional Expressions 3 5 2 Operators 3 5 3 Function Application 3 5 4 Atoms 4 Project Plan 4 1 Development overview 4 2 Programming style 4 3 Roles and responsibilities 4 4 Software environment 4 5 Timeline and log 14 14 15 17 17 19 19 19 20 20 21 5 Architectural Design 23 6 Test Plan 6 1 Testing overview 6 2 Test details 6 2 1 Syntax tests 6 2 2 Semantic tests 6 3 Role in development 6 4 Demonstrative examples 25 25 25 25 26 26 26 7 Lessons Learned 28 7 1 Mike Haskel s lessons 28 7 2 Morgan s lessons 28 7 3 Mike Glass lessons 29 A Code listing A 1 Build system A 2 Antlr grammar A 3 Java sources A 3 1 Package helper A 3 2 Package testing A 4 Test cases 2 30 30 31 46 46 53 62 Chapter 1 Introduction and Motivation SAMPL is a simple functional strictly typed potentially platform independent translated high performance signal processing language 1 1 Introduction SAMPL is a language used for signal and music processing It produces programs that take in audio streams as input and outputs the modified audio stream along with text output SAMPL also allows for the sampling of the audio file to be transparent to the user with the user defining desired behavior for the program and the actual loop for the sampling happening in the background As a program designed for the processing of music it has domain specific types SAMPL has primitive types including time frequency and intensity along with string and integer types SAMPL has the potential for platform independence as it will be translated to C Possible applications of SAMPL are as simple as frequency filters effects such as reverb and as complex as identifying and filtering a particular instrument 1 2 Functional SAMPL is a functional programming language in which programs define the output stream in terms of various operations on the input stream Programs consist of a series of recursive definitions The language provides functions for sampling the input stream such as 3 frequency 200 hz rmsvolume 5 sec i e samples of the input which vary over time and highpass 400hz stream i e functions for mutating streams to produce other streams 1 3 Strictly Typed SAMPL is strictly typed providing types directly related to signal processing such as frequency time and intensity It also provides string and integer types Programs specify values of these types by specifying units as in 300 hz 20 rad or 50 3 sec The language supports basic operations such as comparing adding or scaling values of a given type and provides functions for converting between types in meaningful ways such as frequency time 1 4 Control Flow One of the key features of SAMPL is that the process of scanning and sampling input is transparent to the user Ordinarily a program for signal processing would need to implement a tight loop which encapsulates the process of reading the input and updating state as necessary This process is conceptually distinct from the specification of the audio transformations and users shouldn t need to implement it To accommodate this SAMPL implements this loop in the background and a program s control flow is based upon constructs for applying filters when certain conditions hold Such constructs include if then else which takes on a different value depending on some condition as in if rmsvolume 5 sec 75 lfs lowpass 5000hz input else input end which applies a low pass filter to the input when and only when the input is sufficiently loud 4 These control structures limit the layers of indirection between the programs and their intended effects 1 5 Possible Applications SAMPL has a number of possible applications ranging from simple to complex processing tasks Simple applications in SAMPL will allow low or high pass filters to be applied to the stream outputting the filtered stream Another application will be applying reverb to the input stream These applications can be made more complex in applying a high pass filter whenever a there is a frequency lower than a specified frequency and apply reverb only when the intensity exceeds a certain value SAMPL will also make it possible to write applications to recognize particular instruments which will make it possible to filter out the flute or only filter out the flute while there is a trumpet playing Programs generated by the SAMPL compiler are themselves inherently modular as users can easily pipe output from one program to another 5 Chapter 2 Tutorial 2 1 Hello world SAMPL programs like programs in other functional languages consist of a sequence of definitions Our equivalent of a hello world program is one which defines the output equal to the input without modification let intensity output input The let keyword signifies a new definition intensity output is what we are defining that is a term output whose value is an intensity which varies over time output is a special term in that the program s output stream takes on its value The output term must always have type intensity Other possible types in general are scalar frequency angle time and boolean On the right hand side of the we define that the value of output should be equal to the value of the term input input is a built in term representing the input stream 2 2 Functions In SAMPL one can define terms which take arguments functions For example consider this program let intensity halve intensity x x 2 let intensity output halve input comments are C style multi line comments 6 intensity halve again denotes a term halve with values of type intensity intensity x denotes a formal parameter x also of type intensity halve is a function from intensities to intensities SAMPL is a pure language in that functions may not have side effects beyond specifying an output value 2 2 1 Higher order functions
View Full Document
Unlocking...