guitar input - pure sine and/or square output

Algorithm development and general DSP issues

Moderator: frank

jovesdies
Posts: 33
Joined: Wed Feb 25, 2009 3:55 am

guitar input - pure sine and/or square output

Post by jovesdies »

Hi,
is there the possibility to obtain a pure (without harmonics) sine wave or/and square wave output from FV1 with a guitar input?
Let me explain (If I can...) : I play guitar through FV1 and I want to obtain the basic tone frequency without any harmonics in form of sine wave or square wave.
Thanks!
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

Hmmm, pitch detection is the limiting factor. You could try to determine zero-crossing points and use that to compute time and generate an LFO for the sine wave or generate a square wave based on the time but I have no programs to do this.
Frank Thomson
Experimental Noize
livingston
Posts: 131
Joined: Sun Nov 15, 2009 3:37 pm
Location: New Orleans, LA US

Post by livingston »

I'm interested in this, too. Any more specific thoughts on how to detect and count zero crossings?
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

Using the SKP ZRC should do the trick. I have not tried this but something like:

Code: Select all

equ old_sig reg0
ldax old_sig ; read in saved value
ldax adcl ; read in ADC left, also pushes ACC -> PACC
skp zrc,different ; skip if the signs of ACC and PACC are different
; if here the sign of both old_sig and adcl are the same
wrax old_sig,0; save the adcl to old_sig
; do other stuff
clr
skp zro,end; jump over the routine for zero crossing
different:
; if here the signs are different so a zero crossing happened
wrax old_sig,0; save the adcl to old_sig
; do other stuff
end:
Frank Thomson
Experimental Noize
livingston
Posts: 131
Joined: Sun Nov 15, 2009 3:37 pm
Location: New Orleans, LA US

Post by livingston »

So making a square wave from the above is simple enough, but what about other waveshapes? Sine, saw and triangle would be nice. Filtering a square wave into these shapes is pretty imprecise and of dodgy quality with a changing input frequency, so it seems it's better to start with a sine and derive the others from there.

I was thinking something like this:

Code: Select all

different: 
; if here the signs are different so a zero crossing happened 
wrax 	old_sig,0		; save the adcl to old_sig 
rdax	number,1
sof	1,.001
wrax	number,0
So when the zero crossing happens we add a constant to a running count, then use that number as a frequency control for a sine generator. I tried it, it's not working, but the number to be added (in this case .001) was a random guess, so I will try different values.

Am I on the right track here?
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

I would probably generate the sine then derive the others from it, i.e. square is derived from sign of sine, sawtooth is similar in that you could use zero crossing to reset it to bottom, etc.
Frank Thomson
Experimental Noize
livingston
Posts: 131
Joined: Sun Nov 15, 2009 3:37 pm
Location: New Orleans, LA US

Post by livingston »

Right, but I'm wondering how we get from zero crossings to a pitch control for the sine.
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

Could you post the entire program?
Frank Thomson
Experimental Noize
livingston
Posts: 131
Joined: Sun Nov 15, 2009 3:37 pm
Location: New Orleans, LA US

Post by livingston »

Sure:

Code: Select all


equ	freq	reg0
equ	s	reg1
equ	c	reg2
equ	p0fil	reg3	;coarse frequency control filter
equ	p2fil	reg4	;output level control filter
equ	amp	reg5	;output amplitude
equ 	old_sig 	reg6 
equ	number	reg7


ldax 	old_sig 		; read in saved value 
ldax 	adcr 		; read in ADC left, also pushes ACC -> PACC 
skp 	zrc,different 	; skip if the signs of ACC and PACC are different 

; if here the sign of both old_sig and adcl are the same 
wrax 	old_sig,0		; save the adcl to old_sig 

; do other stuff 
clr 
skp 	zro,end		; jump over the routine for zero crossing 

different: 
; if here the signs are different so a zero crossing happened 
wrax 	old_sig,0		; save the adcl to old_sig 
rdax	number,1
sof	1,.001
wrax	number,0

end:

skp	run,2
SOF	0,0.5		;setup LFO with amplitude of 0.5
wrax	s,0		;c is initialized to zero on startup

rdax	pot1,1		;get fine freq control
sof	0.01,-0.005	;scale to proper exponential limits
rdax	pot0,0.625	;add coarse freq control
sof	1,-0.66
exp	1,0
rdfx	p0fil,0.01	;average with filter
wrax	p0fil,1
mulx	number
wrax	freq,0

rdax	pot2,15/16	;set up pot2 for db/step amplitude control
rdfx	p2fil,0.01
wrax	p2fil,1
sof	1,-15/16
exp	1,0
wrax	amp,0

rdax	c,1		;oversample the oscillator to reach 20KHz easily.
mulx	freq
rdax	s,1
wrax	s,-1
mulx	freq
rdax	c,1
wrax	c,0

rdax	c,1
mulx	freq
rdax	s,1
wrax	s,-1
mulx	freq
rdax	c,1
wrax	c,0

rdax	c,1
mulx	freq
rdax	s,1
wrax	s,-1
mulx	freq
rdax	c,1
wrax	c,0

rdax	c,1
mulx	freq
rdax	s,1
wrax	s,-1
mulx	freq
rdax	c,1
wrax	c,1.99

mulx	amp		;scale output
wrax	dacr,0
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

