Invert Musically

I found how to do it linearly, but it is not musical notes that are reversed, it is the frequencies. Is it possible for someone to make “pitch distortion” so when the sound is inverted, instead of a very high frequency in the middle, stretch it to where in the middle is not half frequency, but half octave numbers, somehow use ring-modulation and pitch or something, or just take frequencies from notes and swap them backward in pitch, changing it from Hz to semitones?

Here is something I want to add to…

(lowpass6 (mult (highpass6 track 2) (hzosc 20000))
20000)

Is there an easier way to do this besides selecting frequencies and swapping or moving it a hundred and a half times? Is there a shortcut that lets me reverse the pitch, for recordings like MP3 or WAV? Not MID, that is not what I want, I want to morph the frequencies to turn reversed Hz in to reversed notes.

Is there an easier way to do this besides selecting frequencies and swapping or moving it a hundred and a half times?

I’ve never programmed in Nyquist and I don’t understand what you’re trying to do, but normally if you want a program to do something 100 times, or a million times, you use a loop. Usually, one or more variables is changed (often incremented/decremented or read from a file/array) every time through the loop because it rarely makes sense to do the exact same thing a million times. Looping and conditional execution are the two concepts that make programming useful.

But even you write 100 lines of code, I’d consider that a small program…

This is ‘possible’, but on a scale of “easy ↔ difficult”, I’d rate it as “-> → -> very difficult”, at least it is to do it properly.

How did you do that?

I did it Linearly with this code in Nyquist:

(lowpass6 (mult (highpass6 track 2) (hzosc 20000))
20000)

I want a Nyquist code to morph inverted frequency to sync with pitches, or one that changes frequencies, and moves notes to the opposite order. It would make the notes on the spectrum flipped upside down, or flip the frequency analyzer into a mirror curve, but not in the way the code works alone. Is there a “lin/log/exp/sin scale” setting for frequencies?

PS - I can adjust pitch in one effect, frequency with another, and even the formants. But how about reversing them using Nyquist?

I meant taking each note and putting it on the other side, a loop would just repeat the command. I’m asking to, for example, swap C0 with B9, C#0 with A#9, D0 with A9, D#0 with G#9 and repeat the pattern, so all notes are reversed, flat to sharp, bass to treble. It would take ages to select certain frequencies and move it, and do it again with the next note, over and over, and have frequencies shifted to the opposite note manually.

If I could use a morphing tool for frequencies (like Equalizing is volume of frequency, or Compressing is volume of volume, but adjusting one frequency with another), it would appear inverted on a musical scale.

I want to reverse the tone of pitch, not frequency.

Below, the upper track shows a sine tone rising from 10 Hz to 20000 Hz.
The lower track shows the result of applying that code to the rising tone.

Yes, but I am not trying to generate a sound from low to high, I’m trying to flip the spectrum Logarithmicly, making a reverse pitch effect. This graphic-designed picture should give you an idea on what I’m trying to do. Left is unchanged, right is inverted pitch.
upsidedownpitch.jpg

Here is the examples of musically-scaled audio inversion if it is…
flip.jpg
I’m trying to make the spectrum run inverted with music, where notes, octaves, semitones are reversed, not hertz.

This article describes most of what you would need to implement in code: http://blogs.zynaptiq.com/bernsee/pitch-shifting-using-the-ft/
In my opinion, this is definitely not a beginners project.

Is there code to reverse the frequency in the form of reversing the brightness of the spectrum (Loud frequencies are mute, Soft frequencies is somewhat loud, etc.)? Yes, I know it would sound staticy, but I’m still working on the flipping effect…

O=Done
X=Unfinished

O Linear Spectrum
O Waveform
X Musical Spectrum
X Frequency Analysis
X Frequency-Time Swap
X Time Reverse

If anyone can tell me how to do the following X effects, I would appreciate it. O effects is already achieved.

I tried putting this file in the Plugins folder, but did not show the effect in “Add / Remove Plug-ins…” http://blogs.zynaptiq.com/bernsee/repo/smbPitchShift.cpp

Am I missing something? (Accidentally sent the other message early, this one is part of the other)

A CPP file is a program written in the C++ programming language. C++ is a “high level” “human readable” programming language. It has to be complied (converted) to a machine readable EXE or DLL file. That’s not an easy thing to do if you’re not a programmer and I don’t know what complier you’re supposed to use and I don’t know if it’s supposed to make a plug-in or a command-line program or if this is just part of a program. (It’s not a Windows GUI application.)

Audacity already has two pitch shift effects built in:
https://manual.audacityteam.org/man/change_pitch.html
and
https://manual.audacityteam.org/man/sliding_stretch.html

It doesn’t reverse high and low. All that does is shift it, but I want to flip or reverse the pitch.

I have an idea… but it requires math. Can audacity somehow calculate numbers? If so, and for example if it is 10=high notes & 0=low notes, would it be possible to do x-1 (-10=high & 0=low), then + 10 (0=high & 10=low)? I don’t want to make over 20,000 sound files with each frequency, pitch shift them, and merge it all back together, that’d take up huge memory and it would be a pain-in-the-neck amount of time. I want the musical notes in frequencies to be reversed, not the Hz. So, is it possible to make a Nyquist plugin that does something this, and if so, could you please give me an example?

