*** MUS171 #05 01 18 Miller: @0000 This is the familiar network where you have an oscillator with a controllable amplitude. Amplitude of course you control by @0015 multiplying the output of the oscillator, that's the easy way to do it. And the frequency of the oscillator you control by sending it the appropriate input. So here it is: [Tone] Miller: You can do them both simultaneously, maybe not. Miller: @0030 Wizard of Oz. And if you want to sequence that, why you don't get some delay objects, so maybe the @0045 good way to do this is give yourself a button, and then you can have delays. "Delay" you can abbreviate as "del"; there are abbreviations for some of the @0060 most frequently used objects. And it's going to become important in this particular case. You'll see why. Miller: So let's @0075 have the button turn this on, and have it to be at 440. The recording will jump to 440; I'll tell you why in a second. You don't want to necessarily slide to the note, if you want to start a note at the beginning of something. @0090 You might want to have it just jump there. So this is now a button that makes sure that we're at 440 when we turn this thing on. [Tone] Miller: When you turn something off, you don't have to do anything to its pitch, because just turning the amplitude of the thing by multiplying it by 0 turns it off. @0105 It's still playing A-440, this oscillator is, but we don't care about it. So now a...[Tone] Miller: You do want one of those -- @0120 it also turns this off, right? So hit that button and turn it off. So you want it to slide to 440 and turn it off. Miller: @0135 Ah! That sounded horrible. Let's not do that! OK. So now what we're going to do is make a nice little sequence by having "delay 500" successively, @0150 which will be setting these delays every 500 milliseconds. Miller: As a matter of survival, if you're going to have a bunch of delays, don't daisy-chain them but have them all come off of the @0165 button or whatever triggered them. Because, why? Because that way when you start it again it restarts all the delays and you won't have messages trickling down the delays when you're no longer trying @0180 to do certain things. So now what's going to happen is every time I press the button ... yeah, I should do this <> every time you press the button you start a sequence of delays going. [Tone] Miller: @0195 [Over sound] Miller: And furthermore, here's a subtlety, when you start a delay, if it was already started, it forgets @0210 the previous time it had been started for and resets it to the new time you're starting for. Miller: That's a good way for a delay object to behave, because then it doesn't go off and do something in the wrong order, because you told it to do something and then changed your mind later. If you changed @0225 your mind about what you wanted to do. It is now only doing the new thing, so you can actually believe that things are going to do what you ask them to when you start something -- if you connect to the delay this way. Miller: If you decide that you want to connect to the delays @0240 successively one to the next, then that won't necessarily be true, each one will set the next one off, and if you reset the first one, depending on what phase the others are in, they'll continue doing their things, and then you'll have different delays fighting each other for control of your oscillators, @0255 which will not be as good. So it is a good thing not to daisy chain your delays, but to have them all come off the same source like that. Miller: Now I'm going to make beautiful music. That's going to be, nothing? Oh, @0270 it's going to be a rest. Yeah, that'll suit fine. And then they'll go over there, and then they'll wait another second. I won't even put that delay in there. It should be 2500. @0285 And here it'll go back down to A and here we'll stop. And now, here's one of the things that's problematic about patching, and I will show you @0300 strategies later to deal with this: Your patches get messy after you've done a certain amount of stuff. Technique number one: Miller: Turn the font size down. Other techniques are going to be use more than one window, but I haven't shown you how, and also @0315 use names for things so that everything doesn't have to be a connection. I haven't shown you how to do that either, but that's all coming. And now if I have this right I'll have this this beautiful composition. [Tone] Miller: @0330 Ta-da! The marching demons in the Wizard of Oz. So this is how to make sequences that do things like control amplitudes and frequencies. OK. Questions about this? What I did and why? @0345 Yeah? Student: I forgot, for the first number in these messages is for frequency? There's a .03 there. Miller: Oh! OK, yes. That's the thing. These are @0360 numbers, what they are depends on where you put them. Or rather, how they're interpreted depends on where you put them. So these numbers are frequencies by virtue of the fact that they're talking through this line to this oscillator. But these other numbers are amplitudes because they're talking and this line is getting multiplied @0375 by the oscillator. So even though the data goes down, in some sense the meaning bubbles up. Student: So it's on the line that goes amplitude and then time...? Miller: Right. Or value and time or target and time. @0390 I think of it as target, because it's the place where the line will eventually be, or the thing that the line will eventually be emitting, I guess is the right word after the time elapses. Student: So it's another process that determines what they're lined up to. Miller: Yeah. @0405 Other questions? No. I'll leave this then and get onto fun topics. Not that this isn't a fun topic, but there are other fun topics. ...I'll just do a "Save As", @0420 remember the font size and start all over again. I'll just do three...table...Oh, no, wait. Miller: I neglected to tell you a bunch of things last time. @0435 Yes, right. Table oscillators first, and then units, psychoacoustic units which is MIDI units of pitch versus frequencies, and decibels versus linear amplitudes, which I will show you after I show you the basic @0450 yoga of table lookup in computer music -- Well, phase generation and table lookup, which is how oscillators are made, which is the bread and butter of computer music. And the fact that it's taken me five classes to get here says something either about the @0465 indirectness with which I'm approaching the thing, or the fact that perhaps it is actually more complicated than I'm thinking to myself it was supposed to be. OK, so we're going to do phase and tables. <> Do this one. OK. @0480 And, we don't need any of this except the time for that, so. But we'll keep this around for this, just to be able to use it. @0495 But...here's where I'll stop, maybe on this. Miller: All right. So the first thing to comment on is the following: There is an object, @0510 whose name is phasor, which generates phases. These are not useful things to listen to. In fact, let me prove to you this is not useful to listen to by playing it.[Tone] Miller: This is a bad sound. @0525 The reason is that it sounds like a mosquito is what's called fold-over. Well, there are several reasons it sounds like a mosquito. But the reason it sounds bad in computer music ears is because of fold-over, the fact that this signal is not a good band-limited signal @0540 that is limited to 22 kiloHertz and a half. It is an un-band-limited signal that has theoretically an infinite trail of partials, and in a digital environment such as in any computer music environment, you will hear @0555 various kinds of badness happen. What it sounds like is just not exactly a stable quality of the signal. It sounds like it's fluttering a little bit. That is @0570 fold-over. There are better examples of fold-over that I could show you, but they would be piercingly ugly to listen to and I don't really want to deal with them. Go look at the PD documentation; you'll see a wonderful fold-over generating patch which will make you jump out of @0585 your chair and spit out your gum. So now why am I showing you this, then? Because you use it to do things like look up wavetables. To show you this, I have to get out @0600 my array so you can see what's happening. I'll do that now. Sorry this is getting repetitive, but it is what it is. I'll call it <> "array.1.18a" Miller: 18] @0615 And then just going to use a nice tabwrite~ write it. Wow. I shouldn't really have given a long name, should I? "array.1.18a" ... I don't want these to fight with each other if @0630 you happen to load more than one of these up while you're looking at old patches, which is why I'm making these awful names. I'll show you a better way later, but that will wait. Miller: So now, one of the things the phasors do that makes ...oh! @0645 Duh! I thought it was me. It actually was me but at a deeper level. Here's a crucial thing to get: Here's a @0660 sawtooth wave...notice how there are bad kinks in this? That's actually graphics. Miller: But there are bad kinks in the thing, because sometimes when the thing wraps around, actually let's go to 440, sometimes when the thing wraps around... Since we're at @0675 44,100 points per second, 440 Hertz means how many samples per cycle? @0690 100 and a fraction, I think, if I'm doing this right. << (41,100 samples/second)/(440 cycles/second) = 100.22 samples/cycle >> Miller: So it's <> about 100 samples long. Oh yeah, it's about a hundred samples long 'cause the table's about a 100 samples big. But @0705 it's not exactly 100 samples long from the bottom to the top, it's just that sometimes it's 100 samples and sometimes it's 101 samples.<> Miller: It's not a decent periodic signal, really, it's a sawtooth wave being represented @0720 digitally and it sounds bad. What you do to make it sound good is you use it to look up a table such as ... -- And here's object number two for today: Phasor and cosine are both @0735 objects you haven't seen yet. The cos takes whatever goes into it and reports its cosine, or outputs its cosine. [Tone] Miller: @0750 And that's when you get this kind of thing: That's a nice sinusoid. Miller: OK. So your cosine is not a sine, because cosine is the simple function and sine is the complicated function to @0765 deal with. There's only one wavetable, so it became cosine. With an oscillator, really, you've seen this as osc~. The osc~ is in some sense equivalent to (phasor and cosine). @0780 Phasor is an object which just generates a phase that goes from left to right if you'd like, a certain number of times a second you specify, for instance by an input. And cosine is a table lookup @0795 which if you give it 0, it gives you 1; if you give it 1/2, it gives you -1. And if you give it 1, it gives you 1 again. Miller: And I happened to click it just at a moment when it was going from 0 to 1 in the space of the window. But if I do it again, @0810 you'll see in fact that it's just moving between those two values. That was an accidental click. All right? Miller: Now, this is interesting because you don't have to use cosines. You can use other waveforms. And @0825 what would be another good waveform? Miller: Well, for instance, I could ask for the cosine of twice the thing which would be two @0840 cycles of the cosine wave and do that like this: Multiply the phasor by two so that it doesn't sweep from 0 to 1, It sweeps from 0 to 2. Miller: And then, @0855 when I connect that, you hear [Tone] the octave. Miller: So, there's twice as fast as this. [Tone] Miller: Well, "twice as fast," that might be confusing. What's really happening is, @0870 think of this as a function. This function is a cosine of twice the input which is to say it doesn't just go from one, to minus one, to one once as the phasor's output goes from 0 to 1. Miller: As the phasor's output goes from 0 to 1, @0885 this goes from 0 to two and so this thing goes through two cycles. So, you're looking up the second harmonic. So, now you can do groups of harmonically related sinusoids. You can build up tones out of @0900 amplitudes of individual harmonics by combining cos~, and cos~ of the octave with the cos~ of the twelfth, and so on ... like that until you get tired of making the patch. Miller: This is @0915 a very simple ... What's the right word? ... a very simple example of using wavetables, of using waveforms, specifying waveforms, which are things which @0930 you index by giving it a number from 0 to 1 so this phasor does repeatedly at some number of times per second given by its frequency. Miller: Phasor has memory. It has to remember its @0945 phase from sample to sample. So, it is an effective integrator. The frequency that you put it tells it how much it's going to add to each previous sample to make the next one. Miller: cos~ doesn't have any memory. It's @0960 just a pure function that takes whatever you put in and puts something out. So, phasor is the real oscillator here and cos~ is a wavetable that the oscillator is indexing. Miller: And furthermore, this @0975 combination of (phasor and cos~) is what you previously have known as osc~. All right? Now, I told you that so I can tell you this next thing: Miller: You can make your own tables up. @0990 Here's where, at least in some respects, things start to get fun. So, how am I going to do this so it's in the right space? There, I can't see that so I'm going to cheat a little bit. I'm going to make a window as big as @1005 I possibly can so I can keep this font. Miller: That will hopefully make something that can be understood. I'm going to make another table and I'm going to give it, @1020 again, I didn't think in advance, I'm going to give it 8 points. Yeah. And this is now going to be a table, "tab.1.18" -- @1035 Sorry. That's a bad name. Everything is bad about this ... Miller: Here's the graph. Yep. We're happy. Everything is good. Now, last time I did this, I forgot that I asked you to do @1050 the points instead of polygons. Miller: Points. So check that we did. I forgot, OK. Now, we have something which we can edit and it's just a bunch of numbers. 8 of them. Right? Miller: @1065 So, you've seen all of this before except I don't know if you've seen me drawing one, but that's one way of getting things into the table. There are other ways. You can have text in a file. You can, if you want to, @1080 save the properties and somewhere in here it gives you the opportunity to... Miller: What does it do? What does it allow you to do? Edit this in by...Oh, got 'em .. where am I now? I'm looking a feature that @1095 isn't there -- OK. I'll show you how to get numbers in there in a good way later. That's going to be a whole other thing. All right? Miller: So, I just put a waveform in here. Now, what I can do is say, "Oh. Let's listen to it by..." Miller: @1110 OK. Some pedagogical sense tells me I should do this first. We're going to read out of the table and the table is going to be "tab.1.18a." @1125 Notice, I did not put a tilde in. I'm going to do this just with messages to start with because it's going to be easier to understand what's going on. And then, I'm going to add a tilde and we're going to be operating with signals. So, @1140 on that Miller: Input number ... and beside it Miller: So, I'm using a Macintosh keyboard on a Linux machine. The little Apple key doesn't do anything in Linux. @1155 It doesn't think it's an Apple. Miller: OK. So, I give it numbers like 0 and it gives me this value. I give it a number 1 and it gives me this value and so on like that. And now, I can just go sweeping through @1170 the thing looking at the values in the table. Right? Miller: So, we've got storage. Not only storage, but storage of as many numbers as you want to put in the array. Student: How come when you go @1185 negative three, it still gives you a value? Miller: Yes, thank you. What happens when I go off the end of the table is, it says, "Well, that's OK. I'll just give you the closest point to what you had." So, in general, Pd's approach to errors -- @1200 this is not good computer science -- is it just puts guardrails on everything. Miller: So, if you divide by 0, it doesn't give you an error. It just gives you 0. If you try to read off the <> array ... Actually, there's several things it could have done. It doesn't give you an error because then you wouldn't hear anything. @1215 It's better to hear something that's wrong than not to hear anything. Maybe. Miller: You could also say that "if I gave you a negative value, the thing that you should do is wrap around to the other end as if you were an endlessly repeating waveform." That <> @1230 is done using a different object in Pd. The table doesn't do that and if you want that, you have to use an object called "wrap" which I will introduce later if needed. Miller: Instead, it simply says, "If you're between 0 and 7, @1245 it will read the value out of the table. And if you're in excess of 7 or below 0, it will simply give you the last or the first value." Which is good enough for us right now. Miller: Furthermore, if I give it a number like, let's see... If I give it 0 as the first value, @1260 and the last value is 7 because there are 8 numbers -- That's one possible way of counting. That's the modular arithmetic way of counting. Miller: The other thing is, if I give it a half, what should it do? @1275 That's a trick question on two levels. ... Yeah? Student: You can give it a 1, possibly. Or you can give it less than 1? Miller: Well between this and this. So, you could just @1290 do what you said, which is to say, just call it 1 or just call it 0. Miller: Oh! And then, should you round, in other words, if I give it a half should round it up to one, or should it just truncate it down to 0? Another thing that... Yeah? Student: @1305 Could it do interpolation? Miller: Another thing it can do is interpolation. But then, the question is, how many points of interpolation should you do? And if it's two points, there's really only one good interpolation algorithm. But when you have four or 8 points, there are several different @1320 ways of interpolating that have different properties. -- So, it just doesn't<>. Miller: If I give it numbers between 0 and one, it declines to act smart. It simply truncates the 0 and gives you that value @1335 until I hit one, at which point, it gives you the next value and so on. Student: So, if you were to go below this number now, does it round down or does it just round one of them up? Miller: It rounds down. Right. Oh, yes. @1350 There's no memory again so it doesn't know what I asked it previously. So, everything is as if there's no yesterday and it always rounds toward minus infinity. Actually, in table land, it only counts from 0. So it rounds towards 0, we'll call it. @1365 OK? If you wanted to... Yeah? Student: Can you go and put the numbers in again? Miller: Yes. @1380 I'm trying to decide which is the best way to show you how to do that and which requires the least constructs. There are about five ways of doing it and I didn't realize I was going to have to do that today. So, I didn't think @1395 in advance about which one to show you so I'll get back to that. Miller: You will eventually want to be able to do things like throw values in a table. Miller: Oh! There's a tabwrite~ you can see here, so you can guess that there might be a tabwrite <>. @1410 But it's not. Remind me to get back to this. The tabwrite is not a tabwrite~ without a tilde. -- It doesn't turn out to make sense to just write sequentially through the table in message land so it works differently. Miller: @1425 All right. So, here's tabread. Now, you could say, "tabread~" And now that you've heard everything that you've heard, you know exactly what will happen when I run a phasor into tabread~ @1440 and then, listen to the result. Miller: Why don't I hear anything? Do I look surprised that I don't hear anything? @1455 I'm not trying to project surprise here. OK? Miller: What are the values coming out of phasor? 0 to 1, not inclusive. And what does tabread~ do? It rounds down to the nearest integer. @1470 The nearest integer down is always 0 so we're getting out solid, whatever that number was, -.21 and the mixer is then forgetting it because it's AC-coupled. Miller: So, if I want to hear something, @1485 I would take this phasor and multiply its output by the size of the table. Miller: @1500 Oh. Here's a thing: You will learn various ways of making your patches not occupy a huge amount of space. Something that I do but you don't have to, is when you're multiplying @1515 by a line, you put the line next to the multiplier instead of above it. Miller: And if you do that consistently, then you learn to expect it and then it looks normal when you do this, even though, this line almost looks like it's going up. This is the way that I normally do this when I'm working. Miller: @1530 Now, I'm going to say, "Multiply by the size of the table, please." Oh, I forgot to put a space. Miller: Oh, hey! Sorry. @1545 I need a tilde because I need a signal multiplier because there's a signal coming out of phasor~. Miller: And now, this is sounding better than the phasor. Right? @1560 And I have a little timbre-editor. OK. This is not beautiful sounds yet because there are discontinuities in the table. Let's turn this off. Student: @1575 Doesn't the table go from from 0 to 7, though? Instead of 8? Miller: Ah, thank you, right. So, why am I going up to 8? It's because if I went from 0 to 7 you would never hear this last value because the phasor @1590 would go from 0 to 7 but it would never get to 7 because the exact value of 7 would wrap it down to 0. Miller: So if I want to read the entire table, I want to go all the way to 8 even though I know nominally the table stops at 7. So @1605 it's confusing for two reasons that cancel each other out. Miller: There are 8 things in the table so 0 to 8 sounds natural until you realize that actually they're indexed from 0 to 7. So it sounds like you should go only to 7. But in truth you should still go to 8 because @1620 otherwise you wouldn't get any of the 7 because it would not do it. Miller: Is that clear? That is either clear or not depending on whether you could follow about three different facts that I introduced in the last half hour @1635 all at once. OK? So you can think of the horizontal axis here as going from 0 to 8. Miller: In fact I think of it that way, even though the places where the individual points live @1650 are just in integers from 0 to 8 which are 0,1,2,3,4,5,6 and 7 -- but not 8, because then there would be nine of them. Miller: And furthermore, for it to "spend just as much time," if you like, between @1665 7 and 8 as it does between 0 and 1, you should multiply the phasor's output by the whole number 8 -- the number of points: 8. This will change when we start interpolating the table, because then there will be fewer values that are useful. @1680 But that will happen later. ... Next thing about this, what if...There is one way of getting values into the table. But we can do it anyway. @1695 Let's put a sinusoid in here. Miller: I am going to be a little sloppy, but not terribly sloppy. We're going to say, osc~, and I'm going to give it a frequency which is equal to (the sample rate)@1710 /8, so that its period in samples is 8. Right? Miller: And I'm going to be lazy and say, give me a message @1725 box which gives me the sample rate which I believe to be 44,100. And then I will say divide it by 8, the number of samples in the table. That will be the frequency for an oscillator. And then I'm going to write @1740 that into the table. This is called "tab.1.18a" ... confusing, @1755 all of the above ... Miller: . OK. write it. And there is our nice sinusoid. Oh, that didn't appear... <