Variable bit depth

Algorithm development and general DSP issues

Moderator: frank

Post Reply
livingston
Posts: 131
Joined: Sun Nov 15, 2009 3:37 pm
Location: New Orleans, LA US

Variable bit depth

Post by livingston »

As part of a digital audio degradation effect, I want to simultaneously reduce sample rate, bit depth and dynamic range. The sample rate reduction (faked with a square wave ring modulator) and dynamics I have figured out, at least conceptually.

But I'm not sure how to have a pot-variable bit depth. I know it's possible to use AND to mask off bits, but can't yet think of a way to make this variable from max down to... maybe 1 or 2 bits. Anybody have any ideas?

I found this by Frank:
frank wrote:Here's a simple example, simply ANDing off the lower bits:

Code: Select all

crush equ 0xfc0000 ;define the bit mask - 6 bits here
clr
rdax adcl,0.5
rdax adcr,0.5
skp neg,invit; working with 2's comp numbers, if negative skip down
and crush
skp gez,outter
invit:
sof -1.0,0 ; for negative samples, invert them,
and crush ; mask the data
sof -1.0,0 ; invert it back
outter:
wrax dacl,1.0
wrax dacr,1.0
You could get fancier (use a POT input to determine mask, etc.)
Seems like maybe a MULX in there somewhere could do the job?
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

Since AND requires an immediate value and not a register, I was thinking using SKP to jump to the desired mask when I wrote that. So read the pot input, mask it to maybe 2 or 3 bits so it has 4 or 8 positions (each corresponds to a desired mask) then subtract an lsb, skp ZRO, subtract an lsb, skip zro, etc.
Frank Thomson
Experimental Noize
ZibiSound
Posts: 66
Joined: Fri Mar 15, 2013 3:02 pm

Re: Variable bit depth

Post by ZibiSound »

Hi Frank, forgive me a little offtopic, but I got a problem. Here's your code:

Code: Select all

equ	crush 	0xFC0000

clr
rdax 	adcl, 0.5
rdax 	adcr, 0.5
skp 	neg, invit	
and 	crush
skp 	gez, outter

invit:
sof 	-1, 0
and 	crush
sof 	-1, 0

outter:
wrax 	dacl, 1
wrax 	dacr, 0
There's no sound at output, at all :? When I comment the ";and crush", I got bypass signal at output, so there is a problem.
ice-nine
Posts: 192
Joined: Thu May 24, 2012 9:03 am

Re: Variable bit depth

Post by ice-nine »

I don't know if this will help you but it is a program published by 'Slacker' some time ago and it uses the pot SKP routine to select bit depth. It was shared public so I don't think Ian will mind me re posting posting it again.

Code: Select all

;Digifuzzer
;Pot0 - Sample rate reduction
;Pot1 - Bit depth reduction and digital distortion effects
;Pot2 - Volume

equ temp reg0
equ filter reg1
equ temp1 reg2

skp run,START
wldr rmp0,0.999,4096	;set up rmp0

START:

;Sample rate reduction

sof 0,0.999	
wrax rmp0_rate,0		;set speed of rmp0 
cho rdal,rmp0		;read value of rmp0
sof -2,0.999		;scale to 0 -1 ramp
sof 1, 0.003
rdax pot0,-0.026		;deduct value of POT0
skp neg,ENDSRR		;if negative skip to ENDSRR
jam rmp0		;else reset ramp1
ldax adcl			;read ADCL
sof -2,0			;boost
sof -2,0	
sof -2,0	
wrax temp,0		;write to temp
ENDSRR:

;bit manipulation

ldax temp
wrax temp1,1
skp gez,BM
sof -1,0
wrax temp1,0

BM:
ldax pot1
and %01110000_00000000_00000000
skp zro,SKIP
sof 1,-0.125 	
skp zro,SEVEN
sof 1,-0.125 	
skp zro,SIX
sof 1,-0.125 	
skp zro,FIVE
sof 1,-0.125 	
skp zro,FOUR	
sof 1,-0.125 	
skp zro,THREE
sof 1,-0.125 	
skp zro,TWO
 	
ONE:
ldax temp1
xor %10101010_10101010_10101010
sof 0.5,0
wrax temp1,0
skp zro,ENDBM

TWO:
ldax temp1
and %00000000_11111111_11111111
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
wrax temp1,0
skp zro,ENDBM

THREE:
ldax temp1
sof 1,-0.3
wrax temp1,0
skp zro,ENDBM

FOUR:
ldax temp1
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
and %01000000_00000000_00000000
wrax temp1,0
skp zro,ENDBM

SKIP:
skp run,ENDBM

FIVE:
ldax temp1
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
and %01100000_00000000_00000000
wrax temp1,0
skp zro,ENDBM

SIX:
ldax temp1
sof -2,0
sof -2,0
and %01111000_00000000_00000000
wrax temp1,0
skp zro,ENDBM

SEVEN:
ldax temp1
and %011111111_10000000_00000000
wrax temp1,0

ENDBM:

;uninvert

ldax temp
skp gez,NOISEGATE
ldax temp1
sof -1,0
wrax temp1,0

NOISEGATE:

ldax adcl
absa
rdfx filter, 0.0005
wrlx filter,-1
sof 1,-0.001
skp neg, FADE

ldax temp1
sof -0.5,0
mulx pot2
mulx pot2
wrax dacl,1
wrax dacr,0
skp zro, END

FADE:
ldax temp1
mulx filter
wrax dacl,0
wrax dacr,0

END:


www.stanleyfx.co.uk
"It's fairly straight forward, if you want to start it press start, you can work out the rest of the controls yourself."
ZibiSound
Posts: 66
Joined: Fri Mar 15, 2013 3:02 pm

Re: Variable bit depth

Post by ZibiSound »

Actually, the problem was too low input signal, but this code looks intresting too. Thank you :)
Post Reply