SoundObject - something that can be assigned to a variable in a mut program Entry - something that can be put into a VoiceSet, Table or Sequence Scalar - a (possibly complex) Number, Time or Frequency Rational - int/unsigned Double - double Sample - a (possibly complex) Sample, Waveform or Filter (a continuous, Number-valued function indexed by Number, Time or Frequency respectively) ImplicitSample - definied implicitly SineSample TriangleSample SquareSample SawtoothSample NoiseSample ExplicitSample - defined explicitly Table VoiceSet Sequence ParseTreeObject StatementSequence Statement AssignmentStatement ExpressionStatement LValue Items in a Function: Extent (unit and time scale factor) Domain offset (time shift) Range scale (volume) i = (-1)^(1/2) ft[x] = x@i ift[x] = x@(-i) convolve[x][y] = ift(ft[x]*ft[y]) delta = ft[1] shift[x][t] = convolve[x][sineWave@(i*t)] = ((x@i)*(sineWave@t))@(-i) Types: * Number * Potential * Frequency * Hz * Time * s * Sample == function from Number (0..1) to Voltage, conceptually. May be stored as a frequency-domain function. * sine * square * triangle * sawtooth * whiteNoise * Waveform (a Sample at a particular frequency) * % == output from previous voice * Sequence * Sequence * Sequence * Sequence * VoiceSet * VoiceSet * VoiceSet * VoiceSet * Table * Table * Table * Table Operators: () parentheses {} embedded statement ^ power (RTL) - unary negative + unary positive @ time-scale * multiplication / division + addition - subtraction & next-voice | next-in-sequence = assignment [] function evaluation/composition ~ next-channel % unary sequence outer All symbols: !"#$%^&'()*+,-./:;<=>?@[\]^_`{|}~ _ is interpreted as alphabetic . is used for decimal points , is used to delimit function arguments ; is used to delimit statements " is used to delimit strings Unused: !#$':<>?\` Built-ins: last = the current output from the previous voice (ring modulation) division = the increment given by | outputWave outputWaveRate outputWaveBits outputWaveChannels pcSpeaker pitCycle minPotential maxPotential voices amplitudeBaked frequencyBaked outputSimulatedWave outputSimulatedWaveRate outputSimulatedWaveBits outputSimulatedWaveChannels outputPCSpeakerBin outputPCSpeakerScore outputPCSpeakerSampleBank squareWavesOnly allowRingModulation sampleSize sampleBankSize sine square triangle sawtooth whiteNoise tau +-*/^@ .SVT . .SVT S SSTT V VTVT T TTTT | .SVT . SSTT S SSTT V TTTT T TTTT & .SVT . VTVT S TTTT V VTVT T TTTT +- Number Frequency Time Sample Waveform Number Number ! ! ! ! Frequency ! Frequency ! ! ! Time ! ! Time ! ! Sample ! ! ! Sample ! Waveform ! ! ! ! Waveform * Number Frequency Time Sample Waveform Number Number Frequency Time Sample Waveform Frequency Frequency ! Number ! ! Time Time Number ! ! ! Sample Sample ! ! Sample ! Waveform Waveform ! ! ! Waveform / Number Frequency Time Sample Waveform Number Number Frequency Time Sample Waveform Frequency Time Number ! ! ! Time Frequency ! Number ! ! Sample Sample ! ! Sample ! Waveform Waveform ! ! ! Waveform ^ Number Frequency Time Sample Waveform Number Number ? ? Sample Waveform Frequency ! ! ! ! ! Time ! ! ! ! ! Sample Sample ! ! Sample ! Waveform Waveform ! ! ! Waveform @ Number Frequency Time Sample Waveform Number ! ! ! Sample Waveform Frequency ! ! ! Waveform ! Time ! ! ! ! Sample Sample ! ! ! ! ! Waveform ! ! ! ! ! | Number Frequency Time Sample Waveform Number SNumber ! ! ! ! Frequency ! SFrequency ! ! ! Time ! ! STime ! ! Sample ! ! ! SSample ! Waveform ! ! ! ! SWaveform & Number Frequency Time Sample Waveform Number VNumber ! ! ! ! Frequency ! VFrequency ! ! ! Time ! ! VTime ! ! Sample ! ! ! VSample ! Waveform ! ! ! ! VWaveform * Envelope == function from Number to Number Envelope adsr(Time t) { if (t < at) { return t*ar; } if (t < dt + at) { return t*at- ... } ... } Actually implement as a Waveform which is point-multiplied by the Waveform you want to envelope We would like to be able to have an instrument consisting of a function for the pure sound and a function for the envelope Time-scaling would stretch the pure sound function but not the envelope This could be done by having * (and @, + etc.) stay in unevaluated form if the domain units differ 1) Time scaling would only affect the left component of such a construct 2) Time scaling does not affect an object if doing so would take its domain unit outside {-1, 0, 1}. Is there a use for any other domain units? - possibly (though could always remove the units and do the same operations on dimensionless quantities). 3) Time scaling a compound object only affects the lowest dimensioned component (when increasing the dimension) or the highest (when decreasing) Same thing can work for frequency adjustments like vibrato (sample + waveform)*(sample + waveform) = sample + waveform*sample + sample*waveform + waveform @frequency = waveform Can find derivative of a function by multiplying by linear and taking the FT Waveform @ Number yields Waveform Sample @ Number yields Sample Sample @ Frequency yields Waveform Waveform @ Time yields Sample All Numbers kept as Rational internally until they get too big, at which point we switch to double. Have a way of defining variables in a particular voice, We need @ as well as * because given a Waveform we want to be able to adjust its pitch and amplitude Waveform w; w*2 // double volume w@2 // double frequency Similarly with a Sample: Sample s; s*2 // double volume s@2 // double frequency Given "Sample s" and "Frequency f" should s*f be synonymous to s@f? % is the current output from the previous voice (a Waveform) Make this a reserved word instead to avoid confusion with the sequence outer operator? . is just a variable (conventionally per voice) which is pronounced "default" and is generally used as the sample for that voice. It would be nice to be able to redefine variables right in the grid: {.=sine;} .@C2 Inside {} you can have statements inside an expression (no value, just side effects) Make Sample*Sample do pointwise multiplication (ring modulation) Make Waveform*Waveform do pointwise multiplication Make Sample^Sample do convolution Or not, pointwise power would be more regular - (a^b)(z) == integral(x=-inf..inf, a(x)*b(z-x)) So we can convolve a waveform with another waveform It would be nice to be able to create filters (e.g. low-pass, high-pass, bandpass) We could generate filter waveforms directly, but it would be nice to be able to express them in the frequency domain If we consider a Sample==Number->Number and Waveform==Time->Number then Filter==Frequency->Number So we can make filters by using (e.g.) Sample Have an FFT operator ~ Sample and Waveform are conceptually continuous valued and repeating Therefore the output of ~ on one of these gives a discrete function (distribution) of infinite extent Since the time-reversal operator is @-1, we could make the Fourier Transform operator @((-1)^(1/2)) Can also make chirps this way Does @2 have a different meaning in the LCT sense than the meaning we're giving it? No - time-scaling is a perfectly good LCT How can we efficiently do fractional fourier transformations? http://www.chronowake.com/frft.pdf suggests we can do it by multiplying by a chirp before and after the FFT (see section 6.5) Also see (20) on page 36 of the same PDF? (Or is that a different definition?) Should we also use @ instead of ^ for convolution? Implementation of @: Don't use http://www.cisl.ucar.edu/css/staff/pauls/papers/FFFT/mscpt.pdf - it's about a different Fractional Fourier Transform q:\info\The Fractional Fourier Transform and Its Applications.ppt Need a shift operator shift(x) which is a delta function at offset x. Convolve this with a Sample (or @Hz version for Waveform) to apply a time shift Need a data type for a distribution Can actually generate this by doing an FFT of a sine Do all computations internally with complex numbers, just take the real part when outputting sine is actually exp(i*x). What are the imaginary parts of square, triangle, sawtooth and whiteNoise? Also want to leave space for a stereo operator, maybe %% Sample%%Number or Waveform%%Number puts it on the left channel (-1), right channel (+1), center (0) or somewhere else along the real line No - just have a separate output for each channel. Doesn't use up an operator, is more flexible and generalizes to any number of channels. It would be nice if Samples, Waveforms, etc. were vector-valued so that they could encode stereo position Would need a way to extract/combine channels to do positional manipulation - maybe use ~ which works a bit like & but which doesn't decay Suppose we have a = sine; { a = square; } &; output = a &; // The a here means the one in voice 0, i.e. square a = sine; { & { a = triangle; } } &; output = { c = d & { b = a; } ; } c &; // The a here means the one in voice 0`1, i.e. triangle? Or a new voice, meaning only one level is transferred over {}? - the latter seems hard to understand Generalized Samples can be finite (repeating) or infinite Therefore instead of indexing by 0..1 we should index by 0..extent (where extent may be infinite) Do we want -infinity..infinity for infinite functions? A distribution is a (multiple) derivative of a continuous function I think the number of discontinuities in the first derivative must be countable, since if you can't isolate them then the original function won't be continuous We should probably be able to get away with enumerated discontinuities So it's a continuous function plus a sum of delta functions, each one of which may be differentiated any number of times and scaled. So a discontinuity is: int order; // 1 for delta, N for derivative of N-1 Complex scale; // scale factor Scalar position; Don't forget there's a factor of (-1)^order when convolving with function to yield Nth derivative of function We want to evaluate waveforms, samples and filters lazily so that we can work out what resolution we need them at However, we also have (functions and) | requires knowing the current value of division division must be a scalar - we currently don't have any way of getting a number from a waveform so we can evaluate numbers strictly No longer true now we have [] Evaluate lazily, but sequentially. So the laziness is "as if" we did sequential evaluation with infinite precision We can do this by creating a new object each time a variable is assigned - previous uses go to the previous object and subsequent uses go to the new object Output can be number (dimensionless) - DC, Waveform, Table or Table - i.e. something indexed by time Rename Sample as Function The individual points within an ExplicitFunction are Samples When used in a VoiceSet, a Sequence or Table should decay to a Function A one-element VoiceSet is equivalent to a function everywhere. To decay a VoiceSet of more than one element to a function, put it into a sequence (with "division=infinity;" if necessary) and then put the sequence into a one-element VoiceSet. To avoid clicks and pops, we really want each oscillator to have the same Sample value (or at least the same phase) when sequenced That's not possible for general Functions though, so probably shouldn't bother unless it's really annoying, in which case find some more specific way of solving that problem Suppose we do Function@Function. The @ should be applied pointwise, and only the frequency should change at each point, not the phase. So .@(f1 | f2 | f3) would do what we want. Does a time-dependent @ allow us to write x@major and get (x + x@5/4 + x@3/2)? If so, how can major be defined? Almost certainly not - that would mean having the exponential inside the integral evaluate to a (weighted) sum of delta functions, which implies finding the log of a delta function, which is defining a whole new object. If we're defining a whole new object we may as well write: major = 1 & 5/4 & 3/2; chord = sine@C@major; decay (e.g. from VoiceSet to Waveform) as necessary A sequence is really an "outer" function along with a vector of inner functions. The outer function maps the domain onto an index into the vector. The inner functions must all have the same domain and value units. The outer function has dimensionless value The outer function can have a different domain unit to the inner functions, but will only decay to a function if the inner domain unit and outer domain unit are the same. | only creates outer functions with integral value. Can access the outer function with the unary % operator and modify it to have non-integral values. If the outer function evaluates to a+b where a is integral and b is fractional, sequence evaluates to vector[a]*(1-b) + vector[a+1]*b. So can glissando just by doing "sequence% = convolve(sequence%, pulse)". To define "pulse" we need a way of doing functions of unlimited extent. "division = infinity"? Negative indexes or indexes greater than the last wrap around (just as sequences and other functions repeat) If the outer function's value has an imaginary part it is ignored, just as with output Functions A Number is a special case of a Function (one that is constant over the entire domain) Except the domain unit is whatever you need it to be. The [] operator evaluates a function at a value, or composes functions. So sine[0] = 0. x[y][z] = x[y[z]] (associativity of function composition). Because all functions have real range, any imaginary part is ignored. Because functions repeat, indexing outside the domain wraps around until inside. Can use a sequence as an LValue: a | b = c; assigns a to the part of c from 0 to division and assigns b to the part of c from division to division*2 By using | on the left and the right can extract arbitrary sections of a function Can use a VoiceSet as an LValue: a & b = c; assigns a to the first voice in c and assigns b to the rest This is useful for moving several values around at once. "a | b" repeats after 2*division. "a | b" means the same thing as "a | b |". The final "|" can be elided and will be inserted during parsing. A "|" with an empty RHS on the end is ignored. Hence we can use "a |" to take the beginning "division" of "a" and repeat it. If "a" is a sequence then "a | b" means sequence concatenation rather than slicing. Unless the domain unit of a function is 0, the only LCTs we can do are pure real or pure imaginary Note that distributions can be multiplied by infinitely differentiable functions but not by other general distributions - delta*delta is not defined. Importing a wave from a file yields a band-limited function, not a discrete distribution Strings: Useful for arguments to include statement Also useful for directly creating a terse function (e.g. simple melody or waveform) Band-limited function like importing from a .wav file Evaluates to ASCII values of characters at integers Extent and period are both length of string Syntax for functions: major[x] = x + x@5/4 + x@3/2; minor[x] = x + x@6/5 + x@3/2; If we allow recursion, our language becomes Turing complete How do we terminate recursion? Have conditional operator ?:, Boolean-valued operators ==, !=, <, >, <=, >=, Boolean-valued functions Or: multiplication by 0 short-circuits function evaluation Dynamic scoping? This makes a difference for functions: a = 1; f[x] = a*x; a = 2; b = f[3]; // b==3 for lexical scoping, b==6 for dynamic scoping. Dynamic scoping is more difficult to understand. Dynamic scoping makes functions more like macros, lexical scoping more like proper functions Let's use lexical scoping unless we find a really good reason to do otherwise Functions can be used before they are defined (unlike variables) This is necessary in order to allow (mutual) recursion Use the same function call scoping as ALFE Do we want to allow functions to specify the types of their arguments? If so, how? In general, is MuT typing static or dynamic? Not sure how to specify static types - there are so many things about variables which could be part of the type, but most operations don't care about most of them Table Of what? VoiceSet? Sequence? Function Constant or non-constant? Domain unit Range unit (integer/rational/double, real/complex) Distribution? Initially just make a dynamic language. If we find a very good reason to add some static types later, do so If something really needs a scalar (e.g. division or "f[x] = ..."), just add an implicit [0] to the end. Why do we have separate operators for explicit and implicit functions (() and [] respectively)? Explicit functions can return any kind of object. Is the same true for implicit functions? Don't currently have any way to create or manipulate a 2D implicit function And even if we did, there would be ambiguity about how to reference the separate arguments Therefore implicit and explicit functions are separate We can convert an implicit function to an explicit function by doing: explicit(x) = implicit[x] Can we convert an explicit funciton to an implicit one? In the same way? i.e. "implicit[x] = explicit(x);" What if explicit returns a Function rather than a Scalar? Implicit functions have extra degrees of freedom removed, so the above would be the same as "implicit[x] = explicit(x)[0];" Functions are more like macros - there's not much that they can do that can't be done directly (other than recusion and Turing-completeness) Need to figure out terminology to distinguish between [] functions and () functions. Get rid of () functions - allow functions to be function-valued Where does this leave (mutual) recursion? Make it impossible? There might be some really interesting sounds which are only possible with recursion. Explicitly-specific function (f[x] = ...) can only be assigned once and have above-and-below scope, implicitly-specified function (f = ...) can be reassigned? Seems a little ocunter-intuitive If a name is not found in the above-scope, search the below-scope (in reverse order?) This seems like a neat solution - simple and forgiving. We can implement this by looking up a name as if the reference is at the end of the program (scope?), if it's not defined in the usual place Try the end of the current scope first, then the end of outer scopes until we reach the end of the program - that way we can define mutually recursive functions locally How should we implement band-limited resampling? Using FFTs? SRC or libresample? The FFT of a periodic signal is a distribution - does that mean that we can't convolve two periodic signals? No - sin(a)*sin(a+b) = (cos(a-(a+b)) - cos(a+a+b))/2 = (cos(-b) - cos(2a+b))/2 => convolution is cos(-b)/2 So perhaps it's just that we can't multiply deltas of different orders If time-domain signals are band-limited and frequency-domain signals are discrete, what about FRFT signals? Hopefully this is academic and we can just compute arraywise whenever there's an FRFT (or FT?) to do. Suppose we define "f[x]=x*x;". x can be a scalar or a function When we reference f without []s, assume that x is a scalar? I think we won't have a problem if this rule is followed, since either's an explicit argument or there isn't, and either way the type of the argument is known. Or we could force all arguments in explicitly-defined functions to be scalars, so if you wanted a second order function you'd write: f[x][y]=x[y]*x[y]; I don't like that as much though. What are the circumstances where this is ambiguous? Explicit functions are equivalent to macros If division==infinity, what does a|b yield? a for >0 and b for <0? Do we want a dot product operator? f[x][y] = x*y; f.sine yields g where g[x] = integral(y=-infinity..infinity, f[x][y]*sine[y]) Might be expensive to calculate Is there a use case? Avoid adding it unless we find one, but keep it in mind What if you dot product together two second-order functions (e.g. f.ft) - do we have to integrate over the space of all functions? We can implement dot product with an integration operator And we can implement integration by evaluating the Fourier transform at 0 Need to figure out how to implement a@b for complex, time-dependent b We know how to implement it for constant complex b To implement it for real, time-dependent b: It's not (a@b)[x] = (a@(b[x]))[x] since we don't want discontinuities in b to imply discontinuities in a@b for continuous a (manifests as clicks when frequency changes) Therefore, integrate b yielding B. (a@b)[x] = (a[B[x]]) division is currently a scalar. What would it mean for division to be a function? The period of the function should be the previous meaning of division Suppose a is an integer and a <= division[x] < a+1 and f = division[x]-a Then the value of the final function should be components(p+a)*(1-f) + components(p+a+1)*f division must be real division is just the default outer function of a sequence If the way to get periodic functions is to use | but you need a periodic function to use |, how do we begin? The default division is 0 with a period of 1 Given a periodic function, you can time-scale it and use it as the outer function of a sequence to create new periodic functions Once a sequence decays to a function, its outer function is zeroed One annoying thing about this idea is that the period of a function should be just an unobservable implementation detail - it shouldn't actually change the music Especially for a constant function where the period is not meaningful So maybe instead of being a periodic function, division should encode component and interpolant directly, as with the previous idea of outer functions In that case, might want to have a floor function built-in for simple default behavior. It's not necessary to decide in advance if the output is: periodic or compact-support band-limited or discrete Plan: Create an object for each operator Write code to parse Write code to resolve names Implement evaluations as required