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 12:36 pm

Tried this...

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*))
       (print "Track error.\nStereo track required. If you are trying to convert a mono file, use Convert from mono to 3 channels." else)))
...and "Print" didn't work...

...which is better, "print" or "throw 'err"?
Last edited by steve on Tue Oct 13, 2020 12:58 pm, 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 1:02 pm

When you include code in your post, please use the "</>" button to create code tags. In the message editing widow they look like this:
[code][/code]
You then insert your code between the [code] and [/code]
like this:

[code]
Type or paste your code here
...
[/code]

The code tags ensure that the code formatting is preserved.
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 1:38 pm

Winston wrote:
Tue Oct 13, 2020 12:36 pm
...which is better, "print" or "throw 'err"?
It depends what you want to do.
I'll write about PRINT here, then another post about THROW.

PRINT writes a string (text) to the default output stream - For Nyquist in Audacity the default output stream is the debug window. It also returns the string. Thus if a PRINT statement is the final line run, then the string will be returned to Audacity and Audacity will display it in a message window.
See: https://www.audacity-forum.de/download/ ... ef-200.htm

The PRINT statement can be useful when debugging code. For example this code fails:

Code: Select all

(setf data (list "A" "B" "C" "D"))
(setf myarray (make-array 4))

(setf count 1)
(dolist (val data)
  (setf (aref myarray count) val)
  (setf count (+ count 1)))

(print myarray)

The debug output is not particularly easy to understand

Code: Select all

error: index out of range - 4
Function: #<FSubr-SETF: #55555868d418>
Arguments:
  (AREF MYARRAY COUNT)
  VAL
Function: #<FSubr-DOLIST: #555558c6e088>
Arguments:
  (VAL DATA)
  (SETF (AREF MYARRAY COUNT) VAL)
  (SETF COUNT (+ COUNT 1))
... (more)...
To see what is happening within the DOLIST loop, we can add =https://www.audacity-forum.de/download ... 9.htmPRINC and PRINT statements like this:

Code: Select all

(setf data (list "A" "B" "C" "D"))
(setf myarray (make-array 4))

(setf count 1)
(dolist (val data)
  ; print some stuff to help debug
  (princ "Count is: ")
  (princ count)
  (princ " and val is: ")
  (print val)
  ; end of print statements
  (setf (aref myarray count) val)
  (setf count (+ count 1)))

(print myarray)

The debug output is then:

Code: Select all

Count is: 1 and val is: "A"
Count is: 2 and val is: "B"
Count is: 3 and val is: "C"
Count is: 4 and val is: "D"
error: index out of range - 4
Function: #<FSubr-SETF: #555558681858>
Arguments:
  (AREF MYARRAY COUNT)
  VAL
Function: #<FSubr-DOLIST: #555558687e78>
So we can see that the list is being stepped through correctly, but our "count" variable is wrong because =https://www.audacity-forum.de/download ... rt at zero.

We can then fix our code like this:

Code: Select all

(setf data (list "A" "B" "C" "D"))
(setf myarray (make-array 4))

(setf count 0)
(dolist (val data)
  ; print some stuff to help debug
  (princ "Count is: ")
  (princ count)
  (princ " and val is: ")
  (print val)
  ; end of print statements
  (setf (aref myarray count) val)
  (setf count (+ count 1)))

(print myarray)

and see that it now works as expected.

After getting it working correctly, the diagnostic PRINT statements should be removed:

Code: Select all

(setf data (list "A" "B" "C" "D"))
(setf myarray (make-array 4))

(setf count 0)
(dolist (val data)
  (setf (aref myarray count) val)
  (setf count (+ count 1)))

(print myarray)

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 1:42 pm

steve wrote:
Tue Oct 13, 2020 1:38 pm
I'll write about PRINT here, then another post about THROW.
Unlike PRINT, the THROW statement does not print anything. What it does is to stop the program immediately and send a message to it's associated CATCH.

See: https://www.audacity-forum.de/download/ ... ef-281.htm
and: https://www.audacity-forum.de/download/ ... ef-048.htm

Those pages include examples, so probably not worthwhile for me to add more examples here.
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 1:49 pm

I'm not sure what you are hoping to do here, but it won't work.

Code: Select all

     (vector
       (snd-function (aref *track* 0))
       (snd-function (aref *track* 1))
     (snd-function *track*))
Looking at the parentheses, the start of the function call is "(vector ...." and the end of that function call is the final ")"

VECTOR creates an array, and each argument is an element of the array.
You code is creating an array where the first element is (snd-function (aref *track* 0)), the second element is (snd-function (aref *track* 1)) and the final element is (snd-function *track*).

I suspect that you have miscounted the opening "(" and closing ")".

I would very highly recommend NOT relying on counting parentheses. Use a text editor that can highlight matching parentheses, such as NotePad++ (it's free).
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 » Thu Oct 15, 2020 6:42 am

Steve, about this...

Code: Select all

     (vector
       (snd-function (aref *track* 0))
       (snd-function (aref *track* 1))
     (snd-function *track*))
...I'm trying to merge the duplicated stereo track to mono, without merging the other. I'm trying to duplicate both left and right channels, and merge them to make 1 stereo and 1 mono. 3 channels. Not to be mean, but if you made the program, how is this hard to understand? Basically, I want to copy a stereo track/channel to itself, and mix the copied track/channel without affecting the original. This...

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 data (list "A" "B" "C" "D"))
(setf myarray (make-array 4))

