340 likes | 617 Views
Electric Guitar Digital Effects Processor. By Eric Sun. Famous Electric Guitarists. What do they have in common?. Long Hair Enjoyed smoking They all used audio effects! Common Audio Effects Distortion Reverb Delay Flange . An E. Guitar Signal Chain. How Digital Audio Works.
E N D
Electric Guitar Digital Effects Processor By Eric Sun
What do they have in common? • Long Hair • Enjoyed smoking • They all used audio effects! Common Audio Effects • Distortion • Reverb • Delay • Flange
Interesting Facts • Sampling Rate: 48.828kHz • Samples signify amplitude and nothing else • Sampling rate is usually 44.1 kHz • Guitars are fun
How to Record and Play Data • Determine what to record. • We want to record data from the left channel only because guitars have mono outputs. • The plugs on mono cables use the left contact point for the signal, and the right contact point is eliminated. • Use two clock signals, SCLK and LRCK • SCLK = 3.125MHz • LRCK = 48.828MHz (sampling rate) • SCLK “ticks” 64 times for every tick of LRCK.
How to Record and Play Data Continued • When LRCK = 0, data can be retrieved from the left channel. • When LRCK = 1, data can be retrieved from the right channel. • So when LRCK = 0, we retrieve 1 bit per tick of the SCLK from the audio port. RAM is 16 bits wide, so we only retrieve 16 bits, even though the stereo codec on the board outputs 20 bits. The least significant bits are ignored.
How to Record and Play Data Continued • 16 bits = 16 ticks. • Then we write those 16 bits of data to a location in RAM. This takes 1 tick. • We could do more, but instead we stall for about 47 ticks until LRCK = 1. • Now it’s time to read in the right side data. • But the guitar is mono! Therefore, instead of reading in data from the audio port, we read data from memory.
How to Record and Play Data Continued • We read data from the same address at which we wrote to earlier. • Then we send the data one bit at a time to the audio output port. • Conclusion: Data that is inputted and written to memory is read from memory and sent back out within microseconds. • Afterwards, we increment the read and write addresses before we process more data. We read in more data from the audio port when LRCK = 0 again.
Delay • What is delay? • Airports have delays. • However, delays can be cool when applied as an audio effect.
Delay What is audio delay good for? • Echo • Reverb • Flange • We previously noted that the output happens almost simultaneously with the input. This is because we read data from the same RAM address as what we just wrote to. Therefore, there is no delay.
Delay • However, if we read from an address that is less than the address at which we just wrote to, there is a slight delay. • We sample data with LRCK at 48.828kHz, and we increment the addresses once with every tick. Therefore the time difference between the data samples at each address is 22us. • If I play something on the guitar, write the data to address 2, and read from address 1, we will have to wait until LRCK ticks again before we hear what I played. That is a 22us delay.
Delay For good effects, we can use many different addresses. • recordAddr <= "0000100000000000000"; • playAddr <= "0000100000000000000"; -- 0ms delay • delayAddr1 <= "0000011111111111111"; -- 5ms delay • delayAddr2 <= "0000011111011111111"; -- 10ms delay • delayAddr3 <= "0000011110111111111"; -- 15ms delay • delayAddr4 <= "0000011101111111111"; -- 20ms delay • delayAddr5 <= "0000011101011111111"; -- 25ms delay • delayAddr6 <= "0000011100111111111"; -- 30ms delay • delayAddr7 <= "0000011100011111111"; -- 35ms delay • delayAddr8 <= "0000011011111111111"; -- 40ms delay • delayAddr9 <= "0000011011011111111"; -- 45ms delay • delayAddr10 <= "0000011010111111111"; -- 50ms delay • delayAddr11 <= "0000011010011111111"; -- 55ms delay • delayAddr12 <= "0000011001111111111"; -- 60ms delay • delayAddr13 <= "0000011001011111111"; -- 65ms delay • delayAddr14 <= "0000011000111111111"; -- 70ms delay • delayAddr15 <= "0000011000011111111"; -- 75ms delay
Echo • In order to add echo, we simply read data from 0ms address, read again from the 75ms address, and add them together. • Reading from memory only takes 1 tick of SCLK, and exporting data to the audio port takes 16 ticks. • Therefore, it is possible to read up to 48 delay samples before we need to write to memory again.
Reverb • In order to create reverberation, which adds a concert hall effect, we add SEVEN delay signals, from 5ms, 10ms, 20ms, 30ms, 45ms, 60ms, and 75ms to the original.
Flange • Flange is similar to echo. However, the delay must oscillate between 0 and 75ms at a frequency of 0.5Hz. • 0.5Hz at 48.828kHz = 97656 ticks of the LRCK • We have 15 addresses from 0-75ms delay, so to go from 0 to 75ms and back, we will go through 29 address changes. • 97656/29 = ~3368 ticks of LRCK per address. • With every 3368 ticks, we change delay addresses.
Distortion • Distortion can be done by modeling this analog circuit.
Distortion • In order to simulate that, we must use these equations.
Distortion • The dog feels my pain. “arooooo”
Distortion • Homer does too
Distortion • I don’t know how to divide by floating point numbers in VHDL. • Solution: use a less-musical method that still achieves distortion. • Full-Wave rectification can do this!
Distortion • What is full wave rectification?
Distortion How to rectify the signal (it is very simple) • Observe each piece of data that is ready to be exported to the audio port. • All data is in Two’s Complement form. • If most significant bit is 1, invert each of the 16 bits. • You can add one if you want, but it won’t make a difference to a 16 bit integer.
VHDL Implementation • I rewrote the entire thing because I was being unsuccessful at hacking the University of Queensland audio project. • I used three files…. • effectstop – top level structural description that linked the effects unit to the SRAM interface • effects – all of the audio processing was contained in this file • Sram interface – I only used the left bank, and I used the file from the University of Queensland website.