### Help building a frequency inverter/voice inverter?

Hi everyone!

Beginner-intermediate max user, no experience in gen.

Looking for a frequency inverter; also known as a voice inverter or voice scrambler.

I can’t seem to find one anywhere, so I decided to try to build one myself.

http://www.windytan.com/2013/05/descrambling-voice-inversion.html

This author seems to have come up with a pretty simple and clever means of getting frequency inverter.

How do I go about multiplying every other sample by -1 to achieve the frequency invert?

Hi

kind of intermediate myself here too, but my thoughts anyway:

you mention Gen, but I would guess that achieving this in the time domain would be quite tricky; have you any experience using fft~ in Max? i.e. doing it in the frequency domain. I quickly tried to phase shift an audio file using a simple pfft~, and failed – cuz my FFT chops are at best crap, so I won’t even embarrass myself by posting it here (I used cartopol~/poltocar~ and added PI to the phase outlet = no change at all).

Brendan

How do I go about multiplying every other sample by -1 to achieve the frequency invert?

In gen~, if that’s all you want to do, and you’re not worrying too much about what the author on that site wrote about "a sampling rate has to be chosen to (approximately) match the signal bandwidth", then the codebox can be as simple as this:

History n(1);

out1 = in1 * n;

n *= -1;

(edit: in my patch below i used ‘n = n * -1’ as i was just trying to be explicit to be absolutely sure of what i was doing, but it’s the same thing as, and is also possible in gen~ with, ‘n *= -1’)

Here’s a patch to demonstrate:

**all**of the following text. Then, in Max, select

*New From Clipboard*.

----------begin_max5_patcher---------- 1089.3ocyWssiaaCD8Y4uBA9TagWCQIesAEH8s9OrIvfRhVlanIEnn7Zmfzu 8xKhxT275jtnnOXIqY3kYNyLGN7ayB.o7K3JP3uG9bXPv2lEDXDoEDz7c.3D 5RFEUYFFnJiWh+avbqpJ4UJ1H2IIs9PE4qFYqW1HiUehvnXoYEhaDVhjYGIr h8BblzZAvX3hn4gwQlWvjn1WgetYVjbytwSe4IHzsmYHZVFulI6uq7Zoaaiz B+9rY5GyePekgeUsQtcQhuX1.PAlcG.vtmxqkXqSApHELDEz5BcPC3znQRrw 8WtV+JYqAYhm.Jh.i5zcVcrnwUa70.vABEeFKpHbl2nC.nxROwAdSQCPuvMK zl4shHLqn3VQB7Yha9IsRQBkOJUNXsv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LL -----------end_max5_patcher-----------

^In that patch, if you choose(within the ‘demosound’ bpatcher interface), the more musical sounds like drum beats or ‘sho…’ or ‘anton…’ it works to some extent, but if you choose the native-american talking(‘cherokee’), you’ll notice you can’t hear much, because we aren’t ‘matching the signal bandwidth’ of that particular sound very accurately here.

I might try to come back later with a more pfft~-oriented solution if i have time, that way you wouldn’t have to match the signal’s

spectrum-range/bandwidth, but for now, hope that makes sense and gets you started understanding how to do something similar in gen~.

It’s just a ring modulator (with modulator at Nyquist freq). No fft or gen magic needed.

You can achieve a kind of downsampled effect with `freqshift~`

and negative frequencies (mirrored spectrum).

**all**of the following text. Then, in Max, select

*New From Clipboard*.

