How to reverse and change speed in one effect

Help for Audacity on Windows.
Forum rules
ImageThis forum is for Audacity on Windows.
Please state which version of Windows you are using,
and the exact three-section version number of Audacity from "Help menu > About Audacity".


Audacity 1.2.x and 1.3.x are obsolete and no longer supported. If you still have those versions, please upgrade at https://www.audacityteam.org/download/.
The old forums for those versions are now closed, but you can still read the archives of the 1.2.x and 1.3.x forums.
Winston
Posts: 56
Joined: Fri Aug 28, 2020 12:59 pm
Operating System: Windows 10

Re: How to reverse and change speed in one effect

Post by Winston » Tue Oct 13, 2020 9:31 am

I'm trying to find a "Duplicate" effect in Nyquist, so I can use it to duplicate L and R and convert one of the duplicates to mono, but for another effect, duplicate the mono 2 times to make 3 channels. Also, if I try to use the stereo one with mono sound, how would I write a message pointing out that it is mono, use the other effect, without always saying the same message? Here is the code I'm trying to write, with the question-mark showing what command I need...
(if (stereo *track*)
(?DUPLICATE?)
(vector
(snd-function (aref *track* 0))
(snd-function (aref *track* 1)))
(snd-function *track*))

Winston
Posts: 56
Joined: Fri Aug 28, 2020 12:59 pm
Operating System: Windows 10

Re: How to reverse and change speed in one effect

Post by Winston » Tue Oct 13, 2020 9:32 am

for the other, just duplicating twice to make 3 channels total.

Sorry I cut that off. I sent too early by accident...

Help?

steve
Site Admin
Posts: 81627
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: How to reverse and change speed in one effect

Post by steve » Tue Oct 13, 2020 10:01 am

Winston wrote:
Tue Oct 13, 2020 9:31 am
I'm trying to find a "Duplicate" effect in Nyquist
Nyquist is included with Audacity, but it is separate from Audacity.

When a Nyquist plug-in runs, it returns some kind of data to Audacity, and Audacity then decides what to do with that data. For example if a Nyquist effect returns audio data, then Audacity replaces the selected audio with the audio returned by Nyquist. If the returned data is text, then Audacity displays the text in a message window. See here for more information about "return values": https://wiki.audacityteam.org/wiki/Nyqu ... urn_Values

Note that Nyquist has no direct way of creating or deleting tracks, no direct way to modify the sample rate or bit depth of an Audacity track, no direct way of editing tracks... All that Nyquist does directly is to operate on data that is passed to it, and return some kind of data.


