Aliaser

Algorithm development and general DSP issues

Moderator: frank

Post Reply
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Aliaser

Post by frank »

Some aliaser code I was working on for a new module program set but decided to share instead. Free to use in private and commercial pedals as long as you mention code (or original code if you mod it) was from OCT Distribution.

Code: Select all

; aliaser.spn
; Frank Thomson
; OCT Distribution
; (c) 2010 OCT Distribution
;
; Input: Left
; Output: Left
; POT0 : set "sample" rate
; POT 1 and POT2 not used
;
old	equ	reg0
new	equ	reg1
fptr	equ	reg2
temp	equ	reg3
temp2	equ	reg4
ptrmax	equ	1.1;  High sample rate, need to be just over 1.0 if we want no aliasing at high setting. 
ptrmin	equ	0.001; Low sample rate 

skp	run, start
clr
wrax	old,0
wrax	new,0
wrax	fptr,0

start:
clr
rdax	pot0,0.5
sof	ptrmax-ptrmin,ptrmin
rdax	fptr,1
wrax	fptr,1
sof	1,-0.5
skp	neg,interp
wrax	fptr,0
rdax	new,1
wrax	old,0
rdax	adcl,1.0
wrax	new,0
interp:
clr
rdax	new,1.0
mulx	fptr
wrax	temp,1
rdax	temp,1
wrax	temp,0
rdax	fptr,-1.0	
sof	1.0,0.5
wrax	temp2,0
rdax	old,1
mulx	temp2
wrax	temp2,1
rdax	temp2,1
rdax	temp,1.0	
wrax	temp2,1
absa
wrax	temp,0
;
rdax	temp2,1.0
skp	gez, gogo
clr
rdax	temp,1.0
sof	-1.0,0
wrax	temp,0
gogo:
clr
rdax	temp,1.0
wrax	dacl,1.0
wrax	dacr,0
Frank Thomson
Experimental Noize
Alex MAK
Posts: 89
Joined: Fri Nov 05, 2010 1:00 pm

Post by Alex MAK »

Frank, thank you for the code! He is very good;). But there is one observation. The effect is regulated very strongly at the beginning of the scale, and is not regulated further. Possible that the effect was regulated by full scale evenly?
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

Depending on the audio source (i.e. guitar) you may want to lower the value of ptrmax to something like 0.5 since a guitars range is only about 80Hz to 1.4KHz so you can lower the top sample rate much lower (even down to 0.25 may work OK) Just play with the value of ptrmax.
Frank Thomson
Experimental Noize
Alex MAK
Posts: 89
Joined: Fri Nov 05, 2010 1:00 pm

Post by Alex MAK »

Frank, thank you! Works as expected:). How to make "robot voice" was brighter against the background of pure guitar?
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

Alex MAK wrote:Frank, thank you! Works as expected:). How to make "robot voice" was brighter against the background of pure guitar?
The ring modulator would do better at a robot type voice, this does frequency aliasing due to intentional under sampling.
Frank Thomson
Experimental Noize
soundsubs
Posts: 24
Joined: Fri Feb 25, 2011 11:49 am

Post by soundsubs »

...would love to see this brought up again.

specifically, id like to reduce sample frequency rate and then bit depth after that. is this possible with the fv-1?
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

Just use an AND mask to limit bits.
Frank Thomson
Experimental Noize
Sweetalk
Posts: 141
Joined: Thu Oct 15, 2009 5:13 am

Post by Sweetalk »

This code is great, any explanation on the algoritm?.
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

Sweetalk wrote:This code is great, any explanation on the algoritm?.
It's been a long time since I wrote the code but basically I just use a counter to decide when to generate a sample. When I do generate a sample I interpolate between the latest ADC samples to create the final value.
Frank Thomson
Experimental Noize
Sweetalk
Posts: 141
Joined: Thu Oct 15, 2009 5:13 am

Re: Aliaser

Post by Sweetalk »

Bringing up an old thread!. I was looking at this code and can't get my head around the interpolation portion. I understand that between the pot and fptr you decide to take a new sample or not, but not how is interpolated to "fill the holes" between samples. Any thoughs? Maybe I'm missing something
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Re: Aliaser

Post by frank »

Well it has almost been 11 years since I wrote this but it looks like I am using fptr as an interpolation coefficient since it is updated every real sample period.
Frank Thomson
Experimental Noize
Sweetalk
Posts: 141
Joined: Thu Oct 15, 2009 5:13 am

Re: Aliaser

Post by Sweetalk »

frank wrote: Mon Oct 11, 2021 5:37 pm Well it has almost been 11 years since I wrote this but it looks like I am using fptr as an interpolation coefficient since it is updated every real sample period.
Yeah Frank, a long time, sorry to bring it up. Took me 9 years to check it out and read the code line by line :mrgreen: .

I drew a block diagram of the code to see what it does. There are some bits that confuses me, for example:

Code: Select all

rdax	new,1.0
mulx	fptr
wrax	temp,1
rdax	temp,1
wrax	temp,0
This is the begining of the interpolation part. You take the new sample, multiply it by fptr (interpolation coefficient) and save it to temp. So far so good. But you keep that on the acc and then add it again to temp. You're adding the new sample adjusted by the coef to itself, why?. You do that on the old sample as well with temp2.
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Re: Aliaser

Post by frank »

I would have to take time to really break it down but off the top of my head, when you do interpolations the base equation is:

A*x + B*(1-x)

Where x is the interpolation coefficient, but you can change the equation to:

A*x + B -B*x
or
(A-B)*x + B

which can be easier to code in some cases, no need for a "1.0", only 1 multiply, etc.
Frank Thomson
Experimental Noize
Sweetalk
Posts: 141
Joined: Thu Oct 15, 2009 5:13 am

Re: Aliaser

Post by Sweetalk »

Well, I finally got it sorted out. Ran a desk test, pen and paper and looked the evolution of the registers. fptr generates the "virtual clock" that takes samples and manages the interpolation part. It's a bit different from other algos with interpolation but it does the job really well.

With the temp register you make the interpolation part for the new sample. And then you use it again to save the absolute value of the interpolated signal.

The temp2 register acts first as the interpolation coeffiecient for the old sample and to save it once adjusted to that coefficient. Finnaly you save the final interpolated sample on it.

I'm curious about why you took the absa on the temp register. Then you check the sign of temp2 (with the interpolated sample) and flip the sign of temp (that got the absolute value of the inteprolated sample) to get the correct sign. Why don't use temp2 directly?
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Re: Aliaser

Post by frank »

Sweetalk wrote: Thu Oct 14, 2021 2:37 am I'm curious about why you took the absa on the temp register. Then you check the sign of temp2 (with the interpolated sample) and flip the sign of temp (that got the absolute value of the inteprolated sample) to get the correct sign. Why don't use temp2 directly?
No idea, it was 11 years ago so it may have been something left over from another idea, etc.
Frank Thomson
Experimental Noize
Post Reply