----------begin_max5_patcher---------- 1882.3oc6assahiCF9Z3o.kKWwf7wX68YXuZucznJSvP8zPBShoS6LZ5y95C IgDJzFnsgptsRTR7wu+S9+fa+83QQyyuSUFM4um70IiF86wiF4ax0vnp2GEs VdWRprzOrnURc1CQSC8bqrHStVsqiux+VceYaWmu0jpL94gpZszbeZX70iqL QFZANCvfzpVCS0b+FU.bQk5UYxznoShzYlnIeqZbajljq0YqtpPkXBCEB4zY foSvD7L5zIHf6kXzLPyjrPSmUiLXMNz+J.CDupEcVxivkdgG74y+9WfDTTCJ JrrAip3JUlbdE4T2WgpTkYjFcd1QPo8KP0uZvXo7V0hqjFSgd9ViZ2SkUBmJ oiSHjtUkurt451aipz7rUGSP0YfkWmWX1ajvCNxZQC9.8oytUWpq4Cg9+y3w 69x+6+LdZO04J2XYaE4kI4aTObX8K3w0uxyxWa+LeURdZdQf6CZyym5DwML9 Go48jJabAws.Hh+KH.z70g01P6gpkcQEFxhILGphoDA.4dR3ZB1EjcTCwsI0 dn50fYu8QWL+wR5HDhKtzgbhRmFL+5HcxT+zhiZLXT242lnkEpeTdsdo4gIe gB.fS8T6m374pm5yQzPtvSjPjmjoOmboCikFcFriMox6S0klinnReADbmmbe VnSbxVYw88hYDy87BpWfiAOm+pN7h3n94swtGGxYyBoQtuakjT8llHCZ6WYT zRc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3mu.BEYa0U2SgkILtJsq8R9oofRxal MWuZkpHjRlknWJ2lZ5xoVlmYpuVnuNARZkLlJUsV4J6QqJKS.HNxWYYBAgIn vSwLLoakkcKaMPrb2+QZx2ka67UK0ooMqa6hkUmQbzpB4Bsc2qKzUTGXfD.n H1s4XffCHgmrM0s.2UyBVOMJGHDdLGC.j3vBHhicTzimFpob5H6HD9AiYPle 2PHrfw2aZxrUgrfQL1LtkAgP0csoHeSdQsBmkowIBZbyD2Zxan3cJb1oYZ.O gSgDOJ.nX.msaa2XZfJkJH.OcQioHHqoXO04oaEp9RL0gcRwHnf5lEmPI9oC iEwztzWWQ.OFHBvga4Nb2CLH.vwcmiqdI944toMq0QS82DTgks5uYBZLCFdJ NFfq2zw6vs695rbl8KxPzZq5rt1Xr8wBM1.+RqRyyt+or.jII6qkCrjDG50s iIPpmy.YwTmJ2AItNWIBE69IvD46qacpFb.LKNnvw4DfmeCwHh6NcdF6sI+q Z01TYwoY2E58fFc.qYNmELCDhXbEVX.9SZzE3IUFmV5fZsXeRyM2PA7vXqu8 J.lhDjiZt49WY.xX.7wL2nHJGAOIyMAvdXgWGfwQwvCZtQXTDIPMNqMx9la6 cagPFGx8zCTXOcnRuRvo6c54QrRQbQk1jm4vruyerB422Z8ssTmHOPkj6JPI MqEomFs8.BMdj6tUXAB5OXgUKR2IbEcTiWJq8beVGBXmyeF+e30AQgC -----------end_max5_patcher-----------

with fft you´d have the option to scale, limit and shift the range until it sounds useful.

for example you might want to dynamically assing a base frequency and mirror the spectrum around it.

with fft you´d have the option to scale, limit and shift the range until it sounds useful.

I don’t disagree, but where is your patch? ;-) Joking aside, it’s a matter of choosing convenient method. Simple RM in frequency domain is just a waste of CPU cycles.

for example you might want to dynamically assing a base frequency and mirror the spectrum around it.

This is what `freqshift~`

with negative frequency shift does. Of course it depends on what a "base frequency" is.

Ok, raja, Roman and AK, I have to ask: wtAf is going on here:

-- Pasted Max Patch, click to expand. --Copyallof the following text. Then, in Max, selectNew From Clipboard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siOV+67WOd6HJF7VVwt9nx7bmj0q2Pkp7kNSm L47eUHsuGML6cFO68rB2.Rpspmrofx1M.QZRuqM41SkY2BZaT.vLhaGMM+gS ing6 -----------end_max5_patcher-----------

Is this sourcery or am I entirely stupid? I spent this afternoon trying to solve it and you guys do it with, like, 5 objects or 3 lines of code:

It’s just basic DSP. If you know how to ring modulator works (side bands and stuff) it’s quite obvious. Both examples (Raja’s and mine) generate signal with alternating -1 and 1. Raja did this exactly like in the article linked by @OP, I did it using some stock msp objects. And this signal is how sine looks at Nyquist frequency (half the sampling rate). Multiplying a signal by sine is the ‘ring modulator’. RM shifts entire spectrum up and down by the frequency of the sine. Given the sound spectrum mirrors at each multiple of Nyquist frequency, frequencies from 0 to Nyquist are moved beyond limit of hearing and frequencies from Nyquist to sample rate are moved into human hearing frequency range (see fft~ help file).

**all**of the following text. Then, in Max, select

*New From Clipboard*.

----------begin_max5_patcher---------- 1779.3oc2YksaaaDE8Y6uBA9Xgq5ruzugh9PeMHvXD0H4IlhiB4PG6Dj7s2Y gjhTVxlRwUIMFvRjy58dt6W8kquJag8Qcc1r+b16lc0Ue45qtJNTXfqZe+pr MpGyKT0wkkUp+jcwGxtIMkS+nKNbtpxY2ZK9V2LkMarMtBsKtMT6n0tmJzwM zstzhbOsUmnhrZy5RUQ1M8OM68sKcqxkemob8sU5bWZ0TNbN3lYPBK7ESF9D QmC52imLLk6SElkQRvyG+tniN1Voq0kNkyXKOzEPCeAZ+X16Ca5qWec3ialH xUma2p6wmJU45VVNdpPv.pdQypZymiSinrChnfihnu.LIwI.Jdib1faLWUjm aaJiaPLQvSNQvSh9tAuin1sZk6ayP.h3vpc3uC0tIp.xHA1RxiHJ3j0+ffWC Cau.1+UP3OLKWQfYvDzYZ4xy9+lMXhgEx2TaPZ1uRVSIGFnjepywb5bPib6l MdKumAG+8SerwT6x99k8DPT1CwQaYZ7ED9X7E747E6MTJ+GyPGlkfSW9ZBJo uffDywyw9+f3.Wmh5HmSOQoI4MjqWVus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qv95MU2OegY8ZcUJYUOW uR0T3FiUq7UR10QUeIEjAoopKzgeajQMjg.PBTrgLDBBSPomXbLYbCYBGaGg 3g2+R4r6R8ewZeEtE8m6vZo6JXHackZoY2uLSnj2AjARBfRV3xw.o.PRO4GZ begZ2EraaTAPJizLC.HrzAHYr.G87sg56BExuBYbwXNjGuMDBK4h81lpbcp9 .DmOW3AHDpapsU1s1pNMNOnIHxteZQ+Fab1dNdmBmeatdhmHnPRjJ.HFPv2c sac8jJkJIfHeQYTDj2WKXWELdgZrBzQvIEifRZXWBBkD2NjIYzw72XQffAjI xQ3QGQ3AND.D3w6ITBYbegdT6sN5KOWRkdXM1POJiCSOwX.b2kd8N5NzoaOx re4WYa7pylNiwgNF5sA9rQWXKe5kr.T446qkC7rj.F0sYDHMhLPNiFT4NHyM pKpzPYq3DHJ1W25TM3.XNKovIDDPDugXDIzJzWwda1+nW2TnpNM6tzrGznC3 MyE7jYfTxvszBGHdQitDlzZb54Cp2h8EM2BKEHRqsqou.LEIIG0biIlSgbN. eLyMJhJPvSxbSB7NKh5.bAhAOn4FgSQjD2Dr1H6atsWS1gbATD4Gnz6cnUuR Jn6487HVoHgrUaJBNb+6hmqP9gFevsUlb0AZzzXAJo+rHSzncBjPeL4wWEVh fQGK7NQ5NgqbjZ7JUWr6yxIfeOe85+E.CeebO -----------end_max5_patcher-----------

