Pitch Converters

Many of the examples you’ve seen so far in Csound Power! use a preset value for the oscillator frequency, or input a raw value for frequency from the score, as in “The Mixer Opcodes,” above. This is fine for tutorials, but it’s not always useful in musical situations. More often, we want to control the frequencies of notes—that is, their musical pitches—from the score, so as to play melodies, chords, or bass lines, and to do so with some sort of shorthand rather than having to calculate all of the desired frequencies by hand. Csound lets us do this in a variety of ways. Here is an example that illustrates the concept in a deliberately clumsy way:


  instr 1
  ; setup:
  iCos ftgen 0, 0, 8192, 11, 1
  iamp = p4
  ifreq = p5

  ; tone generation:
  asig gbuzz 1, ifreq, 75, 1, 0.9, iCos
  ifiltrise = 0.005
  ifiltdec1 = 0.05
  ifiltdec2 = p3 - (ifiltrise + ifiltdec1)
  kfiltenv linseg 300, ifiltrise, 2500, ifiltdec1, 1000, ifiltdec2, 300
  afilt moogladder asig, kfiltenv, 0.2

  ; output:
  aout linen afilt * iamp, 0.01, p3, 0.1
  outs aout, aout
  endin

  </CsInstruments>
  <CsScore>

  t 0 100

  i1 0 0.5 0.5 250
  i1 +.. 225
  i1 +.. 200
  i1 +.. 225
  i1 +.. 250
  i1 +
  i1 + 1

(For details on the odd-looking data in the score, see Chapter 8, “Writing a Csound Score.”) If you enter this as shown, instrument 1 will play the opening phrase of “Mary Had a Little Lamb.” The frequency values sent to the oscillator (gbuzz) come directly from p5 in the score. In this score, we’re playing “Mary Had a Little Lamb” in just intonation, but that’s little more than a detail. Or is it? If we wanted to play the same tune, in C major, using the standard 12-note-per-octave equal temperament used on a piano, the score would look like this:


  i1 0 0.5 0.5 329.627
  i1 +.. 293.665
  i1 +.. 261.625
  i1 +.. 293.665
  i1 +.. 329.627
  i1 +
  i1 + 1

There just has to be a better way! And of course, there is. The tool to use is the cpspch opcode. Derive ifreq in instrument 1 using this line:


  ifreq = cpspch(p5)

and edit the score so that it looks like this:


  i1 0 0.5 0.5 8.04
  i1 +.. 8.02
  i1 +.. 8.00
  i1 +.. 8.02
  i1 +.. 8.04
  i1 +
  i1 + 1

With these two changes, the score should sound exactly as it did before. The input to cpspch (in this case, the value being sent by p5 in the score) is in Csound’s octave/pitch-class format. This format uses numbers with two decimal places. The integer part (8, in the example above) is the octave designation. The two decimal places give the number of the chromatic half-step within that octave.


image

Caution When using pitch-class data, be careful not to omit the leading zero in the decimal part of numbers like 8.02. Csound will interpret a value of 8.2 as if it were 8.20.


cpspch assumes that your music is based on conventional Western tuning, with 12 equally spaced pitches per octave and octaves that are defined by doubling the frequency. This may or may not be a tuning system that you want to use. To produce some other equal-tempered scale, use cpsxpch. With this opcode, you can choose the number of equally spaced steps per octave, the frequency width of the “octave,” and the base frequency that corresponds to a pitch-class value of 0.0. Try replacing the line with cpspch in the previous example with this line:


  ifreq cpsxpch p5, 11, 2, 1

The phrase will sound much as it did before, but if you add harmonies the difference will quickly become clear: This scale has only 11 equally spaced notes per octave, not 12, so all of the intervals are a bit too wide. Creating music with 17, 19, or 31 notes per octave is just as easy. And if you replace the 2 in the code line above with some other value, such as 3 or 1.75, you’ll get an even more exotic tuning.

cpsmidi

If you’re playing a Csound instrument live from a MIDI keyboard, the opcode to use for deriving a frequency from the MIDI note number is cpsmidi. This can only be used in an instrument that has actually been triggered by a MIDI note. If you need to translate an integer coming from elsewhere into a frequency value, use cpsmidinn.

cpsmidi has a sibling, cpsmidib, which incorporates pitch-bends into its output. The bend depth in semitones is given as an argument to cpsmidib. For instance:


  kpitch cpsmidib 2

This will give you the pitch value including a possible pitch-bend with a maximum depth up or down of two semitones.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.126.211