As my first project to learn pd, I chose to write a very simple guitar synth, that will take 6 discreet channels of MIDI input, including pitch bend information, and play a simple sawtooth sound. 6 discreet channels is important to capture the full guitar performance, because that's exactly what a guitar is...

***Thus, to REALLY play this patch, you need a 6-channel instrument that generates MIDI output... E.g., a guitar with a Fishman TriplePlay pickup or the MIDI output from a guitar with a Roland GK3 driving a Roland VG unit or similar. ***

Your PBR (pitch bend range) and your starting channel are configurable, and must agree with your transmitting midi guitar controller.

This patch is actually quite fun to fool around with. With a pitch bend range of 12 or 24, you can run a slide all up & down the neck and it works perfectly!

Three files attached:

  • sjrbPDGS1.pd - the guitar synth main program
  • SynthModule-saw-1.pd - an abstraction used for each of the 6 channels
  • Bendin-mtof-freq-calc-expr.pd - This is basically a 'help' file to explain the formula & let you test it. It is not needed to run the synth.

Frequency calculation, using notein and bendin:

I had a VERY hard time finding how to actually honor pitch bends in pd. Lots of folks have asked the question out there on the web, only to receive kinda useless theoretical answers. It took me a while to work out the formula:

[expr $f2*pow(2, (($f3*($f1-8192))/98304))]

Where:
$f1 = bendin value
$f2 = mtof value from midi note from notein
$f3 = pbr, pitch bend range

Formula explained:
freq-w-pb = freq * 2^((pbr/12)*((bendin-8192)/8192))

Which simplifies to:
freq-w-pb = freq * 2^((pbr*(bendin-8192))/98304)

Note similarity to:
next-note-freq = freq * 2^(1/12)

I.e., it's all about powers of 2... In increments of 1/12ths, it's your semitones. But when applying pitchbend, you don't want increments of semitones, you want increments of 1/8192ths of pbr # of semitones.

Bendin values range from 0-16383, where:
0 = bend the note DOWN by pbr# of semitones
8192 = NO bend
16384 = bend the note UP by pbr# of semitones

Yes, I know there is a one-off error (max is 16383, not 16384), and you can't actually get all the way to 16384, but it's so close nobody will ever hear the difference...

I hope this makes sense!

Caveats:

Pitchbend is a 14-bit value, requiring TWO bytes of data from your MIDI controller, one with MSB and one with LSB. Some gear only sends MSB (0-63=down and 64-127=up). The good news is that bendin properly reports it in the 0-16383 range, so no special coding is needed. However, the bend will NOT sound smooth, there will be audible steps, especially when using high PBR values. You'd need to modify this algorithm with a [line~] somewhere to even out the steps. Or stick to low PBR values when using very old gear.

Feedback welcome! I've just started learning...

Shawn

http://www.pdpatchrepo.info/hurleur/sjrbPDGS1.zip