Clean Octave up and Pitch Shifter idea!

Started by alecacca, December 27, 2010, 03:33:52 PM

Previous topic - Next topic

alecacca

hello i'm alex,

i'm 19 and i've got an idea for a clean (but digital)  octave up last night.

it's digital so ADC and DAC are needed, it uses the most common method for pitch shifting:
 -   after sampled a frame of a signal with N samples, play it at double speed.

SO here i try to explain..     there are:
-  two RAMs, RAM1 and RAM2  
- a square wave got from squaring the foundamental of our guitar signal (we'll take the low to high edge of that squared wave and use it as a Start trigger)

this is how it works:
The St (start trigger) goes high when our wave is starting. in this moment we begin to convert the signal through the ADC at 44100 Hz and writing the samples on RAM1.
When our wave has made a revolution and the wave is going to repeat, we get another St high.
in that moment we stop writing the data on RAM1 and we continue writing on RAM2 instead.
now we have the previous wave recorded on RAM1 and all that we have to do is to read it and convert it at double speed (44100hz x 2, 88200hz) so once we have finished playing two times (and at double speed) the "old" wave we have also finished to write the "new" wave in the other RAM.

every high edge on St tell us to toggle the writing and reading process between the two RAMS.

if it works it's very cool cause it's polyphonic and if it's made with a PIC microprocessor can have changes to parameters!! :)


ah.. Sorry if i hadn't explained clearly, i know that my english is bad!!

tell me if it can work!!

Alex





jasperoosthoek

I always thought that this is how some Winamp pitch plugin worked. There are several, some work with Fourier transforms and maybe also with repeating samples.

It would work for sure but I don't know if it works without artifacts: The biggest problem IMO would be the glitch when you play the second time and the last and first sample are very different. Maybe you can just fade out and fade in. More experienced digital tinkerers are needed here.

You could do with one and a half times the memory instead of double: When you played the previous memory at double speed you only needed to record half of the new memory. Afterwards you can start to overwrite the memory you already played. But if you want to program this yourself you can start the easy way with two memories and elaborate once you've got it working. The last time I programmed a PIC was with an in situ programmer: http://www.voti.nl/wisp648/index.html I really like the idea that you can keep the PIC in the circuit and program it every 5 minutes  :icon_cool:.

Just my 1 cent.  :)
[DIYStompbox user name]@hotmail.com

Hides-His-Eyes

That requires frequency detection though, doesn't it?

What would give a pitch shift of an octave would be to record to both RAM banks simultaneously at 22kHz, say, but to then play back from alternating RAM banks at 44kHz.

Can the ram read and write simultaneously?

jasperoosthoek

Hmm wait a minute, if you record at 44100 Hz, all you have to do is take the average of two samples. As you play back at double speed you only need half the speed. Or, of course you can record at 22050 Hz but that might give you Nyquist artifacts. http://en.wikipedia.org/wiki/Nyquist_frequency

It's late here, I'm getting my third beer ;D.
[DIYStompbox user name]@hotmail.com

alecacca

Quote from: Hides-His-Eyes on December 27, 2010, 05:20:05 PM
That requires frequency detection though, doesn't it?

no, beacuse the reading and the writing process is timed by a signal that starts at every start of the wave.

Quote from: Hides-His-Eyes on December 27, 2010, 05:20:05 PM

What would give a pitch shift of an octave would be to record to both RAM banks simultaneously at 22kHz, say, but to then play back from alternating RAM banks at 44kHz.

Can the ram read and write simultaneously?

yes but i thought to use two different rams to have one writing and one reading in the same time to have a constant output signal.  :)

phector2004


PRR

#6
> the glitch when you play the second time and the last and first sample are very different

He's proposing to switch on "the fundamental of our guitar signal". I assume this is the Zero Crossings. Cutting between two samples both very-near zero, there is no "ACK!" glitch such as splicing random audio.

RAM can in/out at many MEGA Hertz. So there is no problem reading and writing at the "same time". Nor any reason to have "2 memories". Write byte 0001. Read byte 1001. Write byte 0002. Read byte 1002. When trigger happens: Write byte 1001. Read byte 0001.

Assuming guitar-band audio and 1MHz RAM, the RAM can be idle (waiting for next read/write) 98% of the time. Or if it actually takes time to change-over from read to write, 96% idle.

