Invert delay

Using Nyquist scripts in Audacity.
Post and download new plug-ins.

If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like

Invert delay

Permanent link to this post Posted by Michael Kazmierski » Sat Nov 05, 2016 11:50 am

Hello,
I'm facing another audio problem here. Let's see, the best way I can describe it is like this.

So I have a recording of a pipe band (bagpipes and drums), and there is a fixed flanger frequency of 1024 Hertz. Here's how I counteract it right now, but I was thinking of a plugin to simplify the job.

I first divide 1 by 1024, I get 0.0009765625, this being the number of seconds to delay. I select "regular", delay level per echo is set to 0, delay time is 0.0009765625, no pitch change, and only one echo. However, the flanger effect gets worse. So I invert that modified track, copy it to the clipboard, undo back to the original, new track, paste it in, and I get only the signal that has been delayed by the chosen amount. I mix and render to a new track, copy that to the clipboard, and then undo back to the original, new track, paste that in - then finally the echo signal is inverted compared to the original. Make sense? However, this is really really tedious and I want to speed up the process a bit by having to do less. So, I was wondering if it could be possible to add an option to invert the echos (i.e. for each echo it would invert the signal, so you get more of a 512 HZ square wave in this particular instance rather than a 1024 HZ sawtooth wave)? The options would be to either have a regular echo (which is what it only does now) and also to have the echos inverted. Let's say you want to block out a certain frequency (after calculating the number of seconds), and all subsequent harmonics, sort of like a reverse comb filter, I know it's rather hard to explain but I think you might be able to understand what I'm trying to say. To me, this would be very very helpful in blocking out tones whose frequency you can determine. Also, note that the delay level would also be included in this modified plugin. Essentially it would be exactly like Delay.NY, but add only one option to make the signal for each echo inverted (so that you can also counteract slower echos as well). Hopefully I've made sense, I have tried modifying the Nyquist plugin myself but to no avail. I read somewhere that inverting is just typing "Mult -1", and I replaced the + signs with - signs and I get an error. Hopefully you can help either writing the plugin or assisting me in modifying it. Thanks

Michael
Michael Kazmierski
 
Posts: 53
Joined: Wed Aug 17, 2016 1:06 am
Operating System: Windows 7

Re: Invert delay

Permanent link to this post Posted by steve » Sat Nov 05, 2016 12:26 pm

