Stupid questions. For beginners.

Algorithm development and general DSP issues

Moderator: frank

Alex MAK
Posts: 89
Joined: Fri Nov 05, 2010 1:00 pm

Stupid questions. For beginners.

Post by Alex MAK »

I want to ask my first stupid question in this top.
Not all effects are equal in volume. Is it possible to write a piece of code? Find the right rates? To the output signal is equal to the input signal. How to do it? How do I apply this code to any effect?
livingston
Posts: 131
Joined: Sun Nov 15, 2009 3:37 pm
Location: New Orleans, LA US

Post by livingston »

Think of the signals inside the FV1 as numbers, from -1 to 1. If you think about an analog audio signal, that looks like this:

http://t1.gstatic.com/images?q=tbn:ANd9 ... rugL_FbYkg

The line down the middle is "0" inside the FV1. The very top of the graph is "1" and the bottom is "-1". So for every audio cycle, it's a series of numbers :

0, 0.1, 0.2, 0.3....1, 0.9, 0.8, 0.7... 0, -0.1, 0.2...

Ok, so let's say we have an audio signal that is too quiet. Inside the FV1, this will be like a series of number that swings between (for example) -0.2 and 0.2. What we want to do is make the swing bigger. So we multiply by 2.

What that means is that, for every number in the FV1, we multiply that number times 2. Before it was

-0.2..........0.2

multiply everything by 2 and we get

-0.4..........0.4

Twice as loud. In the FV1, we use the "SOF" opcode to add or multiply.

So let's say you have a signal in a register called "QUIET", and you want it to be almost twice as loud. You would then want to

Code: Select all

RDAX    QUIET,1    ;read in the register called "QUIET", at full volume.
SOF         1.99,0       ;multiply the signal by 1.99, add 0 - for technical reasons you can't actually multiply by 2, you must use 1.99
WRAX      ADCR,0    ;write the louder signal to the output, clear the accumulator
If you want to get more than that amount of gain, you can use several SOF statements in a row.

Code: Select all

RDAX    QUIET,1    ;read in the register called "QUIET", at full volume.
SOF         1.99,0       ;multiply the signal by 1.99 - for technical reasons you can't actually multiply by 2, you must use 1.99
SOF         1.99,0
SOF         1.99,0
SOF         1.99,0
WRAX      ADCR,0    ;write the louder signal to the output, clear the accumulator
This gives us 1.99x1.99x1.99x1.99=15.68 times the volume. If you are careful to always use an even number of SOFs, you can get slightly more gain with the same number of instructions by multiplying by negative 2.

Code: Select all

RDAX    QUIET,1    ;read in the register called "QUIET", at full volume.
SOF        -2,0       ;multiply the signal by 1.99 - for technical reasons you can't actually multiply by 2, you must use 1.99
SOF         -2,0
SOF        -2,0
SOF         -2,0
WRAX      ADCR,0    ;write the louder signal to the output, clear the accumulator
This gives us 2x2x2x2=16 times the volume.

It's also possible to use recursive gain to get more gain with fewer instructions, but I haven't used this, hopefully somebody else will chime in. I really recommend the knowledge base. It is written very well for people who are trying to understand how all of this works. I have no formal DSP training and the information there helped me a lot.
Alex MAK
Posts: 89
Joined: Fri Nov 05, 2010 1:00 pm

Post by Alex MAK »

We need to change a piece of the finished code, or to append a new piece of code to set?
Alex MAK
Posts: 89
Joined: Fri Nov 05, 2010 1:00 pm

Post by Alex MAK »

Tell me please how to edit codes. I want to understand the essence. How can I build the code to pieces with ready-codes? For example:


delayd mem 4096 ; Down delay
temp mem 1 ; Temp location for partial calculations
;
skp run,START

