Ringmodulator

Algorithm development and general DSP issues

Moderator: frank

stentor
Posts: 1
Joined: Mon Dec 01, 2008 4:02 pm

Ringmodulator

Post by stentor »

Have anyone a algorithm for a ringmodulator?
Keith
Posts: 9
Joined: Sun Oct 30, 2005 2:30 pm

Post by Keith »

To do a ring modulator, you need to multiply an input signal by an LFO.

The internal LFOs of the FV-1 are limited in frequency range, but this should work:

Start by initializing a SIN LFO:

skp run,endset
wlds sin0,0,32767 ;output = +/-1, freq = 0
endset

Then adjust the frequency with a pot:

rdax pot0,1
wrax sin0_rate,0

Now get the LFO into the accumulator:

cho rdal,sin0

Then multiply by the input signal:

mulx adcl

and output the result:

wrax dacl,0

If the LFO frequency is not high enough (and it probably won't be), you can make a snake-chases-tail oscillator. Start by defining two registers that will be used to generate sin and cos waves:

equ sin reg0
equ cos reg1

Then initialize the oscillator by setting one to xero and the other to -1; we do this just once, during the first cycle of operation:

skp run,endset ;do not execute if already running
wrax sin,0 ;set sin to 0, (acc should be zero)
sof 0,-1 ;set accum to -1
wrax cos,0 ;write to cos
endset: ;jump-to label

Now do the LFO, using pot0 as a control for frequency:

rdax sin,1 ;read the sin register
mulx pot0 ;multiply by pot value
rdax cos,1 ;read the cos register
wrax cos,-1 ;integrate the cos value, pass on *-1
mulx pot0 ;multiply by pot value
rdax sin,1 ;read sin reg
wrax sin,0 ;integrate the sin value

Either the sin or cos register will be producing sin waveforms (just shifted in phase), so either can be used as a modulation source. The maximum frequency of this LFO is Fs/2pi, which should be high enough!

I suggest producing a control value from the pot, to cause an exponential scaling of the modulation frequency. We will need to use a registe to contain the control value:

equ control reg2

Get the pot into the accumulator:

rdax pot0,1

Now scale the pot value so when it ranges from 0 to 1 the accumulator ranges -10/16 to 0:

sof 10/16,-10/16 ;multiply by 10/16, subtract 10/16

The exponential function will produce an output that is always less than 1. A zero input produces an (almost) 1 output, and a -10/16ths input will produce a value that is effectively 2^-10 (~0.001). Each -1/16th input represents a factor of two reduction in output value, which is always positive. We now exponentiate:

exp 1,0 ;exponent result times 1, add nothing

Then we write this to the control register:

wrax control,0

and use this value in our snake-chases-tail oscillator above. The range should be 10 octaves, from about 5Hz to 5KHz.
Alex MAK
Posts: 89
Joined: Fri Nov 05, 2010 1:00 pm

Post by Alex MAK »

Hi! The code I have does not work. I tried to change it, but it still does not work. Where to look for a mistake?

skp run,endset
wlds sin0,0,32767 ;output = +/-1, freq = 0


rdax pot0,1
wrax sin0_rate,0


cho rdal,sin0


mulx adcl


wrax dacl,0

equ sin reg0
equ cos reg1


skp run,endset ;do not execute if already running
wrax sin,0 ;set sin to 0, (acc should be zero)
sof 0,-1 ;set accum to -1
wrax cos,0 ;write to cos
endset: ;jump-to label


rdax sin,1 ;read the sin register
mulx pot0 ;multiply by pot value
rdax cos,1 ;read the cos register
wrax cos,-1 ;integrate the cos value, pass on *-1
mulx pot0 ;multiply by pot value
rdax sin,1 ;read sin reg
wrax sin,0 ;integrate the sin value




equ control reg2



rdax pot0,1


sof 10/16,-10/16 ;multiply by 10/16, subtract 10/16


exp 1,0 ;exponent result times 1, add nothing


wrax control,0
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

Please explain how it does not work, are you getting no output, a distorted output, something else?
Frank Thomson
Experimental Noize
Alex MAK
Posts: 89
Joined: Fri Nov 05, 2010 1:00 pm

Post by Alex MAK »

I tried to build a Hex code of Keith, gets a lot of mistakes. I remove the extra lines as indicated by the program is the code that I described on the wall. I'm trying to build, get this:

<0000>[ Pass 1] [ 1028] Line: 1 "Start by initializing a SIN LFO: " - ERROR:Whitespace in label - Start by initializing a SIN LFO:
<0001>[ Pass 1] [ 1031] Line: 1 "Start by initializing a SIN LFO: " - ERROR:FAILED On Pass - ONE


RingMod!!!.spn [FAILED BUILD] Build Stopped..
2 Log Messages
livingston
Posts: 131
Joined: Sun Nov 15, 2009 3:37 pm
Location: New Orleans, LA US

Post by livingston »

You already removed "start by initializing a sin LFO" but it still tells you that? That doesn't make sense. Can you post the exact full code you are assembling?
Alex MAK
Posts: 89
Joined: Fri Nov 05, 2010 1:00 pm

Post by Alex MAK »

Code: Select all

;Start by initializing a SIN LFO

skp run,endset
wlds sin0,0,32767 ;output = +/-1, freq = 0
;endset

;Then adjust the frequency with a pot

rdax pot0,1
wrax sin0_rate,0

;Now get the LFO into the accumulator

cho rdal,sin0

;Then multiply by the input signal

mulx adcl

;and output the result

wrax dacl,0

;If the LFO frequency is not high enough (and it probably won't be), you can make a snake-chases-tail oscillator. Start by defining two registers that will be used to generate sin and cos waves

equ sin reg0
equ cos reg1

;Then initialize the oscillator by setting one to xero and the other to -1; we do this just once, during the first cycle of operation

skp run,endset ;do not execute if already running
wrax sin,0 ;set sin to 0, (acc should be zero)
sof 0,-1 ;set accum to -1
wrax cos,0 ;write to cos
endset: ;jump-to label

;Now do the LFO, using pot0 as a control for frequency

rdax sin,1 ;read the sin register
mulx pot0 ;multiply by pot value
rdax cos,1 ;read the cos register
wrax cos,-1 ;integrate the cos value, pass on *-1
mulx pot0 ;multiply by pot value
rdax sin,1 ;read sin reg
wrax sin,0 ;integrate the sin value

;Either the sin or cos register will be producing sin waveforms (just shifted in phase), so either can be used as a modulation source. The maximum frequency of this LFO is Fs/2pi, which should be high enough!

;I suggest producing a control value from the pot, to cause an exponential scaling of the modulation frequency. We will need to use a registe to contain the control value

equ control reg2

;Get the pot into the accumulator

rdax pot0,1

;Now scale the pot value so when it ranges from 0 to 1 the accumulator ranges -10/16 to 0

sof 10/16,-10/16 ;multiply by 10/16, subtract 10/16

;The exponential function will produce an output that is always less than 1. A zero input produces an (almost) 1 output, and a -10/16ths input will produce a value that is effectively 2^-10 (~0.001). Each -1/16th input represents a factor of two reduction in output value, which is always positive. We now exponentiate

;and use this value in our snake-chases-tail oscillator above. The range should be 10 octaves, from about 5Hz to 5KHz.[code]

This error   :
<0000>[ Pass 1] [ 1025] Line: 26  "equ sin reg0 "  - ERROR:Name Exists as Reserved Word - SIN
<0001>[ Pass 1] [ 1025] Line: 26  "equ sin reg0 "  - ERROR:Name Exists as Reserved Word - SIN
<0002>[ Pass 1] [ 1025] Line: 27  "equ cos reg1 "  - ERROR:Name Exists as Reserved Word - COS
<0003>[ Pass 1] [ 1025] Line: 27  "equ cos reg1 "  - ERROR:Name Exists as Reserved Word - COS


RingMod!!!.spn   [FAILED BUILD]   Build Stopped..
4 Log Messages
livingston
Posts: 131
Joined: Sun Nov 15, 2009 3:37 pm
Location: New Orleans, LA US

Post by livingston »

Ok, here's why that fails. "sin" and "cos" are reserved words, so you're not allowed to equate them to a register. See the list of reserved words here:

http://www.spinsemi.com/knowledge_base/ ... rved_Words

Change sin and cos to "s" and "c" or "shlemiel" and "schlimazel" or "ren" and "stimpy".
Alex MAK
Posts: 89
Joined: Fri Nov 05, 2010 1:00 pm

Post by Alex MAK »

I changed the Sin and Cos, s and c . The device produces no sound.
equ s reg0
equ c reg1
livingston
Posts: 131
Joined: Sun Nov 15, 2009 3:37 pm
Location: New Orleans, LA US

Post by livingston »

That code writes to the left output, maybe you're trying to get sound out of the right output?
Alex MAK
Posts: 89
Joined: Fri Nov 05, 2010 1:00 pm

Post by Alex MAK »

That code writes to the left output, maybe you're trying to get sound out of the right output?
Alex MAK
Posts: 89
Joined: Fri Nov 05, 2010 1:00 pm

Post by Alex MAK »

The problem is still there :(
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

Alex MAK wrote:The problem is still there :(
Please post current code.
Frank Thomson
Experimental Noize
Alex MAK
Posts: 89
Joined: Fri Nov 05, 2010 1:00 pm

Post by Alex MAK »

;Start by initializing a SIN LFO

skp run,endset
wlds sin0,0,32767 ;output = +/-1, freq = 0
;endset

;Then adjust the frequency with a pot

rdax pot0,1
wrax sin0_rate,0

;Now get the LFO into the accumulator

cho rdal,sin0

;Then multiply by the input signal

mulx adcl

;and output the result

wrax dacl,0

;If the LFO frequency is not high enough (and it probably won't be), you can make a snake-chases-tail oscillator. Start by defining two registers that will be used to generate sin and cos waves

equ s reg0
equ c reg1

;Then initialize the oscillator by setting one to xero and the other to -1; we do this just once, during the first cycle of operation

skp run,endset ;do not execute if already running
wrax sin,0 ;set sin to 0, (acc should be zero)
sof 0,-1 ;set accum to -1
wrax cos,0 ;write to cos
endset: ;jump-to label

;Now do the LFO, using pot0 as a control for frequency

rdax sin,1 ;read the sin register
mulx pot0 ;multiply by pot value
rdax cos,1 ;read the cos register
wrax cos,-1 ;integrate the cos value, pass on *-1
mulx pot0 ;multiply by pot value
rdax sin,1 ;read sin reg
wrax sin,0 ;integrate the sin value

;Either the sin or cos register will be producing sin waveforms (just shifted in phase), so either can be used as a modulation source. The maximum frequency of this LFO is Fs/2pi, which should be high enough!

;I suggest producing a control value from the pot, to cause an exponential scaling of the modulation frequency. We will need to use a registe to contain the control value

equ control reg2

;Get the pot into the accumulator

rdax pot0,1

;Now scale the pot value so when it ranges from 0 to 1 the accumulator ranges -10/16 to 0

sof 10/16,-10/16 ;multiply by 10/16, subtract 10/16

;The exponential function will produce an output that is always less than 1. A zero input produces an (almost) 1 output, and a -10/16ths input will produce a value that is effectively 2^-10 (~0.001). Each -1/16th input represents a factor of two reduction in output value, which is always positive. We now exponentiate

;and use this value in our snake-chases-tail oscillator above. The range should be 10 octaves, from about 5Hz to 5KHz.
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

The code you are using is really a comparison of different ways of doing it and not fully functional. Here is a working version, needs work to sound good but is a starting point:

Code: Select all

;POT0 : Control frequency
;
equ s reg0
equ c reg1

;Then initialize the oscillator by setting one to xero and the other to -1
;we do this just once, during the first cycle of operation

skp run,endset ;do not execute if already running
wrax s,0 ;set s to 0, (acc should be zero)
sof 0,-1 ;set accum to -1
wrax c,0 ;write to c
endset: ;jump-to label

;Now do the LFO, using pot0 as a control for frequency

rdax s,0.02 ;read the s register, change this value between  0.001 and 1.0
mulx pot0 ;multiply by pot value
rdax c,1 ;read the c register
wrax c,-0.02 ;integrate the c value, this value MUST be the negative of
;what ever you set the value in 'rdax s,X' to above
mulx pot0 ;multiply by pot value
rdax s,1 ;read s reg
wrax s,1 ;integrate the s value

;Either the s or c register will be producing s waveforms (just shifted in
;phase), so either can be used as a modulation source. The maximum
;frequency of this LFO is Fs/2pi, which should be high enough!

mulx adcl

;and output the result

wrax dacl,0  
Frank Thomson
Experimental Noize
Post Reply