i dont find sidebands so obvious, but the default case of spectrum inversion by inverting every other sample could be called a "simple math trick" at least.

it is superior to fft solutions whenever you dont want to deal with latency, but for everything else but 180 degrees it will introduce aliasing (ak´s second example, correct me if i am wrong)

in many situations it might be best practice to use the ringmodulator method and apply post HP and LP filters.

fft: sorry for not having an example ready, but in fft you can inverse the spectrum quite easily, too, by doing something like !-1024 to the bin count before rebuilding the signal. adding a fft-banded brickwall filter lies next to it wih another 3-4 objects.

spectrum stretching, by phase manipulation.

(dc is optional, for hilbert transform use the hilbert object. sorry, cant upload binaries from my windows enclave now)

###### Attachments:

right inlet is frequency, float or signal. what the exact relationship between this value and the spectrum distortion is? no idea.

raja wrote:

"and you’re not worrying too much about what the author on that site wrote about "a sampling rate has to be chosen to (approximately) match the signal bandwidth",

which is, interesting enough, a perfect description of what you should do when "emulating" this "effect" on the digital layer.

because on the digital layer the spectrum is known, it goes from 0 to nyquist, while an radio signals spectrum is theoretically infinite and in practice it depends on the weather, which is why analog voice inverters allows willingly set modes, such as 5, 6, and 7 khz.

-110

(hehe… uh… the OP wrote "How do I go about multiplying every other sample by -1…?" and posted it in the ‘gen’ forums, so honestly, that was all i cared about answering… i’m still reading this thread, but staying out of it beyond that ;D …but these have all been very interesting posts by very great and knowledgable people though, cheers!)

Was dragging my feet about releasing this for a while… But this thread gave me some energy to post.

https://github.com/tmartinez88/veil-voice-encryption

This is a project I have been working on for little while. It is not done at all. You will notice some artifacting on decryption. Open to suggestions on how to make it better, I want it to be open and available to the public at some point (I suppose it is now)

Essentially it is fft reordering or encryption based on a generated key. It basically pulls together 2 or 3 patches from the gen examples folder. Inspired by Simon Singh’s "The Code Book", it approaches encryption using a monoalphabetic cipher. Not exactly what you are talking about here but related so here you go!

https://github.com/tmartinez88/veil-voice-encryption

###### Attachments:

@AK, yes I understand the basic DSP *theory* behind it, I was merely marveling at the simplicity of raja’s

History n(1);

out1 = in1 * n;

n *= -1;

which I have to admit I don’t understand. Is the "n" in History a variable length?? I’m trying to realise his solution with gen objects, so I can understand it a bit better, as I have some Gen workshop stuff to prepare soon. I was able to RM a 22050Hz wave with various audio sources, which achieved the desired effect, what I found more challenging was inverting every other sample. Sorry to OP for the hijack.

Brendan

Is the "n" in History a variable length??

No, n is initialized to 1.

**all**of the following text. Then, in Max, select

*New From Clipboard*.