(setf count 1)
(dolist (val data)
  ; print some stuff to help debug
  (princ "Count is: ")
  (princ count)
  (princ " and val is: ")
  (print val)
  ; end of print statements
  (setf (aref myarray count) val)
  (setf count (+ count 1)))
(setf data (list "A" "B" "C" "D"))
(setf myarray (make-array 4))

(setf count 0)
(dolist (val data)
  ; print some stuff to help debug
  (princ "Count is: ")
  (princ count)
  (princ " and val is: ")
  (print val)
  ; end of print statements
  (setf (aref myarray count) val)
  (setf count (+ count 1)))
(setf data (list "A" "B" "C" "D"))
(setf myarray (make-array 4))

(setf count 0)
(dolist (val data)
  (setf (aref myarray count) val)
  (setf count (+ count 1)))

(print myarray)

...doesn't work. It says that it "Nyquist returns value: 1". When I tried to debug, the error message came up, I think the part relevant to the problem is "error: index out of range - 4", because I believe it tried to duplicate 2 to 4, and remove 1 to 3, since it said "4" in part of the message, and "1" in the other, because 2+2=4-1=3. Options are to make one plugin that makes mono and stereo convert to 3 channels/tracks, or separate ones that only work for specified number of channels/tracks, which a message will come up if it isn't right.
Attachments
lrc.png
Example of what I'm trying to do
lrc.png (82.71 KiB) Viewed 316 times

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 » Thu Oct 15, 2020 9:34 am

Winston wrote:
Thu Oct 15, 2020 6:42 am
but if you made the program
I didn't write the Nyquist programming language. Nyquist was developed at CMU.
Winston wrote:
Thu Oct 15, 2020 6:42 am
Basically, I want to copy a stereo track/channel to itself, and mix the copied track/channel without affecting the original.
Nyquist cannot add or remove Audacity tracks, or change a mono track to stereo, or change a stereo track to mono.

Nyquist can convert stereo audio to mono, but it can't change the Audacity tracks.

You can use Macro commands from Nyquist to add or remove tracks.

You cannot use Macro commands to change the Audacity tracks and Nyquist commands to change the audio in the same plug-in.

There are a few exceptions, but the basic rule is that you need to decide whether to use Macro commands or normal Nyquist commands in the plug-in, and don't attempt to mix the two.
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 » Thu Oct 15, 2020 9:42 am

Winston wrote:
Thu Oct 15, 2020 6:42 am
This...

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 data (list "A" "B" "C" "D"))
(setf myarray (make-array 4))

(setf count 1)
(dolist (val data)
  ; print some stuff to help debug
  (princ "Count is: ")
  (princ count)
  (princ " and val is: ")
  (print val)
  ; end of print statements
  (setf (aref myarray count) val)
  (setf count (+ count 1)))
(setf data (list "A" "B" "C" "D"))
(setf myarray (make-array 4))

(setf count 0)
(dolist (val data)
  ; print some stuff to help debug
  (princ "Count is: ")
  (princ count)
  (princ " and val is: ")
  (print val)
  ; end of print statements
  (setf (aref myarray count) val)
  (setf count (+ count 1)))
(setf data (list "A" "B" "C" "D"))
(setf myarray (make-array 4))

(setf count 0)
(dolist (val data)
  (setf (aref myarray count) val)
  (setf count (+ count 1)))

(print myarray)
...doesn't work
If you change the code to this:

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 data (list "A" "B" "C" "D"))
(setf myarray (make-array 4))

(setf count 1)
(dolist (val data)
  ; print some stuff to help debug
  (princ "Loop 1 -Count is: ")
  (princ count)
  (princ " and val is: ")
  (print val)
  ; end of print statements
  (setf (aref myarray count) val)
  (setf count (+ count 1)))
(setf data (list "A" "B" "C" "D"))
(setf myarray (make-array 4))

(setf count 0)
(dolist (val data)
  ; print some stuff to help debug
  (princ "Loop 2 - Count is: ")
  (princ count)
  (princ " and val is: ")
  (print val)
  ; end of print statements
  (setf (aref myarray count) val)
  (setf count (+ count 1)))
(setf data (list "A" "B" "C" "D"))
(setf myarray (make-array 4))

(setf count 0)
(dolist (val data)
  (setf (aref myarray count) val)
  (setf count (+ count 1)))

(print myarray)

Then you will see which DOLIST loop the error is occurring in.
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 » Thu Oct 15, 2020 9:48 am

If you enable Advanced Mixing Options in Preferences, then this


Image

will export as a three channel track.

(Multi-channel export is not available in Macros)
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 » Thu Oct 15, 2020 10:29 am

Accessed by: Edit > Preferences > Import Export (on a Mac Audacity > Preferences > Import Export )

The link you sent me is for "Mac", not "Win". I have Windows 10, So I'm assuming "Use custom mix" does the same as "Use Advanced Mixing Options"? Do I need a Macintosh emulator for Windows?

Post Reply