(BTW: the video memory for the PC monitor you are staring at does the same thing. It's constantly reading-out a >1MHz data stream to keep the monitor lit-up, and also accepting new data from the CPU decoding text to fonts or MPEG to a movie of kittens. We used to use "dual port RAM" with a front door and a back door; I think RAM got so fast that ordinary RAM worked fine much cheaper.)

Frequency detection is not needed. Read samples at say 10,000 per second. Playing A=220, you get 45.45 samples(!) and then a trigger. Output samples at 20,000 per second, 45.45 and 45.45 again.

Problems: ACCURATE period detection (guitar waves are not simple), and what do you do with a 0.45 sample?

The second problem may be reduced, maybe beyond audibility, by raising the sample rate and intelligently rounding-off the counts so the average error is small. This may mean pushing 1MHz RAM and looking into faster stuff. You may not be able to buy RAM as _slow_ as 1MHz today, though A/D-D/A converters may not be that fast and precise. Although at these rates there are 1-bit codes to give audio dynamic range. 82Hz at 1MHz sample rate requires 12K samples. Even taking 16-bit depth, you can't readily buy all-purpose RAM as small as 24KBytes.... 256KByte got so cheap it went out of style, you'll be paying a few bucks for many MegaBytes and ignoring the excess.

I have a feeling there is some annoying flaw, so that it "works" but is not pleasant. The basic idea is 50+ years old, though tape and BBDs could not be random-access so could not toggle at fundamental period. If there's no horrid flaw, someone must be using it.... too many people have held their nose to this grindstone to have missed something this elegant. That does not mean you can't re-invent it for yourself.
  • SUPPORTER

alecacca

thank you for the reply!
initially i was thinking to this project in a more easier way (8 bit architecture to get it working with a pic16f877a) but obviusly reducing the quality..

i thought to use only one memory and switching two "banks" by toggling the MSB of the address bus, but ignorantly i preferred the more easier way :)

mmmm....it's possible to making it work using 48K or faster sample rates and increasing speed and memory still making a not so difficoult project for a normal DIYer?
(this was what i was thinking to do..)

there is a pic with enough memory? and if not.. is faster enough to have and external memory interfaced in I2C? that would reduce the complexity of the circuit.  :)






jasperoosthoek

I just googled the 18F series and the PIC18F4550 should be up for the job. 2048 bytes of memory should work. Say your minimum frequency is 50 Hz and you sample at 48kHz you would need about a thousand samples BUT you only need to save half of them as you play back at the same speed. Playback at 96kHz is useless. Every two samples are averaged or you have to have a good 24kHz low pass filter.

So you need 2x500x16bits = 2000 bytes ;D.
[DIYStompbox user name]@hotmail.com

alecacca


aaaaah cool! It can work but are you sure that you can manage 16 bits with that pic?  reading the datasheet it has only 8 bits ports and all the istructions works with   0<f<255 ...  i'm wrong? or are you thinking to use two separate variables for a single sample?

jasperoosthoek

I sampled a dual 24bit ADC with that or a very similar 18F PIC ;D.

Indeed, 16 bits are two bytes in the memory. The instructions are 8 bit but you can always manipulate 16 bit numbers by dividing up the 16 bit.

Say you want to add two 16 bit numbers. First add the lower 8 bits of the two numbers and store it in the lower part of the result. If the result is higher than 255 the so called carry flag is set. It's the ninth bit of the result.
Then add the upper 8 bits plus the carry. That's a separate instruction from normal addition. If the carry was set after the previous addition it will now automatically add a 1 extra. Then the result of this addition is the upper part of the total result.

But that's if you program in assembler. A C compiler or any other compiler will do those things for you.

These PICs are so fast that most of the time they will remain idle, so don't worry about the speed.
[DIYStompbox user name]@hotmail.com

alecacca

#11
cool.. but sampling the input signal at 22k doesn't mean that all frequencies above 11k are cancelled? doesn't affect the guitar timbre and quality?
sorry for the amount of questions..!  :icon_rolleyes:


EDIT:    at this point... if our processor can run so fast why don't we use a pic with 4k memory (PIC18F2515) and have more samples for a better quality?






jasperoosthoek

Sampling at 22kHz will only work because you play back at double speed. So in this particular case you can get away with it because the frequencies above 11k become supersonic.

Cool, you found a chip with 4k, that's even better ;D.
[DIYStompbox user name]@hotmail.com

PRR

Guitar does not need over 6KHz.

Anyway: get it to WORK, then make it fast/clean. The first pitch-shifter project I helped on (an early-production BBD) probably had nothing over 2KHz, but this was enough to show it worked. Back in the 1970s, we had to wait for larger BBDs. But in 30+ years the technology has expanded far-far beyond what we need.

I'd be inclined (just me) to demonstrate on PC. WAV-file of naked guitar. Write a little program to detect periods and zero-crossings. Take the samples within that period, discard every other sample, and write the samples to output twice. Repeat until done. Since it is not real-time, you can program in BASIC or other simple language, pause the program to see what it is doing, much easier than dedicated hardware.

I suspect the "quality" will deped a lot on the zero-crossing period-detection, not sample rate or depth.

  • SUPPORTER

alecacca

i've tried to simulate a simple adc--> PIC----> dac  conversion with proteus and multisim.. i'm found out i don't know how SOC EOC OE timing work beacuse the simulation was not going well.. sorry (if someone has a link for a tutorial on how to interface a dac/adc with a pic please tell me :D )..

what software do you use to simulate?

Jazznoise

I'd also advise removing very high frequency components - maybe from 6-8 Khz. You don't want or need anything that high getting doubled.

What about hard clipping, dual rectifying the signal and using the rising edge to trigger the next octave up part if the circuit? It might be a little innacurate but it puts the signal in a language digital systems understand!
Expressway To Yr Null