Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © 2011 by Denny Lin1 Computer Music Synthesis Chapter 3 Based on “Excerpt from Designing Sound” by Andy Farnell Slides by Denny Lin.

Similar presentations


Presentation on theme: "Copyright © 2011 by Denny Lin1 Computer Music Synthesis Chapter 3 Based on “Excerpt from Designing Sound” by Andy Farnell Slides by Denny Lin."— Presentation transcript:

1 Copyright © 2011 by Denny Lin1 Computer Music Synthesis Chapter 3 Based on “Excerpt from Designing Sound” by Andy Farnell Slides by Denny Lin

2 Copyright © 2011 by Denny Lin2 Using Pure Data 3.1 Basic objects and principles of operation 3.2 Working with time and events 3.3 Data flow control 3.4 List objects and operations 3.5 Input and output 3.6 Working with numbers 3.7 Common idioms

3 Copyright © 2011 by Denny Lin3 3.1 Basic objects and principles of operation Hot and cold inlets –Messages received at the hot (usually the left-most) inlet, causes computation to happen and output to generate immediately –Messages on a cold (usually the right-most) inlet will update the internal value of an object (for example, to override a first argument value), but not cause the object to immediately output a result Evaluation order matters –The evaluation order of messages that “fan out” from an outlet to multiple inlets may not be immediately evident from the picture, since they depend on connection order

4 Copyright © 2011 by Denny Lin4 Trigger objects A trigger object splits a message up into parts, and sends them in right to left order to its outlets Enforces that the input received at the top inlet will always be sent to the outlets from right to left Defined as trigger or t, followed by the data types for outlet data (i.e. f for float, a for any) Can mix different data types Can send a bang to effect an immediate calculation when data in a cold inlet is received (aka “warming up” a cold inlet)

5 Copyright © 2011 by Denny Lin5 Float and int objects A float object is used as a variable, to store a single floating point number There are two inlets: –Left inlet: Shows current value in outlet if it receives a bang message; sets and overrides the float object to a value if the message is a number –Right inlet: Sets and overrides the float object to a value The outlet can be used to display the current value of the float object The int object takes a floating point number and truncates the decimal portion of the data

6 Copyright © 2011 by Denny Lin6 Symbols and list objects Like float and int objects, symbol and list object boxes can be used to store a single symbol and a single item from a list Like float and int objects, symbols and lists have similar inlets for accessing and storing data

7 Copyright © 2011 by Denny Lin7 3.2 Working with time and events The following objects provide time and event related functionality: metro, delay, pipe A metronome object (metro) is used to produce a time base (beat), which is a regular series of bang events Tempo is given in millisecond time periods, rather than beats per minute. (1000 milliseconds = 1 second) Conversion factor: Beats per minute = 60000 / milliseconds

8 Copyright © 2011 by Denny Lin8 A counter timebase A float box can be wired with an addition object to produce a for-loop counter The output of the float object is sent to the input of the addition (+) object; the output of the addition object is sent to the cold inlet of the float object The metronome patch can be connected to the counter patch to count how many beats the metronome has produced

9 Copyright © 2011 by Denny Lin9 Time objects The timer object can be used to measure the number of milliseconds elapsed between the time the left and right inlets were banged. The right inlet behaves as a hot inlet control The delay object outputs a single bang after a set interval. The interval can be set by the first argument, a hot inlet message, or by a number in the right inlet. Delay is triggered with a bang, and can be canceled with a stop message The pipe object can delay a stream of number messages by a fixed number of milliseconds, between its inlet and outlet. The delay value can be set by the first argument or the right (cold) inlet

10 Copyright © 2011 by Denny Lin10 3.3 Data flow control The following objects control the flow of data in patches: –select –route –moses –spigot –swap –change –send –receive

11 Copyright © 2011 by Denny Lin11 Select The select object outputs a bang on one of the outlets that matches an item on its argument list. Unmatched messages will cause a bang on the rightmost outlet Similar to a switch statement in C++, where the rightmost outlet is analogous to the default case

12 Copyright © 2011 by Denny Lin12 Route The route object works like the select object, but operates on lists If the first element of a list matches an argument, the remainder of the list is passed on to the client

13 Copyright © 2011 by Denny Lin13 Moses The moses object splits a stream by: –sending numbers lower than the threshold to its left outlet –sending numbers equal to or greater than the threshold to its right outlet –set by the first argument, or a value on the right inlet

14 Copyright © 2011 by Denny Lin14 Spigot The spigot object is a switch that can be used to control any message stream (including lists and symbols) A zero on the right inlet of spigot prevents messages from appearing on the outlet Any non-zero on the right inlet turns the spigot on

15 Copyright © 2011 by Denny Lin15 Swap The swap object exchanges the two values at its inlets, and passes the output to its two outlets The first argument in the swap object can be used to exchange an input number with a constant (usually 1), so we can easily calculate complements and inverses of a number