;
wldr RMP0,16384,4096
wldr RMP1,-8192,4096
;
START: ldax ADCL
; Write it to left delay and clear ACC
wra delayd,0
; Read in left
ldax ADCL
;
wra delayd,0
;
cho rda,RMP0,REG|COMPC,delayd
cho rda,RMP0,,delayd+1
wra temp,0
cho rda,RMP0,RPTR2|COMPC,delayd
cho rda,RMP0,RPTR2,delayd+1
cho sof,RMP0,NA|COMPC,0
cho rda,RMP0,NA,temp
mulx POT1
wrax REG0,0
;
cho rda,RMP1,REG|COMPC,delayd
cho rda,RMP1,,delayd+1
wra temp,0
cho rda,RMP1,RPTR2|COMPC,delayd
cho rda,RMP1,RPTR2,delayd+1
cho sof,RMP1,NA|COMPC,0
cho rda,RMP1,NA,temp
MULX POT2
wrax REG1,0
;
ldax ADCL
mulx POT0
rdax REG0,1.0
rdax REG1,1.0
wrax DACL,1.0
wrax DACR,0


Code Octaver. I want to add reverb. Lowering the octave and reverb should be governed by one POT together. Perhaps then the octave will be replaced by another one, reverb will be replaced by a chorus / flanger and more. I want to get a sitar emulator :)
livingston
Posts: 131
Joined: Sun Nov 15, 2009 3:37 pm
Location: New Orleans, LA US

Post by livingston »

What I think is best is for you to read the knowledge base some more. There's more info there than we can cover in a thread.

Here's some homework for you. This is how I began understanding how programs work. Once you understand these parts, you will begin to be able to read code and understand the structure of the effect.

1. What does "RDAX" do?
2. What does "WRAX" do?
Alex MAK
Posts: 89
Joined: Fri Nov 05, 2010 1:00 pm

Post by Alex MAK »

I did not understand English. Even worse technical English. I find it easier to take parts of information, get answers to questions.

For the job thanks! I will understand and delve in parts. In the near future will give the answer, as I understand it :)

"RDAX" Start reading before any
"WRAX" willingness to use

If this is correct, is ready to begin a new job:)
livingston
Posts: 131
Joined: Sun Nov 15, 2009 3:37 pm
Location: New Orleans, LA US

Post by livingston »

Are you using computer translations into English? Like Babelfish, Google translate, etc? It's sometimes difficult to understand your responses so it's harder for me to help.

To get better at modifying programs, start with a simple goal. For example, you said that sometimes you have a program that is too quiet. Post the program and I will guide you through the process of adding more volume to the program.
Alex MAK
Posts: 89
Joined: Fri Nov 05, 2010 1:00 pm

Post by Alex MAK »

Yes, I'm using Google translator. I will try to formulate his idea is simple and clear. Now I want to deal with the tone control. What is needed for this code? How to properly insert into the body of the program?
livingston
Posts: 131
Joined: Sun Nov 15, 2009 3:37 pm
Location: New Orleans, LA US

Post by livingston »

Are you familiar with designing analog distortion circuits? There are many different useful tone controls for a distortion. The simplest and most common is a single-pole lowpass filter. Here is one by Frank:

Code: Select all

rdax   adcl,1.0  ; Read ADC left 
rdax   lp_filt,-1.0 ; ADCL - lp_filt 
mulx   pot0 ; * C (POT0 in this case) 
rdax   lp_filt,1.0 ; +lp_filt 
wrax   lp_filt,1.0; write result to lp_filt 
wrax   dacl,0 ; write to DAC left
Post the program you want to add it to and I will show you how to do it.
Alex MAK
Posts: 89
Joined: Fri Nov 05, 2010 1:00 pm

Post by Alex MAK »

Thank you! With analog circuits, I know :) . How to add it, for example here?
equ tovrx reg0
equ sigin reg1
equ lf1 reg2
equ lf2 reg3
equ lf3 reg4
equ lf4 reg5

rdax adcl,1 ;read input signal
log -1,-3/16 ;coefficient is the LOG version of threshold ! ! !
exp 1,0 ;provides t/X
wrax tovrx,1 ;save t/X, we'll need it later...
mulx tovrx ;(t/X)^2
rdax tovrx,-2 ;inverts multiplicand, which will invert phase
mulx adcl ;multiply by the input signal
rdax lf1,0.75 ;restore gain and filter
wrax lf1,1 ;output in ACC and lf1

log -1,-3/16 ;coefficient is the LOG version of threshold ! ! !
exp 1,0 ;provides t/X
wrax tovrx,1 ;save t/X, we'll need it later...
mulx tovrx ;(t/X)^2
rdax tovrx,-2 ;inverts multiplicand, which will invert phase
mulx lf1 ;multiply by the input signal
rdax lf2,0.75 ;restore gain and filter
wrax lf2,1 ;output in ACC and lf2