Example of octave: 0 to 12 x -1 = 0 to -12, + 12 = 12 to 0

Plus, another plugin I made needs a value to be 1/60, and because I don’t know how to do math in Nyquist, I rounded & wrote “0.016666667”, but I can’t write the 6 infinite times.

I was trying something different, setting the max frequency to half the sample rate (linearly) but this code is not working…

    (lowpass6 (mult (highpass6 *track* 1) (hzosc (/ 2 *sound-srate*)))
              / 2 *sound-srate*)

This is the entire code…

;nyquist plug-in
;version 4
;type process
;name "Flip Sound"

;control text "Spectrum Or Waveform?"
;control md "Select Method" choice "Spectrum,Waveform" 0
;control text "We currently do not support different scales, reverse, time-and-frequency swapping, or frequency-analysis (yet)."
;control text "This plugin was a pain-in-the-butt to make, took all night, and was forced to get help from the developer later that morning. The sun was up when I got help around Ten AM. Please, enjoy it."
;control text ""
;control text "This plugin can't..."
;control text "1. Flip pitch, like Frequency Spectrum, except frequencies are set in musical notes"
;control text "2. Flip time, play in reverse"
;control text "3. Swap time and frequency, turn spectrum so Horizontal and Vertical is reversed"
;control text "4. Flip frequency analysis, turn spectrum in negative"
;control text ""
;control text "This plugin can..."
;control text "1. Flip frequency, reversing bass and treble linearly"
;control text "2. Flip wave, making the speaker vibrate with an inverted phase"

(if (= md 0)
    (lowpass6 (mult (highpass6 *track* 1) (hzosc (/ 2 *sound-srate*)))
              / 2 *sound-srate*)
    (mult *track* -1))

What am I doing incorrect? It tells me it returned 0. I want to set the frequency to half the playback sample rate, highest possible frequency on that sounds sample speed.

That is not valid code.
If you want to calculate half the sample rate, you need (/ sound-srate 2)

The forward slash on the second line is an error.

I rearranged it to so

;nyquist plug-in
;version 4
;type process
;name "Flip Sound"

;control text "Spectrum Or Waveform?"
;control md "Select Method" choice "Spectrum,Waveform" 0
;control text "We currently do not support different scales, reverse, time-and-frequency swapping, or frequency-analysis (yet)."
;control text "This plugin was a pain-in-the-butt to make, took all night, and was forced to get help from the developer later that morning. The sun was up when I got help around Ten AM. Please, enjoy it."
;control text ""
;control text "This plugin can't..."
;control text "1. Flip pitch, like Frequency Spectrum, except frequencies are set in musical notes"
;control text "2. Flip time, play in reverse"
;control text "3. Swap time and frequency, turn spectrum so Horizontal and Vertical is reversed"
;control text "4. Flip frequency analysis, turn spectrum in negative"
;control text ""
;control text "This plugin can..."
;control text "1. Flip frequency, reversing bass and treble linearly"
;control text "2. Flip wave, making the speaker vibrate with an inverted phase"

(if (= md 0)
    (lowpass6 (mult (highpass6 *track* 1) (hzosc (/ *sound-srate* 2)))
              2 *sound-srate*)
    (mult *track* -1))

but it is still giving me 0. What do I do with the second line?

Do I need to remove something, or am I missing something?

If you run the effect with the Debug button, some information is displayed in a debug window, beginning with:

error: too many arguments
Function: #<Closure-LOWPASS6:

That indicates that there is a problem in your usage of the LOWPASS6 function.

The syntax of LOWPASS6 is:
(lowpass6 signal hz)
https://www.cs.cmu.edu/~rbd/doc/nyquist/part8.html#index479

In your plug-in, you have:

    (lowpass6 (mult (highpass6 *track* 1) (hzosc (/ *sound-srate* 2)))
              2 *sound-srate*)

Let’s rearrange that so that we can see what arguments you are passing to LOWPASS6

(lowpass6 (mult (highpass6 *track* 1) (hzosc (/ *sound-srate* 2)))
          2
          *sound-srate*)

You have passed 3 arguments instead of 2.

My guess is that what you meant was:

(lowpass6 (mult (highpass6 *track* 1) (hzosc (/ *sound-srate* 2)))
          (/ 2 *sound-srate*))

However, that will still give an error because LOWPASS6 requires that the filter frequency is less than half the sample rate.


PS.
A bit more technical detail:

LOUDPASS6 is implemented in Nyquist as a biquad filter (Digital biquad filter - Wikipedia). If the parameters are out of range, the biquad filter becomes unstable and does nasty things, such as division by zero, or infinite or negative infinity results, or NaN results.

To avoid instability / crashing, Nyquist checks that the biquad parameters are within usable ranges, and throws an error if they aren’t.
Example:

error: In BIQUAD, (a2 <= -1) or (1 - a2 <= |a1|) (unstable parameters a1 = 2, a2 = -1)