Just have a second to look at it (busy day for just getting back from a holiday weekend), I think the logic is a little off:

In zero crossing stuff, if signs are the same then do the counter increment (you are doing it if different)

If signs are different, update the frequency control for the sine wave then clear the counter back to 0

Do not use "number" for frequency control, that is the counter and always changing, copy it in the "signs different" routine to a different register before clearing and use that reg in the lfo generator.
Frank Thomson
Experimental Noize
livingston
Posts: 131
Joined: Sun Nov 15, 2009 3:37 pm
Location: New Orleans, LA US

Post by livingston »

Excellent, I tried your suggestions (at least as I understood them) and it now works, sort of!

What I have here now is truly the strangest effect I've ever heard. At some pitches it actually does track, and reasonably well for what it is right now. However, it tracks backwards. In other words, it really does seem to be tracking the fretboard in tune, but playing a note and then going up a major second sounds like going down a major second. Playing a mixolydian scale makes a minor scale come out, and the highest note on the fretboard produces the lowest note out of the effect.

I guess that means I need to subtract rather than add to the counter.

But when it's not really tracking well, it has a very "vocal" sound, I guess by having these jumping harmonics which somehow add up to something like a formant filter. Really weird and fun.

I don't understand how it's so in tune though. I figured it would create some kind of correlation between input pitch and output pitch, but not the proper correlation on the first go. Did I get lucky with the increment number, or does that number not have anything to do with it?

edit: actually, when not tracking well, it sounds a lot like a Speak n Spell. I don't know much about speech synthesis, but I wonder if something similar is used there, swapping back and forth between a couple of pitches at audio rate.

Edit2: I tried subtracting from "number" instead of adding, but the pitch still tracks backwards.
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

You will want to add, the lfo operates in such a manner that the higher the coefficient the faster the lfo.

There are a lot of harmonics in a guitar so if you look at it on a scope you will see a complex wave form, as a result you will get odd results using a guitar to control an lfo. The harmonics will cause "undesired" zero crossings and result in a count that is not representative of the fundamental.

Also, you may need to experiment to determine the proper increment to frequency conversion. You may need to adjust the count by an equation to really drive the lfo at the desired frequency, it may not be linear. If you have a function generator, scope and frequency counter you should be able to derive it.
Frank Thomson
Experimental Noize
mtripoli
Posts: 6
Joined: Tue Sep 01, 2009 12:27 pm

Post by mtripoli »

livingston wrote:...
But when it's not really tracking well, it has a very "vocal" sound, I guess by having these jumping harmonics which somehow add up to something like a formant filter. Really weird and fun...

edit: actually, when not tracking well, it sounds a lot like a Speak n Spell. I don't know much about speech synthesis, but I wonder if something similar is used there, swapping back and forth between a couple of pitches at audio rate.
WOW! Was that statement a whack in the head from the past... :lol: !
You are very much dead on. The synthesis method used on the S&S was called LPC-12. I used this very (very) early on in toy design (I haven't thought about this stuff in a long time). "In those days" memory was very expensive real-estate on an IC. LPC "basically" models the human vocal tract and stores the resulting data. The device used for playback would take these values and reconstruct the sound on the fly. I managed to find on TI's website the data sheet for the TSP50Cx device. I used this in lots of toys in the 80's-90's. This was fun hi-tech stuff back then. One of the really amusing aspects of working with LPC is that because it models the human voice it doesn't do sound effects very well. Lot's of people earned their bread and butter (myself included) by figuring out ways to "bend it" to our will (huh, now that I think of it, we were doing "circuit-bending" way back when :roll: )... anyway, to do a sound effect you would get someone to mimic the sound. Elephants, dogs, cats were actually a guy making those sounds; not the actual recording! You could spend days tweaking the sound to get it just right.
Once memory became cheap (literally over night) there were lots of algorithms that could be used and using things like LPC didn't make sense anymore. Here's the link for the data sheethttp://focus.ti.com/lit/ml/spss011d/spss011d.pdf. Have a look at the LPC Model. Looking at the block diagram I'd be willing to bet someone clever could adapt this to be used on the SPN1001. Maybe the guitar signal is the energy component? Thinking about this has now given me a headache I haven't missed since 1992... :lol: :lol: :lol:
livingston
Posts: 131
Joined: Sun Nov 15, 2009 3:37 pm
Location: New Orleans, LA US

Post by livingston »

Very interesting! I just looked into LPC, quite intriguing. I have a feeling that we are only scratching the surface of the FV-1 doing relatively rudimentary things like sine waves and filters. I think you're right that digging through some of these obsolete concepts like LPC will lead to some exciting ideas in audio processing. I like the idea of recycling discarded ideas - the ones that have becomes unnecessary for industrial purposes can now be used for artistic purposes.
donstavely
Posts: 53
Joined: Thu Jan 07, 2010 2:29 pm
Location: Windsor, Colorado

Re: guitar input - pure sine and/or square output

Post by donstavely »

jovesdies wrote:Hi,
is there the possibility to obtain a pure (without harmonics) sine wave or/and square wave output from FV1 with a guitar input?
Let me explain (If I can...) : I play guitar through FV1 and I want to obtain the basic tone frequency without any harmonics in form of sine wave or square wave.
Thanks!
jovesdies, see the additions to the "Any thoughts on implementing an "infinite hold" effect" thread.
Don Stavely
Post Reply