16 Copyright © 2011 by Denny Lin16 Change The change object can be used to produce output only when values in the list changes Frequently used with the int object to remove erratic signals, or when dividing timebase data

17 Copyright © 2011 by Denny Lin17 Send and Receive Objects The send and receive objects (often abbreviated as s and r) work as named pairs, establishing an invisible “wire” Data fed into a send object’s inlet will appear at a receive object’s outlet The relationship between send and receive objects is one-to-many: there can be only one send object of a particular name, but there can be many receive objects with the same name

18 Copyright © 2011 by Denny Lin18 Broadcast messages Message boxes that contain a message that starts with a “;” will be routed to a destination matching the first symbol For example, message ; foo 20 does the same thing as sending a message float 20 to the s foo object

19 Copyright © 2011 by Denny Lin19 Special message destinations Used to address arrays with special commands, and to interact with some GUI elements that have defined receive symbols For example, the resize message can be used to dynamically alter the size of an array. The pd destination (audio engine) can be used to turn on audio computation from a patch

20 Copyright © 2011 by Denny Lin20 Message sequences Separate messages can be stored in the same message box, when they are separated by commas All of these separate messages are sent in one bang Different from lists: a single message is sent in one bang; lists do not contain commas Lists and sequences may be mixed. For example, a message box may contain a sequence of lists

21 Copyright © 2011 by Denny Lin21 The Print object The print object can be very useful in troubleshooting PureData programs, especially messages and lists The output of the print object is to the PureData Console’s Main Window. The following patch with the sequence 1 2, 3 4, 5 6: Produces output in the console (see next slide)

22 Copyright © 2011 by Denny Lin22 Print Console Output

23 Copyright © 2011 by Denny Lin23 3.4 List objects and operations Pd-extended has advanced list operations such as sorting, reversing, inserting, and searching This section focuses on the following list objects: pack and unpack, loadbang, set, list append, list prepend, list split, and list trim; and covers the topics of list substitutions and distribution

24 Copyright © 2011 by Denny Lin24 The pack and unpack objects The pack object is used to assemble a list, while the unpack object is used to disassemble a list The arguments to both objects are data type identifiers of list elements, and may be float literals when specifying fixed list elements, which could be overridden by inlet data Data should be presented from right to left so that the hot inlet is filled last Data is unpacked in right to left order The data types in the list must match the arguments of the object, unless any-type “a” is used

25 Copyright © 2011 by Denny Lin25 Substitutions Message boxes can be used as a template, where dollar sign arguments can be used to denote where the list data will substituting the arguments List item order is denoted by the number after the dollar sign: $1 refers to first item in the list, and $2 refers to second item in the list Useful for changing the order of items in a list: list {5 10 15} becomes {15 5 10} when put through this substitution: $3 $1 $2

26 Copyright © 2011 by Denny Lin26 Persistence Pure Data saves the contents of message boxes when a patch file is saved, and loads it when the patch is open The loadbang object generates a bang when a patch loads The set prefix in a message object, tells the destination message object to not immediately output its data (to the synthesizer) Combining these facts, the settings are saved in message boxes, and recalled by the loadbang object which loads settings to the synthesizer

27 Copyright © 2011 by Denny Lin27 Persistence using messages

28 Copyright © 2011 by Denny Lin28 More advanced list operations The list append object concatenates two lists together by attaching the second list to the end of the first list. Same as list The list prepend object, returns a new list with the argument or list at the second inlet concatenated to the beginning The list split object disassembles a list from the left inlet, at position specified by a number by the right inlet; elements below the split position appear on the left outlet, and the remainder on the right outlet The list trim object strips off any selector at the start of a message, so only its raw elements remain

29 Copyright © 2011 by Denny Lin29 3.5 Input and output Pure Data has many objects for interfacing with keyboards, mice, system timers, serial ports, and USB ports This section covers the following objects: notein, noteout, makenote, ctlin, ctlout, mtof, ftom, and lists other MIDI objects

30 Copyright © 2011 by Denny Lin30 The notein object The notein object reads in a note number, its velocity, and MIDI channel from the MIDI device Note off messages are equivalent to a note on message with 0 velocity

31 Copyright © 2011 by Denny Lin31 The noteout and makenote objects The noteout object sends performance data to MIDI devices noteout takes note number, velocity, and output channel (defaults to channel 1) makenote takes note number, velocity, and note duration (in ms, to turn off note at the end of the time period)

32 Copyright © 2011 by Denny Lin32 The ctlin and ctlout objects These two continuous controller input and output objects are used to receive data from MIDI controllers Three inlet/outlet ports get or set the controller value, controller number, and MIDI channel For example, ctlin 2 1 reads the value of the Breath Controller on MIDI channel 1

33 Copyright © 2011 by Denny Lin33 Some MIDI Controller Numbers NumberName 1Modulation Wheel 2Breath Controller 4Foot Controller 7Main Volume 8Balance 10Pan 64Damper Pedal (Sustain) 66Sostenuto 67Soft Pedal