log -1,-3/16 ;coefficient is the LOG version of threshold ! ! !
exp 1,0 ;provides t/X
wrax tovrx,1 ;save t/X, we'll need it later...
mulx tovrx ;(t/X)^2
rdax tovrx,-2 ;inverts multiplicand, which will invert phase
mulx lf2 ;multiply by the input signal
rdax lf3,0.75 ;restore gain and filter
wrax lf3,1 ;output in ACC and lf3

log -1,-3/16 ;coefficient is the LOG version of threshold ! ! !
exp 1,0 ;provides t/X
wrax tovrx,1 ;save t/X, we'll need it later...
mulx tovrx ;(t/X)^2
rdax tovrx,-2 ;inverts multiplicand, which will invert phase
mulx lf3 ;multiply by the input signal
rdax lf4,0.75 ;restore gain and filter
wrax lf4,1 ;output in ACC and lf1

wrax dacl,0
livingston
Posts: 131
Joined: Sun Nov 15, 2009 3:37 pm
Location: New Orleans, LA US

Post by livingston »

Ok, here's what I did to start understanding programming. Look at the code like "building blocks". To start, you don't need to understand what every piece of code does, but just understand the blocks. Just like in an analog distortion, we would have something like this:

input - clipping/distortion - tone control - volume control - output

Here is the basic distortion building block in the code you posted:

Code: Select all

rdax    adcl,1    ;read input signal
log    -1,-3/16    ;coefficient is the LOG version of threshold ! ! !
exp    1,0    ;provides t/X
wrax    tovrx,1    ;save t/X, we'll need it later...
mulx    tovrx    ;(t/X)^2
rdax    tovrx,-2    ;inverts multiplicand, which will invert phase
mulx    adcl    ;multiply by the input signal
rdax    lf1,0.75    ;restore gain and filter
wrax    lf1,1    ;output in ACC and lf1
You can see from looking at the code that it's just this block, copied several times, then it writes to the output. So let's make a block diagram showing what this code does:

input [rdax adcl,1] - distortion - distortion - distortion - distortion - output[wrax dacl,0]

We want to put the tone control after the distortion, to turn down some of the harmonics and make it "smoother". So the block diagram should look like

input - distortion - distortion - distortion - distortion - tone control - output

Look at the code and try to find the spot that connects the last distortion stage to the output.

Alex MAK wrote: equ tovrx reg0
equ sigin reg1
equ lf1 reg2
equ lf2 reg3
equ lf3 reg4
equ lf4 reg5
equ lp_filt reg6 ;we need to add this register because thet tone control we are using expects this register to exist

rdax adcl,1 ;read input signal
log -1,-3/16 ;coefficient is the LOG version of threshold ! ! !
exp 1,0 ;provides t/X
wrax tovrx,1 ;save t/X, we'll need it later...
mulx tovrx ;(t/X)^2
rdax tovrx,-2 ;inverts multiplicand, which will invert phase
mulx adcl ;multiply by the input signal
rdax lf1,0.75 ;restore gain and filter
wrax lf1,1 ;output in ACC and lf1

log -1,-3/16 ;coefficient is the LOG version of threshold ! ! !
exp 1,0 ;provides t/X
wrax tovrx,1 ;save t/X, we'll need it later...
mulx tovrx ;(t/X)^2
rdax tovrx,-2 ;inverts multiplicand, which will invert phase
mulx lf1 ;multiply by the input signal
rdax lf2,0.75 ;restore gain and filter
wrax lf2,1 ;output in ACC and lf2

log -1,-3/16 ;coefficient is the LOG version of threshold ! ! !
exp 1,0 ;provides t/X
wrax tovrx,1 ;save t/X, we'll need it later...
mulx tovrx ;(t/X)^2
rdax tovrx,-2 ;inverts multiplicand, which will invert phase
mulx lf2 ;multiply by the input signal
rdax lf3,0.75 ;restore gain and filter
wrax lf3,1 ;output in ACC and lf3