Recent versions of Audacity provide Nyquist with one big new feature - the ability to send Macro Scripting commands (See: https://manual.audacityteam.org/man/macros.html)
By sending Macro Scripting commands to Audacity, Nyquist is able to tell Audacity to do things. Most (but not all) of Audacity's features can be controlled by scripting commands. You will find the full list of standard commands here: https://manual.audacityteam.org/man/scr ... rence.html

IMPORTANT:

A Nyquist plug-in may modify the project by returning data to the project (where the "return value" is audio or labels),
OR
A Nyquist plug-in may tell Audacity to modify the project via Macro scripting commands.
YOU CANNOT DO BOTH IN THE SAME PLUG-IN.


There is a workaround if you need to modify the project with Nyquist AND modify the project via scripting commands:
1. Create a Macro.
2. Use Macro commands to tell Audacity to modify the project
3. Launch Nyquist plug-ins from the Macro when you want Nyquist to modify the project.


Back to your question about duplicating tracks:
Use the "Duplicate:" Macro scripting command.

You can use the "Duplicate:" Macro scripting command from within a Nyquist plug-in like this:

Code: Select all

(aud-do "Duplicate:")
But note that the plug-in must only modify the project from Nyquist, OR modify the project via scripting commands.

Note also that Audacity does not stop you trying to modify the project in both ways within the same plug-in, but the behaviour if you do is "undefined" - that means that the result is unpredictable and may cause unexpected results - Don't do it.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Winston
Posts: 56
Joined: Fri Aug 28, 2020 12:59 pm
Operating System: Windows 10

Re: How to reverse and change speed in one effect

Post by Winston » Tue Oct 13, 2020 11:20 am

This did nothing, was there something I'm missing or didn't get?

Code: Select all

;nyquist plug-in
;version 4
;name "Convert from Stereo to 3 Channels..."
;action "Making extra channel..."
;info "This effect makes a temporary third channel from stereo"

(if is-stereo
     (*track*
     (aud-do "Duplicate:")
     (vector
       (snd-function (aref *track* 0))
       (snd-function (aref *track* 1))
     (snd-function *track*))
       (throw 'err "Track error.\nStereo track required. If you are trying to convert a mono file, use Convert from mono to 3 channels.")))
I'm trying to have it check if it is stereo, and if it is, duplicate the stereo channel with one being mono, the other 2 remaining with no effect, but if it is mono, pop up a message saying that it has to be stereo, or use the other mono version.

Nothing happened.
Last edited by steve on Tue Oct 13, 2020 11:53 am, edited 1 time in total.
Reason: code tags added

steve
Site Admin
Posts: 81627
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: How to reverse and change speed in one effect

Post by steve » Tue Oct 13, 2020 11:55 am

Winston wrote:
Tue Oct 13, 2020 11:20 am
This did nothing, was there something I'm missing or didn't get?
Try running the plug-in with the Debug button.
The first line of the debug output indicates the error in the code.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

steve
Site Admin
Posts: 81627
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: How to reverse and change speed in one effect

Post by steve » Tue Oct 13, 2020 11:56 am

Also note that to use THROW, there must also be a CATCH.
See: https://www.audacity-forum.de/download/ ... ef-281.htm
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Winston
Posts: 56
Joined: Fri Aug 28, 2020 12:59 pm
Operating System: Windows 10

Re: How to reverse and change speed in one effect

Post by Winston » Tue Oct 13, 2020 12:00 pm

This came up, is the 1 on the bottom the first line, or second? Does the "Null" mean Zeroth? Some programs incorrectly read 0 = First, 1 = Second, 2 = Third, ... instead of 0 = Null, 1 = First, 2 = Second, 3 = Third ...

Here is what I got:

error: unexpected EOF
Function: #<Subr-(null): #486b7a0>
Arguments:
#<File-Stream: #4682ac0>
#\(
1>

steve
Site Admin
Posts: 81627
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: How to reverse and change speed in one effect

Post by steve » Tue Oct 13, 2020 12:07 pm

Also, there is a syntax error in the IF statement.
It should be (in pseudo code)

Code: Select all

(if something
    (do-something)
    (do-something-else))
You have

Code: Select all

(if is-stereo
     (*track*
     (aud-do "Duplicate:")
     ...
The implication of (*track* is that *track* is a function name, which it isn't. *track* is a variable (a symbol representing the selected audio).

I assume what you mean is:

Code: Select all

(if is-stereo
    *track*
    (aud-do "Duplicate"))
but that will also fail because IS-STEREO has not been defined.

You probably want to define IS-STEREO like this:

Code: Select all

(setf is-stereo (arrayp *track*))
(see: https://www.audacity-forum.de/download/ ... ef-030.htm)
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

steve
Site Admin
Posts: 81627
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: How to reverse and change speed in one effect

Post by steve » Tue Oct 13, 2020 12:10 pm

Winston wrote:
Tue Oct 13, 2020 12:00 pm
error: unexpected EOF
That means that your "(" and ")" don't match. You are missing one or more "close parentheses".
A common cause of this error is if you have a quoted string that isn't closed.

Example:

Code: Select all

(print "Hello World)
Note the missing quote at the end of "Hello World".
Check to see the error message if you debug that in the Nyquist Prompt.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Winston
Posts: 56
Joined: Fri Aug 28, 2020 12:59 pm
Operating System: Windows 10

Re: How to reverse and change speed in one effect

Post by Winston » Tue Oct 13, 2020 12:27 pm

I got the stereo channel to duplicate, but doesn't merge one of the stereo tracks from 2 to 1... now how to block if mono with a "Error" message, and if stereo, merge one of the stereo channels to one mono, making 3 channels?

Here is what I have... so far:

Code: Select all

;nyquist plug-in
;version 4
;type generate
;name "Convert from Stereo to 3 Channels..."
;action "Making extra channel..."
;info "This effect makes a temporary third channel from stereo"

(setf is-stereo (array p *track*))
     (aud-do "Duplicate:")
     (vector
       (snd-function (aref *track* 0))
       (snd-function (aref *track* 1))
     (snd-function *track*))
       (catch 'mytag (+ 1 (throw 'err "Track error.\nStereo track required. If you are trying to convert a mono file, use Convert from mono to 3 channels." else)))
do the single-quotes matter?
(catch 'mytag' (+ 1 (throw 'err "Track error.\nStereo track required. If you are trying to convert a mono file, use Convert from mono to 3 channels." else)))
Last edited by steve on Tue Oct 13, 2020 12:58 pm, edited 1 time in total.
Reason: code tags added

Post Reply