34 Copyright © 2011 by Denny Lin34 The mtof and ftom objects The mtof object converts MIDI notes to frequency (in cycles per second or Hz) The ftom object converts a frequency to MIDI note

35 Copyright © 2011 by Denny Lin35 MIDI To Frequency Patch PureData’s mtof object converts a MIDI note number to frequency This patch uses osc~ and dac~ objects to play back frequencies converted from MIDI note numbers, using the equation:

36 Copyright © 2011 by Denny Lin36 Other MIDI objects

37 Copyright © 2011 by Denny Lin37 3.6 Working with numbers Pure Data provides mathematics related, comparative, and Boolean logical objects Arithmetic objects:

38 Copyright © 2011 by Denny Lin38 Trigonometric maths objects

39 Copyright © 2011 by Denny Lin39 Random numbers The random object gives a range of numbers from 0 to its argument - 1 For example, random 10 produces random numbers between 0 and 9

40 Copyright © 2011 by Denny Lin40 Comparative objects

41 Copyright © 2011 by Denny Lin41 Boolean logical objects Logical AND is represented as && Logical OR is represented as || Use != 1 to represent logical NOT

42 Copyright © 2011 by Denny Lin42 3.7 Common idioms These are frequently used algorithms: –Constrained counting –Accumulator –Rounding –Scaling –Looping with until –Message complement and inverse –Random and weighted random selection –Delay cascade –Last float and averages –Running maximum or minimum –Float low-pass

43 Copyright © 2011 by Denny Lin43 Constrained counting Using the mod object, the counter’s output value returns to 0 when it reaches the value of the first argument Used for producing multi-rate time-bases, and sounds that have complex repetitive patterns

44 Copyright © 2011 by Denny Lin44 Accumulator Compared to the counter patches, notice that the + and the f(loat) objects have traded positions Stores the sum of all previous numbers sent to it

45 Copyright © 2011 by Denny Lin45 Truncation and Rounding Truncation strips the decimal part of a floating point number into an integer Rounding takes the input value and rounds down to 0 if the input value is = 0.5

46 Copyright © 2011 by Denny Lin46 Scaling Used to map a range of input values (0 to 127) into another set of output domain values (1 to 10) Solve the equation: y = mx + c Where y is the domain’s upper value c is the “bottom value” of the domain (output) x is the “upper value” of the range (input) m is the slope or conversion factor (0.070866) Multiplying input (x) by m and adding the result to bottom value c produces output (y)

47 Copyright © 2011 by Denny Lin47 Looping with until The until object can be used to control loops Will continue until a bang on the right inlet of until is received This approach uses a trigger, select, and a counter

48 Copyright © 2011 by Denny Lin48 For loop Safer and simpler way to use the until object Sends the number of bangs indicated in the inlet of the until object Stops when the message box value has been reached Do NOT feed the until object a negative number (causes infinite loop)

49 Copyright © 2011 by Denny Lin49 Chebyshev Polynomial This patch computes the second of Chebyshev’s first kind polynomials: T 2 (x) = 2x 2 - 1

50 Copyright © 2011 by Denny Lin50 Message complement and inverse Useful for calculating 1-x and 1/x for any x The swap object exchanges the values between its inlet and the 1 from its first argument The left outlet of swap contains the 1, and the right outlet contains the x value The x value is loaded first to the – or / object before the 1

51 Copyright © 2011 by Denny Lin51 Random and Weighted Random Selection In Random Select, a random number between 0 and 3 is generated every 500 ms. Each outlet has an equal probability of being triggered (25%) In Weighted Random Select, a cascade of 2 moses objects split the probability of being triggered into 10%, 40%, and 50%

52 Copyright © 2011 by Denny Lin52 Delay cascade Useful for producing a quick succession of bangs in a fixed timing pattern Input from the first bang will be delayed by the first delay object for 100 ms Output for the first delay is sent to the second after its delay Pattern continues until the last delay object has completed its delayed output

53 Copyright © 2011 by Denny Lin53 Last float and averages Last float value displays the previous value, from a stream of numbers fed to the trigger object’s inlet The trigger object sends a bang to the float object to display the last value, and then stores the next value into float Last value can be used to calculate averages, by adding the previous value to the current value, and dividing by two

54 Copyright © 2011 by Denny Lin54 Running maximum and minimum Given a very small value in its first argument, max can be used to track the maximum value Given a very large value in its first argument, min can track the minimum value Tracking can be reset by sending a very small or very large float value to the cold inlet

55 Copyright © 2011 by Denny Lin55 Float low-pass Can be used to smooth out noisy data from external controllers Follows filter equation y n = Ax n + Bx n-1 Does not converge on the exact input value Can use int to round output


Download ppt "Copyright © 2011 by Denny Lin1 Computer Music Synthesis Chapter 3 Based on “Excerpt from Designing Sound” by Andy Farnell Slides by Denny Lin."

Similar presentations


Ads by Google