log -1,-3/16 ;coefficient is the LOG version of threshold ! ! !
exp 1,0 ;provides t/X
wrax tovrx,1 ;save t/X, we'll need it later...
mulx tovrx ;(t/X)^2
rdax tovrx,-2 ;inverts multiplicand, which will invert phase
mulx lf3 ;multiply by the input signal
rdax lf4,0.75 ;restore gain and filter
wrax lf4,1 ;output in ACC and lf1


;here is where we add the tone control!
rdax lp_filt,-1.0 ; ADCL - lp_filt
mulx pot0 ; * C (POT0 in this case)
rdax lp_filt,1.0 ; +lp_filt
wrax lp_filt,1.0; write result to lp_filt


wrax dacl,0
Alex MAK
Posts: 89
Joined: Fri Nov 05, 2010 1:00 pm

Post by Alex MAK »

Thank you! This part I understand. What are these pieces of code?
equ tovrx reg0
equ sigin reg1
equ lf1 reg2
equ lf2 reg3
equ lf3 reg4
equ lf4 reg5
equ lp_filt reg6
Alex MAK
Posts: 89
Joined: Fri Nov 05, 2010 1:00 pm

Post by Alex MAK »

I want to create a code sitar emulator. Can you help me? I suggest a block diagram of the algorithm: Input => +1 octave => (+ 2 octave; reverb) => output. An +1 octave (POT2max = 2 input) should be mixed with clean sound. Reverb (POT0) should work with only +2 octave. +2 octave (POT1max = 2 input) should be mixed with clean sound. I see it. I want to know how you see.

Octaver code you can use this:

delayd mem 4096 ; Down delay
temp mem 1 ; Temp location for partial calculations
;
skp run,START

;
wldr RMP0,16384,4096
wldr RMP1,32767,4096
;
START: ldax ADCL
; Write it to left delay and clear ACC
wra delayd,0
; Read in left
ldax ADCL
;
wra delayd,0
;
cho rda,RMP0,REG|COMPC,delayd
cho rda,RMP0,,delayd+1
wra temp,0
cho rda,RMP0,RPTR2|COMPC,delayd
cho rda,RMP0,RPTR2,delayd+1
cho sof,RMP0,NA|COMPC,0
cho rda,RMP0,NA,temp
mulx POT1
wrax REG0,0
;
cho rda,RMP1,REG|COMPC,delayd
cho rda,RMP1,,delayd+1
wra temp,0
cho rda,RMP1,RPTR2|COMPC,delayd
cho rda,RMP1,RPTR2,delayd+1
cho sof,RMP1,NA|COMPC,0
cho rda,RMP1,NA,temp
MULX POT2
wrax REG1,0
;
ldax ADCL
mulx POT0
rdax REG0,1.0
rdax REG1,1.0
wrax DACL,1.0
wrax DACR,0
livingston
Posts: 131
Joined: Sun Nov 15, 2009 3:37 pm
Location: New Orleans, LA US

Post by livingston »

Alex MAK wrote:Thank you! This part I understand. What are these pieces of code?
equ tovrx reg0
equ sigin reg1
equ lf1 reg2
equ lf2 reg3
equ lf3 reg4
equ lf4 reg5
equ lp_filt reg6
This is where you define the names for registers. When working with code, you have to write results to a register so that you can clear the accumulator and do more operations. Then later on you can read the register back in.

So you can think of a register as a save point where you can save a number for later use.

If you want, you can just use "REG0", "REG1", etc. in code, but it makes it easier to keep track of thing if you use names.
livingston
Posts: 131
Joined: Sun Nov 15, 2009 3:37 pm
Location: New Orleans, LA US

Post by livingston »

Alex MAK wrote:I want to create a code sitar emulator. Can you help me? I suggest a block diagram of the algorithm: Input => +1 octave => (+ 2 octave; reverb) => output. An +1 octave (POT2max = 2 input) should be mixed with clean sound. Reverb (POT0) should work with only +2 octave. +2 octave (POT1max = 2 input) should be mixed with clean sound. I see it. I want to know how you see.
Find the output of the second octave, then find a reverb code you want to use (check the spin website for "free DSP programs".

Reg1 is the second octave output. Take your reverb code, find the part where it loads the ADC in, and replace that with RDAX REG1,1
Post Reply