The operation you describe seems rather specific (probably not very useful for most users - more about this later), so I'm not inclined to add it to the Delay effect that we ship with Audacity. However, it is quite simple to achieve the effect that you want with a short Nyquist script. Here's the code for the effect - you can run it in the Nyquist Prompt effect (http://manual.audacityteam.org/man/nyquist_prompt.html):

Code: Select all
(setf shift 0.0009765625) ;desired shift (to the right) in seconds

(sim *track*
  (at-abs shift (cue (mult -1 *track*))))


or if you want to set the shift in samples:

Code: Select all
(setf shift 43) ;desired shift (to the right) in samples

(setf shift (/ shift *sound-srate*)) ; convert 'shift' to seconds
(sim *track*
  (at-abs shift (cue (mult -1 *track*))))


How the code works:
  • *track* points to the selected audio.
  • As you rightly said, to invert an audio signal you just multiply by -1.
    Note: the mult command must be used because * only works for numbers.
  • (at-abs <time> <behaviour>) says 'when' a behaviour should be evaluated.
    http://www.cs.cmu.edu/~rbd/doc/nyquist/ ... l#index585
    Note: we are wanting to shift a "sound", which is not a "behaviour" (it's a "sound"). By 'cueing' the sound we allow the sound to be evaluated as a 'behaviour'.
  • sim just adds things (numbers or sounds). It's equivalent to sum.
Putting that all together:
Add <the selected sound> [ *track* ]
to the <selected sound> inverted [ (mult -1 *track*) ], shifted to the right by <shift> seconds.

(some additional comments to follow, but I don't have time right now - back in a short while ;)
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 45360
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Invert delay

Permanent link to this post Posted by steve » Sat Nov 05, 2016 1:17 pm

steve wrote:(probably not very useful for most users - more about this later)

The main use of the Delay effect is to produce a kind of repeated echo, so typically the delay length is between about 50 to 1000 ms. With such 'long' delays, the phase is not really important because we are normally using the effect with broadband signals, so the phase is quite arbitrary (different phase for each frequency component). Where phase becomes important is with very short delays (less than about 100 ms) and with strictly periodic signals (such as test tones), but this is really quite a specialist effect which would be better served by a separate "Comb Filter" effect.

Michael Kazmierski wrote:So I have a recording of a pipe band (bagpipes and drums), and there is a fixed flanger frequency of 1024 Hertz. Here's how I counteract it right now, but I was thinking of a plugin to simplify the job.

I first divide 1 by 1024, I get 0.0009765625, this being the number of seconds to delay. I select "regular", delay level per echo is set to 0, delay time is 0.0009765625, no pitch change, and only one echo. However, the flanger effect gets worse. So I invert that modified track, copy it to the clipboard, undo back to the original, new track, paste it in, and I get only the signal that has been delayed by the chosen amount

I don't think this will actually "work" as you intend, though it may approximate to the intended effect.

Presumably the phasing effect in the original has been caused by an "echo" of some kind (the summation of a delayed signal), and your intention is to "reverse"/"undo" that effect. In order to "undo" the effect, you need to subtract the delayed signal. However, you have neither the original (before the phasing effect) signal, or the delayed signal on their own. All you have is a mix of the original and the delayed signal.

If we call the original, non-phased signal "A", and the delayed signal "B", then you are starting with "A+B". To "undo" the phasing effect you need to "subtract B":
(A + B) - B = A
but...
When you delay and invert (A+B), you don't get "-B" you get "-B" from the delayed and inverted "A", and you also get a delayed and inverted copy of "B".
In effect you have:
(A + B) - (B + C) = A - C

So yes this will remove the 1024 Hz comb filter effect IF the effect was caused by an echo of 0.0009765625 seconds, but it will replace it with a new, lower frequency comb (which may a subjective improvement / less objectionable, but it's not really "fixed" the original problem).

Michael Kazmierski wrote:To me, this would be very very helpful in blocking out tones whose frequency you can determine.

A simpler alternative would be to use the Notch Filter (http://manual.audacityteam.org/man/notch_filter.html).
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 45360
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Invert delay

Permanent link to this post Posted by steve » Sat Nov 05, 2016 1:22 pm

Just to add: The code snippets that I posted in my first reply could easily be converted into a plug-in.
All you would need to do is to add the appropriate "headers", then install it like any other Nyquist plug-in.

Installation instructions: http://wiki.audacityteam.org/wiki/Downl ... ns#install

Information about plug-in headers: http://wiki.audacityteam.org/wiki/Nyqui ... -in_Header

If you need help with plug-in headers, just ask.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 45360
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Invert delay

Permanent link to this post Posted by Michael Kazmierski » Sat Nov 05, 2016 1:25 pm

Ok, I'm super embarrassed here's why:
Well, maybe I was a real dudelsack for asking the question here. I simply changed "Mult" to "Mult -1", where -1 is before the word "gain", edited it so it says "name "Inverted delay", saved the file as Delayinverted.ny, and I'm all set (the echos get inverted like I wanted them to). Now what was I thinking? I think it's just a case of replacing "Mult whatever" to "mult -1 whatever". If I knew this before I probably wouldn't have asked. Sorry about that, now I feel rather dumb for asking for such a plugin when really I just had to do a bit of research about programming Nyquist. If it makes sense to delete this particular thread now, please go ahead. Again sorry for wasting your time (cry) (cry)

Michael
Michael Kazmierski
 
Posts: 53
Joined: Wed Aug 17, 2016 1:06 am
Operating System: Windows 7

Re: Invert delay

Permanent link to this post Posted by steve » Sat Nov 05, 2016 1:29 pm

No problem Michael.
Rather than delete this topic, I'll move it to the Nyquist board. There may be stuff in here that is interest to other users.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 45360
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Invert delay

Permanent link to this post Posted by Michael Kazmierski » Sat Nov 05, 2016 1:33 pm

steve wrote:Rather than delete this topic, I'll move it to the Nyquist board. There may be stuff in here that is interest to other users.
Oh yeah, I guess that's true and would make sense not to delete the thread from the get-go. Thing is, I'm also part of a bagpiping forum (yes those things do exist), and whenever someone feels like they've insulted someone or anything similar (sorry for x y and z), it's deleted by the moderators. Not that this should apply to this, but I'm just saying... haha... All right , have a great rest of the weekend. If there's any plugin I'm thinking about writing I'd be happy to ask you for assistance.



Michael
Last edited by steve on Sat Nov 05, 2016 2:16 pm, edited 2 times in total.
Reason: quote tags added
Michael Kazmierski
 
Posts: 53
Joined: Wed Aug 17, 2016 1:06 am
Operating System: Windows 7


Return to Nyquist



Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests