possible to make this plugin? ("auto draw wave")
Forum rules
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
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
possible to make this plugin? ("auto draw wave")
Hello,
I'm new to this forum and hoping someone can help me out with the following:
Is it possible to make a plugin in Nyquist that connects the first and last sample of a selection with a straight (or cosine-like) line (see picture).
The existence of such an effect would really make my day..I really could use a tool like this.
thank you for your time,
Nils
I'm new to this forum and hoping someone can help me out with the following:
Is it possible to make a plugin in Nyquist that connects the first and last sample of a selection with a straight (or cosine-like) line (see picture).
The existence of such an effect would really make my day..I really could use a tool like this.
thank you for your time,
Nils
- Attachments
-
[The extension tiff has been deactivated and can no longer be displayed.]
-
kozikowski
- Forum Staff
- Posts: 68902
- Joined: Thu Aug 02, 2007 5:57 pm
- Operating System: macOS 10.13 High Sierra
Re: possible to make this plugin? ("auto draw wave")
I don't think the forum likes TIFFs. Can you send a JPEG or GIF?
Koz
Koz
Re: possible to make this plugin? ("auto draw wave")
Sure, here it is again:
- Attachments
-
- effect.jpg (32.2 KiB) Viewed 4877 times
Re: possible to make this plugin? ("auto draw wave")
Assuming that you are talking about very short selections, joining with a straight line is not too difficult.
Try running the following code in the "Nyquist Prompt" effect (Effect menu):
Note that this is only for a mono track.
Try running the following code in the "Nyquist Prompt" effect (Effect menu):
Code: Select all
(let* ((one (/ *sound-srate*)) ; duration of one sample in seconds.
(end-time (- (/ len *sound-srate*) one)) ; time of last sample
(start-amp (sref s 0)) ; 1st sample value
(end-amp (abs-env (sref s end-time)))) ; last sample value
(control-srate-abs *sound-srate*
(pwlv start-amp 1 end-amp))) ; create line.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
Re: possible to make this plugin? ("auto draw wave")
Steve, thank you so much. Your kind solution will certainly help me out, mono is just fine for me.
Is it possible to expand your patch to have a curve instead of a straight line? maybe by entering an equation somewhere?
My "dream patch" is to make a selection and let the plugin draw a single cycle of perfect sine wave.
Best,
Nils
Is it possible to expand your patch to have a curve instead of a straight line? maybe by entering an equation somewhere?
My "dream patch" is to make a selection and let the plugin draw a single cycle of perfect sine wave.
Best,
Nils
Re: possible to make this plugin? ("auto draw wave")
That would be possible, but the hard part is that if you want a smooth transition between the original waveform and the new "line", you need to be able to calculate the curve. For example, if you were to use a sine curve, then you need to calculate the initial phase, the frequency and the amplitude that will fit between the start and end points. If you know the maths and can tell me how to calculate that, then I can probably show you how to code it.N871 wrote:Is it possible to expand your patch to have a curve instead of a straight line?
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
-
Robert J. H.
- Posts: 3633
- Joined: Thu May 31, 2012 8:33 am
- Operating System: Windows 10
Re: possible to make this plugin? ("auto draw wave")
I've certainly missed something.steve wrote:That would be possible, but the hard part is that if you want a smooth transition between the original waveform and the new "line", you need to be able to calculate the curve. For example, if you were to use a sine curve, then you need to calculate the initial phase, the frequency and the amplitude that will fit between the start and end points. If you know the maths and can tell me how to calculate that, then I can probably show you how to code it.N871 wrote:Is it possible to expand your patch to have a curve instead of a straight line?
Could one explain what is actually needed?
I mean, a cycle is just one cycle, i.e. 2 Pi.
Thus, the sample after the selection would be the same as the one at the start of the selection.
The questions are therefore:
- must the amplitude be interpolated to match the first and last value.
- is the highest magnitude of those the max (=cosine) or...
- ...we aim for a peak value of one (with adapted phase)
- is a DC offset allowed
- is a fractional cycle allowed in the range Pi/4 <> 2 Pi (or multiples of it).
In fact, some points require at least 3 samples instead of only 2.
Let's say that we have the values 0.5 and 0 from a 10 sample selection.
This could mean
a -6 dB cosine that lasts 3/4 Pi;
a cosine with start amplitude 0.5 and end amplitude 0;
a 30° sinusoid with amplitude 1 and partial cycle;
a sine wave with 0.5 initial DC offset, amplitude arbitrary;
and so on.
Re: possible to make this plugin? ("auto draw wave")
This code allows you to generate short sections of a s sin curve within the selected region.
The code lines that start with "(setq" set the parameters for generating the curve.
If you want the curve to automatically fit to the start and end points, then you need to know how to calculate those parameters.
For example, for this selection: These parameters produce a reasonably good fit:
(setq amp 0.3) ; +/- amplitude of sine
(setq offset -0.06) ; DC offset
(setq phase -85) ; start phase in degrees
(setq cycles 0.5) ; number of cycles
and so does increasing the number of cycles by 1 (setq cycles 1.5)
I determined the parameters by trial and error, which is not a very good solution.
The code lines that start with "(setq" set the parameters for generating the curve.
If you want the curve to automatically fit to the start and end points, then you need to know how to calculate those parameters.
Code: Select all
(setq amp 0.5) ; +/- amplitude of sine
(setq offset 0.3) ; DC offset
(setq phase 45) ; start phase in degrees
(setq cycles 0.5) ; number of cycles
(sum offset
(mult amp
(osc (hz-to-step (/ cycles (get-duration 1)))
1 *sine-table* phase)))
For example, for this selection: These parameters produce a reasonably good fit:
(setq amp 0.3) ; +/- amplitude of sine
(setq offset -0.06) ; DC offset
(setq phase -85) ; start phase in degrees
(setq cycles 0.5) ; number of cycles
and so does increasing the number of cycles by 1 (setq cycles 1.5)
I determined the parameters by trial and error, which is not a very good solution.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
Re: possible to make this plugin? ("auto draw wave")
I must say this forum is just great, thanks again Steve, this seems to be exactly what I wanted, give me a moment to try it out and I will return with some final thoughts and a better explanation about what I'm trying to do.
Thank you Robert for your thoughts, will reply in my next message.
Thank you Robert for your thoughts, will reply in my next message.
Re: possible to make this plugin? ("auto draw wave")
Steve, great stuff, before explaining why this plugin is of great use to me, could you possibly add one feature: make the "setq amp" automatically the amplitude of the first sample in the selection.
(I will always use 1 cycle, with start phase 270 degrees with DC offset 0.0)
This plugin works great for what I'm doing now (working with sine waves). In general this is what I would like to be able to in audacity (hope it's clear):
make a selection of a wave (for example a selection with a length of 11123 samples) and copy, make a new selection somewhere (for example with a length of 11248 samples), and paste the wave (overwrite! instead of insert) with an auto-stretch so the wave fits the new length without any visible changes in the drawing of the wave. In fact this is a speed change but with a very accurate starting and ending point and without much of a hassle.
I have to be honest in saying I'm not sure such a thing can be done. Stretching always seems to involve some change in wave shape. On the other hand I'm working with very high sample rates: 192kHz so the resolution is high enough, and the waveform are not that complex). But is has to be perfect (for looping reasons). ...
(I will always use 1 cycle, with start phase 270 degrees with DC offset 0.0)
This plugin works great for what I'm doing now (working with sine waves). In general this is what I would like to be able to in audacity (hope it's clear):
make a selection of a wave (for example a selection with a length of 11123 samples) and copy, make a new selection somewhere (for example with a length of 11248 samples), and paste the wave (overwrite! instead of insert) with an auto-stretch so the wave fits the new length without any visible changes in the drawing of the wave. In fact this is a speed change but with a very accurate starting and ending point and without much of a hassle.
I have to be honest in saying I'm not sure such a thing can be done. Stretching always seems to involve some change in wave shape. On the other hand I'm working with very high sample rates: 192kHz so the resolution is high enough, and the waveform are not that complex). But is has to be perfect (for looping reasons). ...