----------begin_max5_patcher---------- 1289.3oc2W0zbiaCC8r8uBM5XGWOjT7ydq26odMyNdjkXjYVYJMRzYS1cR+s WJRIZQEqjrcR6glCNxf.P.OfGH7O1tI8XySx9zjeK4tjMa9w1MabhFDrY76a ROm+TQcduSsTs7aMGeHcm+Hi7IiSbkT+WSBayMEmT5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EEV4qsqosoKr26dLGKH zfgWLMgLd9VUslPvi4DnGbAHJfyt9ZaMgPkPDXfKuHTBBxBc3S+DGaiPwPTD AmjLDTPb0MLA6LGRETRb94tjwY2AkdfcHC+V.hvBQteK.gxf9mnTP1jC1dMF rCE5rY4xaKROaamUSDU+vjEbfuqj0M5meOFvzOO3tj3V3UXF4EEKIF.a2KG5 nCTLj3.FHiRF53fuCoBjwn9FDNGCbkKXFxR0dWNUxeJqtTm2sB2xSJ2Ed5mh M4O8lTIfkvyY9lagflMFwL.+MoRtHgLR4rYKwxCeSRzfp.tWWr.35Q.YDj.u JIhx2SfLFHaMRDAQ3H3OEIR.ri.bnHiinvaRhvLBB6ylANDdIIJvChAirg+7 bG9xQJNad3h8xr6UEytN6pBqvLQbwnqbPGy98OJq7CXa3B53VsLAB5lBvlpT WqYhYMdQVAYbH2oBTXG8MxZDbB9e7P.qMur8uAz7A4iO -----------end_max5_patcher-----------

Thank you!

@Brendan

I’m so sorry, I didn’t realize you were asking specifically about that code(inverting every sample with simple gen~ code was what interested me most at first about the thread).

Here’s some comments that might help:

```
History n(1); //<-create a history of only 1 single sample(no variable-length), and initialize it to 1
out1 = in1 * n; //<-multiply every input sample by n(keeping in mind, that each time through the dsp-loop within gen~, we will hope to alternately change n between 1 and -1, thus creating an inversion every other sample)
n *= -1; //<-AFTER we have already output the sample multiplied by n, change n to be the negative of what it was previously(if n was 1, it will now be -1 prepared for the next time around in the DSP loop, if n was -1, it will now be 1 prepared for the next time around in the DSP loop)
```

And sometimes it helps me to go through exact values, so let’s take a hypothetical example where the input ramps from 0 to 1 over 4 samples(never quite reaching 1 though), so that the input values are 0., 0.25, 0.5, and 0.75:

1) 1st sample input of ‘in1’ = 0.;

1st sample ‘n'(initial value was initialized to ‘1’) = 1.;

1st sample output ‘out1’ = in1(0) * n(1) = 0*1 = 0.;

2) 2nd sample input of ‘in1’ = 0.25;

2nd sample ‘n'(changed to -1 at the end of the previous dsp loop) = -1.;

2nd sample output ‘out1’ = in1(0.25) * n(-1) = 0.25 * -1 = -0.25;

3) 3rd sample input of ‘in1’ = 0.5;

3rd sample ‘n'(changed back to 1 again at the end of the previous dsp loop) = 1.;

3rd sample output ‘out1’ = in1(0.5) * n(1) = 0.5 * 1 = 0.5;

4) 4th sample input of ‘in1’ = 0.75;

4th sample ‘n’ = -1.;

4th sample output ‘out1’ = in1(0.75) * n(-1) = 0.75 * -1 = -0.75;

Thus 0.,0.25,0.5,and0.75 becomes 0.,-0.25,0.5,and-0.75(every other sample inverted). The key thing to remember here is that ‘n’ is a single sample history which changes between 1 and -1 each time through the dsp loop but only changes its state *after* we have already output the current input sample multiplied by the previous state of ‘n'(it’s important that the line "n*=-1;" comes after "out1 = in1*n;").

Hope that helps(sorry for my wordiness, sometimes folks have mentioned it helps to be that descriptive…. but if not, ignore me).

@Thomas John Martinez

That looks amazing, I’ll study up on that patch more soon.

Hey raja

I didn’t explicitly say "@raja", so no apology expected! Your wordiness is very much appreciated; I had a vague idea that ‘n’ was updating itself every time through the loop, but your explanation has clarified this to the point that even I get it ;)

Best regards, peace and love etc

Brendan

(OT; Gregory and I are delivering some gen stuff here in N.I. in a few months, so I need to brush up on my gen chops; been languishing in Linux/Supercollider land for the past year, so have grown a little rusty.)

Forums > Gen