Author Topic: DSPIC30F flanger  (Read 3698 times)

0 Members and 1 Guest are viewing this topic.

multrak

DSPIC30F flanger
« on: May 29, 2007, 11:45:08 PM »
Hi, I found this site & fealt like I was coming in from the cold, great stuff -learned a lot just surfing for an hour. I had built a digital delay circuit for my guitar / piano & mic and started wanting to develope my own effects experimenting with DSP. A couple years ago I was coding JAVA for MIDI but got bored with it, but think I've found something now to keep my interest for a while. I just completed a PIC circuit using a dspic30f4011 and coded it for flanging effect. I built a simple R2R ladded for the DAC and used a quad op amp for the alaising filter and impedence matching. It uses the 10 bit ADC onboard, which is output thru 2 ports (B&C), and a circular buffer that varies in length by values generated by the low frequency oscillator implemented in code (LFO). It sounds good, though needs a little filtering on the output due to quantization noise. I share the code with you here in hopes that someone else has gone down this road and has other ideas - like code for chorus, compression, envelope generator.... Please let me know. Thanks,  Pat
.equ  __30F4011, 1
#list P=30f4011
#include "p30f4011.inc"
#include "p30f4011.gld"
.global    __reset   
.equ   __reset, code_base                                   
code_base:
    mov      #0x1fff, w0      ;portC, bits 13 & 14 = ADout 8 & 9
    mov      w0,   TRISC
    mov      #0xfe01, w0       ;portB rb0 = ADin, bits 1 - 8 = ADout 0 - 7
   mov      w0,   TRISB      
   mov      #0x00e6, w0     ;int unsigned,autoconvert, autostart samp after conv
   mov      w0,  ADCON1           
   mov      #0x0501, w0     ;avdd,ss ref,ch0 & ch1,1 16 word buf, use muxA, scan input(s?)
   mov      w0,  ADCON2      
   mov      #0x0005, w0      ;2 Tad,system clock, 6 tCY
   mov      w0,  ADCON3         
    clr      ADCHS            ;+ch0 & ch1=AN0, -ch0 & ch1 = AVref
    mov      #0x01fe, w0         
    mov      w0,  ADPCFG      ;AN0 is analog in, AN1-->AN8 dig i/o
    mov      #0x0001, w0         
    mov      w0,  ADCSSL      ;Scan only AN0
    mov      #0xffff, w4      ;flag hi
    mov      #0x0000, w6      ;flag lo
    mov      #0x0b00, w7      ;buff hi
    mov      #0x0900, w8      ;buff lo
    mov      #0x0800, w9      ;buff start
    mov      w9,      w0      ;init buffer pointer
    mov      w4,      w5      ;init direction flag
    mov      #0x0a00, w3      ;init buffer limit
   bset     ADCON1,  #0xf    ;Start A/D conversion
main:
   btss     ADCON1,  #0x0    ;Wait for conversion to complete
   goto,    main             ;go back & wait or skip ahead
    mov     0x280,   w1      ;get result from buf0
    sl       w1, #1,  w1
    mov      w1,  [w0++]      ;write result to buffer & increment pointer
    mov      [w0], w2         ;get old result
    add      w2, w1,  w1      ;add to new result
    mov      w1,   0x2c8      ;write bits <7:0> portB <8:1>
   sl       w1, #4,  w1      ;shift left 5 bits
   mov      w1,   0x2CE      ;write bits <10:9> portC <14:13>
   cpslt    w0,      w3      ;end of buffer? 
    goto     LFO              ;yes - reinit
    goto     main
LFO:
    cpsne    w5,      w4      ;check direction flag
    goto,    INCR             ;if hi 
DECR:
    dec      w3,      w3      ;dec buff limit
    cpsne    w3,      w8      ;check buff lim low
    goto     strincr          ;if yes, start inc
    mov      w9,      w0      ;if no, reinit pointr 
    goto,    main             ;go back
INCR:
    inc      w3,      w3
    cpsne    w3,      w7
    goto     strdecr
    mov      w9,      w0
    goto,    main
strincr:
    mov      w4,      w5       ;change buff limit direction
    goto,    INCR
strdecr:
    mov      w6,      w5
    goto,    DECR           
End:

RaceDriver205

Re: DSPIC30F flanger
« Reply #1 on: July 02, 2007, 09:05:23 PM »
How does that flange?

multrak

Re: DSPIC30F flanger
« Reply #2 on: July 10, 2007, 02:05:10 PM »
  Thanks for asking. Sorry I havn't been online to answer for a couple weeks - been camping.  The way this works is that the controller takes samples of an analog signal about 20, 000 times a second and writes it to consequetive memory locations via a buffer pointer that increments after each save. Then it takes the data stored at the next location, which is the "oldest" stored data, and adds it to the present data signal and outputs it. What this does is superimpose the signal stored about 30 ms ago onto the present signal. However, since the buffer length keeps changing (LFO), the phase between the two mixed signals keeps changing, which creates a "comb filter" by cancelling out frequencies which are 180 deg out of phase - and since the phase difference keeps changing, those frequencies being cancelled keep changing. This makes for the "whooshing" or flanging effect. The way this used to be done, in a studio, was to mix two identical tape recordings together, but have one of the tapes playing just a little bit faster while a person tapped their finger on the flange (Flanging) of the faster tape reel, slowing it incrementaly so that the faster tape reel never really gets more than a few hundred milliseconds ahead. Legend has it that the engineer George Martin developed this at a Beatles recording session.    Pat

notchboy

Re: DSPIC30F flanger
« Reply #3 on: July 10, 2007, 02:22:30 PM »
I think you mean Ken Townsend, who was an engineer at Abbey Road -- George Martin is/was a producer, not an engineer.  There's a pretty good Wikipedia article on the various claims of "who invented flanging" here:

http://en.wikipedia.org/wiki/Flanging

multrak

Re: DSPIC30F flanger
« Reply #4 on: July 10, 2007, 02:43:07 PM »
   Thanks for that  - I really wasn't sure, but I've always wondered who was behind the revolutionary sound inovations coming out of that studio back then - kind of knew it wasn't the musicians.