Teensy “String” range issue

Hi everyone,

I’ve been working on a Teensy polyphonic synth, and it’s been a great learning experience. I’m really happy with the results, but I’ve got one last bug I can’t seem to figure out.

The Karplus Strong ‘String’ seems to have a fixed lower range - I can’t get it to play a note lower than E1. It plays all notes above E1 perfectly.

I am mixing the voice with another oscillator, and I can hear the frequency of the waveform oscillator playing the correct notes in response to midi notes below E1 - but the String oscillator plays only E1 in response to any midi note below E1.

Has anyone come across this issue, or used the String object in the Teensy Audio Design Tool?

People on the Teensy forum are probably in a better position to help, but have you looked at the Karplus Strong code in the Teensy library? It could well be as simple as modifying a single line, and the bits of Paul’s code that I’ve looked at are well-commented. It might look something like this (pseudocode):
// MIDI note 28 is E1
if (note_value <= 28) {
note_value = 28;
}

1 Like

Thanks, I had cross posted there and did get an answer - you were on the money.

I’m not sure how I can edit an object from the design tool though - do I need to make a change within the library and then add in the custom library to my code above the automatically generated code?

Are you using the Arduino IDE? If so, just edit the library code directly. When you compile and upload to the Teensy it will build it with your modified version of the library.

My curiosity got the better of me. It’s here, in lines 47 & 48 of synth_karplusstrong.h

		int len = (AUDIO_SAMPLE_RATE_EXACT / frequency) + 0.5f;
		if (len > 536) len = 536;

Sample rate is 44100, so Nyquist is 22050. Frequency of E1 is 41.203.
22050/41.203 + 0.5 = 535.655

Choose the lowest frequency that you would like to be able to generate, plug it into the formula, and set a new cap.

If you wanted to be able to play A0, for example:
22050/27.5 + 0.5 = 802.32. Round this up to the next integer value, and then change line 48 correspondingly to read:

if (len > 803) len = 803;

Note that the choice of the lower limit might not have been arbitrary, and you could run into problems when you make the change.

1 Like

Note that you also should change the dimension of the array in the same file (from 536 to 803 or whatever).

2 Likes

Oops… nice catch Rich! :face_with_open_eyes_and_hand_over_mouth:

3 Likes

Thanks! I posted on the other forum asking if an approach like this would work, but wasn’t sure how the number would be calculated. But that’s actually really straightforward, thank you!

I will have a play around and see how it runs.

Thanks - I changed it to 1349 to get to C0, and it works perfectly!

Over on the Teensy forum they mentioned some other issues with how the string object was coded - nothing that I think matters too much for what I’m using it for, but thought I’d mention here for people that might be looking for other issues.

2 Likes