Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 270
Posted: Tue Mar 10, 2009 3:40 am Post subject:
Improving the kijjaz Guitar Subject description: Your suggestions please
Hey, it's me again. I've been using kijjaz's guitar and drum models in my programs and they work just fine, but I feel that the guitar model has reached a sort of plateau. It's based on the mandolin, with a number of mandolin instruments summed together and sent into a SinOsc limiter. Here is the guitar model that I'm using right now, recoded completely from kijjaz's original example:
Code:
// guitar based on kijjaz's model
class guitar {
// define guitar strings
num_guitar_strings => int num_strings;
Mandolin mandy[num_strings];
//
// distortion
Gain gd_in => Gain divide => Gain gd_out;
gd_in => FullRect fwr => Gain add => divide;
Step step => add;
4 => divide.op; // make it a divider
0.025 => step.next;
//
// hook up guitar and pedals
// summ strings into pedal
for (int i; i <num_strings> gd_in;
}
gd_out => Gain output;
fun void strum (float freq, float pluck) {
for (int i; i <num_strings> mandy[i].freq;
pluck => mandy[i].pluck;
}
}
Note that I have modified the distortion to be x/(n+|x|) type, as discussed in the earlier distortion thread.
What I would like to do is model the guitar more realistically including 6 strings, or 4 strings for a bass guitar model. This would include playing notes and chords. I have the option of using the Mandolin, StifKarp, or Sitar instruments in ChucK, but I'd rather do it with string synthesis.
Would anyone care to enlighten me as to a string synthesis technique that might be reasonably efficient in ChucK? Kijjaz, Kassen, you both are familiar with this sort of thing, what do you suggest? Anyone else? Thanks. _________________ "Let's make noise for peace." - Kijjaz
You send a burst of noise into a feedback loop consisting of a delay line and a filter. The burst of noise should be one period long and the delay line plus the group delay of the fiilter should add up to one period.
So what the guitar model, called a Digitar for Digital Guitar by Karplus and Strong needs is six of these strings. Then we can have the software set the frequency of each string to make a chord, or just do one string for a note.
Other guitar effects such as bending could be simulated by varying the delay over the duration of the note.
Also note that the filter must attenuate the feedback signal, so I suppose that the sustain of the note is determined by the amount of attenuation.
Looks like this will be a bit of an effort but worth the time. Digitar! _________________ "Let's make noise for peace." - Kijjaz
Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 270
Posted: Tue Mar 10, 2009 6:59 am Post subject:
Hey, guess what? Now it plays chords!
The model actually strums up and down with a short delay between each string pluck to simulate the motion of a strumming pick. Listen for eight E chords followed by eight A chords, followed by eight D chords.
Inventor: The model is nice and straight forward.
But there are some sound in it that sustains too much with open string's note,
so I tried to adjust that a little and see how it'd sound.
I also tried to add some other features
but now maybe too much sustains of 2nd harmonic is there,
but it sounds okay.
sounds more like guitar harmonics.
Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 270
Posted: Tue Mar 10, 2009 8:00 am Post subject:
Yeah, kijjaz, yeah!
I rolled your changes into the latest version, to which I added heavy distortion. It sounds almost *exactly* like my Stratocaster! Now we have an awesome guitar model to use in the next rewrite of the generator!
Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 270
Posted: Tue Mar 10, 2009 9:49 am Post subject:
kijjaz, you are making guitar models faster than I can even test them! Ah, but we have both been busy.
Here is the Karplus-Strong guitar with kijjaz's modification and a monome-like keyboard interface to a Boolean Sequencer. It begins silent with a blank logic table printed on the console monitor, then when you press the array of 40 alpha-numeric+symbol keys, the program modifies the logic table accordingly and begins to play.
Function keys F1 through F4 select from four banks of logic equation subtables. Replace shred button clears everything and starts over.
It's over 250 lines of code now and beginning to show some decent functionality. What fun!
Digitar7.ck
Description:
Digitar with Boolean Sequencer and Monome-like Keyboard Interface
Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 270
Posted: Tue Mar 10, 2009 10:45 am Post subject:
Well, in the Wikipedia entry for Karplus-Strong they mention that the frequency is equal to the delay *plus* the group delay of the filter. That's why I included the Wikipedia entry for group delay in the second post as well.
So to fix the tuning problem, I think we need to figure out the group delay of the filter and incorporate that into the delay line setting.
Also if I read correctly, the noise burst duration should be equal to 1/frequency, which it is not in the current model. That makes sense because we want to fill the full delay with noise, not just some of it. _________________ "Let's make noise for peace." - Kijjaz
Well, in the Wikipedia entry for Karplus-Strong they mention that the frequency is equal to the delay *plus* the group delay of the filter. That's why I included the Wikipedia entry for group delay in the second post as well.
Don't forget about the sample of extra delay inherent in a feedback loop. Originally the filter used simply averaged between the current and the last (z-1) sample, later evolutions of KS of course use more elaborate filters.
Quote:
So to fix the tuning problem, I think we need to figure out the group delay of the filter and incorporate that into the delay line setting.
Shouldn't the important factor be the phase effect of the filter at the frequency intended? A 4 pole filter (or 2 2pole ones, to make things easy with LPF which I think is a 2 pole filter) should be phase-neutral at the set gain.
Quote:
Also if I read correctly, the noise burst duration should be equal to 1/frequency, which it is not in the current model. That makes sense because we want to fill the full delay with noise, not just some of it.
As I see things the burst of noise relates to the way the string is plucked/struck/bowed/whatever. Texturing the noise and enveloping it will all have interesting expressive effects. I used to experiment with resonators fed by drum-machine hits quite extensively. Different high-hats and cymbals would sound a bit like bowing while toms would be more akin to a blow to the body of a electric bass-guitar (a interesting playing technique at high gain!), those were certainly way longer than second/f.
Also remember, BTW, that you can halve the frequency by inverting the feedback gain and that it can be useful to remove DC offset (either inside of the loop or after the instrument). _________________ Kassen
Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 270
Posted: Tue Mar 10, 2009 7:34 pm Post subject:
OK, I took a walk and got some afternoon sleep, so I'm up for another night of coding.
Here is the progress so far, the latest version of Digitar. It has adjustable distortion and distortion wet/dry mix, so you can remove the distortion if you like. It also plays either notes or chords so you can make it shred if you like, plus I added a bunch of chords.
When you start it up, it's silent because the logic matrix is empty. Just use the alpha-numeric keys plus some symbol keys in a 10x4 matrix to toggle some logic bits and you will start to hear notes.
Press F1 thru F4 to select which of the four banks of logic table entries the keys map. Press tilde (without the shift) to make the +/- keys adjust distortion up and down. Press tab to make the +/- keys adjust distortion wet/dry mix. Press capslock to toggle between notes and chords.
Thanks for all the info, Kassen. It's a little over my head, but I'll do my best to apply it!
Shout if you get stuck, I didn't intend to write "impressive clever" stuff, I wanted to share some notes on working practically with KS. If something there looks incomprehensible I'll try to re-phrase it. _________________ Kassen
Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 270
Posted: Tue Mar 10, 2009 9:49 pm Post subject:
Kassen wrote:
Inventor wrote:
Thanks for all the info, Kassen. It's a little over my head, but I'll do my best to apply it!
Shout if you get stuck, I didn't intend to write "impressive clever" stuff, I wanted to share some notes on working practically with KS. If something there looks incomprehensible I'll try to re-phrase it.
Well, one question: why would a four-pole filter be phase neutral at the set gain? As I understand it a simple LPF model with default Q of 1 has zero phase at DC, increasing phase as frequency increases, and 90 degrees of phase at high frequencies for each pole.
In this case we're setting the cutoff to three times the string frequency, so that puts us in the region where the phase is well under 45 degrees.
Also a four pole filter, even if it had phase of 360 degrees at the string frequency, would have a one cycle delay time. I think this is what is meant by the group delay of the filter, which is why the Wikipedia page on Karplus-Strong said that the feedback loop should have delay equal to the delay line delay plus the filter group delay.
So, in summary, I think we need to figure out the group delay of a 2-pole low-pass filter at 1/3 cutoff frequency and subtract that from the period of the string frequency to set the delay line.
Does that make any sense? _________________ "Let's make noise for peace." - Kijjaz
This program is super interesting, especially the interface.
I've read several reviews for software (always NI Kontakt engine) for emulating strumming, etc. I love that similar things are being done in the ChucK community, however small.
Using a regular keyboard in place of a multi-thousand-dollar monome appeals to no end, all aesthetic differences aside. Really cool stuff, Inventor/(kijjaz/Kassen)!
Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 270
Posted: Wed Mar 11, 2009 5:30 am Post subject:
Thank you telstar!
Here is the most recent source code and an audio demonstration. I added some features, including barre chords, reverb, microphone input, and recording.
Well, one question: why would a four-pole filter be phase neutral at the set gain? As I understand it a simple LPF model with default Q of 1 has zero phase at DC, increasing phase as frequency increases, and 90 degrees of phase at high frequencies for each pole.
I think it should have a 90° phase offset at the cutoff frequency per pole. Hence 4 pole filters will resonate; if you add feedback it lines up exactly at the cutoff frequency creating a resonant peak there. _________________ Kassen
Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 270
Posted: Wed Mar 11, 2009 11:18 am Post subject:
Kassen wrote:
Inventor wrote:
Well, one question: why would a four-pole filter be phase neutral at the set gain? As I understand it a simple LPF model with default Q of 1 has zero phase at DC, increasing phase as frequency increases, and 90 degrees of phase at high frequencies for each pole.
I think it should have a 90° phase offset at the cutoff frequency per pole. Hence 4 pole filters will resonate; if you add feedback it lines up exactly at the cutoff frequency creating a resonant peak there.
Well I'm not sure be I doubt that a 4-pole low-pass filter with feedback will resonate because the gain at the cutoff frequency is -3dB, so the loop gain is below unity. Isn't there a resonant peak below the cutoff frequency for Q higher than 1, as in a Wah pedal? Not sure. But how would that affect the delay calculations for Karplus-Strong anyway? _________________ "Let's make noise for peace." - Kijjaz
But how would that affect the delay calculations for Karplus-Strong anyway?
I'm not 100% sure ... but let me try anyway ...
When you'd have a phase shift of lets say 180 deg at for a filter that is in your loop at the resonance frequency that 180 deg shift would amount to half a period of that particular frequency, and thus it corresponds with 1/2f seconds of delay in the signal and that would be the delay to compensate for. Now you probably wont re-tune your filter for different lengths of the delay line (different ouput frequencies), so you'll also have to figure out the filter delay for all other frequencies (based on the actual phase shift at those frequencies).
Now when you are having a filter with constant group delay you'd see that that all those times would evaluate to the same value, and you'd have to subtract that fixed value from the calculated delay time for the delay line (based upon the wanted frequency). So that would be sort of easy to calculate (based upon a known phase shift at a known frequency for the filter chosen).
Now what filters would exhibit constant group delay is another question ... Bessel filters are said to approximate it ... but I really know nothing here.
There would be another possible approach ... namely making a tuning table that you manually fix for some frequencies and then perform a linear interpolation on for the in-between frequency values.
Joined: Nov 20, 2007 Posts: 1988 Location: West Red Spot, Jupiter
Audio files: 237
Posted: Thu Mar 12, 2009 11:08 am Post subject:
Hello ChucK people,
This guitar thread caught my attention because I have an interest in Karplus-Strong models.
First, let me warn that I am _not_ a ChucK programmer, in fact, I am lower than a noob. I've looked at the source, but I'm very lost.
My question, however, is really about K-S.
I've implemented K-S in a few different digital synthesizers using an FPGA. One is an 8 voice polysynth ( PolyDaWG/8 ) and the other is a 56 string "harp" I call Xarp-56. I also experimented with the Perry Cooke slide flute model a bit.
My question is regarding the string model and the reflection filter. My implementation uses a simple single pole IIR filter. I see there is a bit of discussion here regarding more than one pole for the reflection filter.
I thought about using a 2 or more pole filter, such as a state variable filter in lowpass mode and assumed that this would cause harmonics at the filter's resonance (Fc) to die out more slowly than the fundamental assuming Fc is above the fundamental of the string's natural vibrational frequency and a Q of greater than unity and some general attentuation to keep the gain < unity at all frequencies. Is this a correct assumption? Seems it would be interesting to be able to select the harmonic to enhance this way.
I'm curious as to what instrument types this technique models.
What I'm not seeing in the ChucK source for this project is the structure of the reflection filter - is this part of a library?
With FPGA design, I have to create such filters without the benefit of a library other than a "library" of modules I've created myself or obtained from others. I've gotten code for things like UART and DAC drivers from friends. The bulk of the code in my designs was code I wrote.
Anyone who might be interested in my FPGA MIDI synth designs can look at the links in my sig... _________________ FPGA, dsPIC and Fatman Synth Stuff
Time flies like a banana. Fruit flies when you're having fun. BTW, Do these genes make my ass look fat?corruptio optimi pessima Last edited by JovianPyx on Thu Mar 12, 2009 11:36 am; edited 2 times in total
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum