[audacity4blind] Re: Tone Generator

  • From: "David Engebretson Jr." <d.engebretson@xxxxxxxxxxx>
  • To: <audacity4blind@xxxxxxxxxxxxx>
  • Date: Fri, 22 May 2015 21:58:56 -0700

Yes it does.

Best,
David


--------------------------------------------------
From: "Annabelle Susan Morison" <foristnights@xxxxxxxxxxx>
Sent: Friday, May 22, 2015 8:32 PM
To: <audacity4blind@xxxxxxxxxxxxx>
Subject: [audacity4blind] Re: Tone Generator

Will it say what the abbreviation for each oscillator is?

-----Original Message-----
From: audacity4blind-bounce@xxxxxxxxxxxxx
[mailto:audacity4blind-bounce@xxxxxxxxxxxxx] On Behalf Of David Engebretson
Jr.
Sent: Friday, May 22, 2015 8:31 PM
To: audacity4blind@xxxxxxxxxxxxx
Subject: [audacity4blind] Re: Tone Generator

Yes, I think it is.
Check out:
http://www.cs.cmu.edu/~rbd/doc/nyquist/part8.html

Under the level 5 heading of "Oscilators"

Best,
David


--------------------------------------------------
From: "Annabelle Susan Morison" <foristnights@xxxxxxxxxxx>
Sent: Friday, May 22, 2015 7:00 PM
To: <audacity4blind@xxxxxxxxxxxxx>
Subject: [audacity4blind] Re: Tone Generator

I wonder if the structure of this code is the same for things like sine,
square, and sawtooth oscillators?

-----Original Message-----
From: audacity4blind-bounce@xxxxxxxxxxxxx
[mailto:audacity4blind-bounce@xxxxxxxxxxxxx] On Behalf Of Steve the Fiddle
Sent: Tuesday, May 19, 2015 8:36 AM
To: audacity4blind@xxxxxxxxxxxxx
Subject: [audacity4blind] Re: Tone Generator

As there's two of you asking, I'll reply on-list.

First, a bit about the structure.
Here is the code again:

(abs-env
(let ((eps 0.0001)
(attack 0.001)
(amp 0.3)
(duration 2.5)
(frequency 1760))
(setf envelope (diff (pwev eps attack amp duration eps) eps))
(mult envelope (stretch duration (osc-tri frequency)))))

I'll call this the "ding" code (because it makes a sound that goes
"ding").

As you can see, there are lots of parentheses (brackets).
All Nyquist statements are in the form;
(function-name arguments)
where "arguments" is 0 or more parameters for the function to chew on.

Functions can be, and often are, nested one inside the other.
For example:
(function-a (function-b))
In this case, "function-b" is a function with no arguments (no
parameters),
and
"function-a" is a function with one argument (one parameter).
In other words, "function-b" is used as an argument of "function-a"

In the "ding" code, there are several layers of nesting.

The outermost function is "abs-env".
ABS-ENV is rather complex to describe, but in brief, it allows us to
specify
time in seconds within an effect.

"Effects" are one way of running Nyquist code
and is characterised by processing existing audio data. They are therefore
referred to as "process effects". Another way that Nyquist code can be
used
is as a "generator", characterised by generating new audio data
without taking in
any pre-existing audio data. Not surprisingly these are called
"generator" effects.

Generator effects, when written as plug-ins, are placed in the
Audacity Generate menu.
Process effects as plug-ins are placed in the Effects menu.

Generate effects are different to process effects in how they deal with
time.
For a generate effect, "one second" defined in the code is "one
second" in real time.
For process effects, time is stretched such that the selection length
in Audacity
equates to "one second" in the code. This is generally useful because
for process
effects we don't normally want to bother with how long the selection
is - we usually
want to process all of the selection, regardless of it's length, and
we can do that
by treating the length as "one unit of time".

In the case of "ding", we are generating a sound, but we are doing it
in the Nyquist
Prompt effect. The Nyquist Prompt effect is a "process" type effect, so
the
time
stretching feature will apply to our "ding" code unless we tell it
otherwise.

The ABS-ENV function causes the code within to use "absolute time". That
is,
one
second in the code is one second in real time, It allows us to process
the nested
code with time handled like a generator effect, even though we are running

it
in
the Nyquist Prompt which is a process effect.

Big breath. That's the hard bit out of the way.

ABS-ENV takes one argument, and in "ding" we have one function called
"LET".
The rest of the code is/are the arguments (parameters) for the LET
function.
"LET" is a common and very useful "block structure".

The first arguments of "LET" are enclosed in brackets and set values
for variables
that will be used within the LET. These are "local variables" in that
they only exist
with the "LET" block of code.

These local variables are:

((eps 0.0001)
(attack 0.001)
(amp 0.3)
(duration 2.5)
(frequency 1760))

In effect and because this is at the start of a LET function:

let eps = 0.0001,
let attack = 0.001,
let amp = 0.3,
let duration = 2.5,
let frequency = 1760

These are the local variables that will be used within the rest of the
block.

The second and final part of the LET block is called the "body" code.
This is the business part of the block that actually does something.
In the case of "ding" it is just two lines:

(setf envelope (diff (pwev eps attack amp duration eps) eps))
(mult envelope (stretch duration (osc-tri frequency)))

"SETF" sets its first argument to the value of the second argument.
In this case we are creating a new variable called "envelope" and
giving it the value:
(diff (pwev eps attack amp duration eps) eps)

A quick overview about what we are doing in this line:

In the final line we will be creating a boring, monotonous tone, but
we will make
it beautiful by shaping its dynamics. To do that we are going to create a
"control signal" that can be applied to the boring tone. This second
to last line
creates the control signal, which we have named "envelope".

This is a really useful technique, so it's worth spending some time
explaining:

Amplification is really just "multiplication". If we have a digital sound
and
we
multiply every sample value by 2, the we make the sound twice as loud - we
have amplified it by "2" (the same as +6 dB). If we multiply every
sample value by
0.5, then we make it half as loud - we have amplified by 0.5 (same as -6
dB).

Amplification is very easy in Nyquist.
Up until, I think Audacity 2.0.6, Audacity used the symbol "S" in
Nyquist process effects
to represent audio from the selection. In Audacity 2.1.0 this was
updated and Audacity
now uses the symbol *TRACK* (note that the asterisks are part of the
name).
We will use the symbol "S" in these quick examples. If you are using
Audacity 2.1.1 or
later, there is a checkbox in the Nyquist Prompt to select "legacy
syntax". Enable
legacy syntax to use the old "S" symbol rather than the new *TRACK*
symbol.

These examples work on mono tracks only:

(mult s 2.0)
(mult s 0.5)

The first example multiplies "S", which is the sound from the track,
by 2. It amplifies by
a factor of 2.
As you no doubt have worked out, the second amplifies by a half.

It's a little more complex to process stereo tracks, but fortunately
Nyquist has a magical
incantation that allows us to process multiple channels. It is
"multichan-expand"
and it is used like this:

(multichan-expand #'mult s 2.0)
(multichan-expand #'mult s 0.5)

Note the two special characters "hash" and "single quote".
Note also that it is a "single quote" character and not a "back
quote". On my keyboard
the singe quote character is the lower-case key with the @ symbol.

OK, so how cool would it be if we could amplify by a varying amount?
Pretty cool I think, and quite easy to do. What we would need to do is
to create a
"control signal" that is the same length as the sound that we are
amplifying
and
that each point along the control signal, (each sample), has the value
that we want to
multiply by. For example, if we want to fade out from x1 amplification
to zero, then
we want a control signal that starts at 1 and goes gradually down to zero.

Nyquist has a whole bunch of related functions for creating these
control signals, and
they are collectively called "piece-wise approximations".

The easiest of these "piece-wise approximations" to describe is the
"piece-wise linear" version
which is the function "PWL"

PWL takes pairs of arguments. Each pair consists of a time value and
an amplitude value.
The amplitude value of the final pair is zero and does not need to be
entered.

To create an envelope of duration "one time unit" that starts at
amplitude 1.0 and goes down
to amplitude 0.0, we need the time/amplitude pairs:
time = 0, amplitude = 1.
time = 1, amplitude = 0.

Because PWL automatically adds the final "amplitude = zero", we should
miss that out,
and the function is written:
(pwl 0 1 1)

Control signals rarely need to be absolutely precise, so by default,
control signals are
created with a low sample rate (1/20th of the audio sample rate). The
low sample rate
makes them a bit quicker to generate, process and require less memory.

If we run (pwl 0 1 1) on its own, it will produce a very short and
inaudible control signal
(you may hear a click at the start). It is short because it is at a
low sample rate, but when
run on its own it is returned to the Audacity track that has the
normal audio sample rate.
We don't need to worry about that, because we are not going to use it
on its own. We are
going to apply it to (multiply) a sound.

(mult (pwl 0 1 1) s)

or the version that can handle stereo tracks:

(multichan-expand #'mult (pwl 0 1 1) s)

Note that for a process effect, the selection length is treated as
"one unit", so the
duration of "1" in PWL is the length of the audio selection.


This provides a really useful trick for manipulating the amplitude of
an audio track.

Let's say that we want the volume of a track to go from silence, to
double amplitude
and then down to quarter amplitude.

To do that we want a control envelope that over the course of "one
unit of time" goes
from zero, to two, to 0.25.

So our time/amplitude pairs are:

0 0 / 0.5 2.0 / 1.0 0.25
PWL has an implicit "amplitude = 0" at the end, so strictly speaking
we should have a final pair of "1 0" at the end
0 0 / 0.5 2.0 / 1.0 0.25 / 1.0 0
and then miss off the final zero in the PWL function:
(pwl 0 0 0.5 2 1 0.25 1)

So to amplify the selected sound:
(mult s (pwl 0 0 0.5 2 1 0.25 1))
or the stereo version:
(multichan-expand #'mult s (pwl 0 0 0.5 2 1 0.25 1))

We can also set a named variable to have the control signal as its
"value".

(setf envelope (pwl 0 1 1))
(setf env2 (pwl 0 0 0.5 2 1 0.25 1))

and then multiply the sound "S" by the variable;
(mult s envelope)
(mult s env2)

As you are probably guessing by now, multiplying a sound by a control
envelope
provides a useful and accessible way of precisely manipulating the
amplitude
of sounds. This technique is the basis of the "Adjustable Fade" effect;
http://manual.audacityteam.org/o/man/adjustable_fade.html
and the "Text Envelope" plug-in:
http://wiki.audacityteam.org/wiki/Nyquist_Effect_Plug-ins#Text_Envelope

There is more information about PWL and the other "piece-wise
approximations"
in the Nyquist manual:
http://www.cs.cmu.edu/~rbd/doc/nyquist/part8.html#index389

Time for a quick sup of tea, then on to the final part of the "ding"
code...

One of the "piece-wise" variations is "PWEV"
The "V" versions have explicit start and end values. The start time
has to be zero,
so that is omitted and the first value is the amplitude at zero.
The "E" stands for "exponential". Rather than producing a straight
line between each
of the control points, it creates a logarithmic curve.
Natural sounds tend to decay exponentially, so using an exponential
decay curve is
what I wanted.

One thing to be careful of when using "piece-wise exponential
approximations"
is
that log(0) is an illegal value.

Now I actually want the envelope to rise from zero and drop back down
to zero, so what
I do is to create an envelope that rises from a small value up to the
maximum amplitude
and then drops back down to the same small value. I can then "lower"
the entire curve
(after it has been calculated) by subtracting that "small value" from
each sample value.

Looking back at the values set at the top of the LET block:

((eps 0.0001)
(attack 0.001)
(amp 0.3)
(duration 2.5)
(frequency 1760))

The "small value" I've called "eps" and given it the value 0.0001.
The maximum amplitude I want is about 0.3, hence "amp" = 0.3.
I want the sound to rise quite quickly to make it a bit percussive, so
I'll put the high point
at 0.001 seconds. That's "attack" = 0.001.
The overall length I want as about 2.5 seconds, so that's "duration" =
2.5.

Note that because we've used ABS-ENV, the times are in seconds.

The first part of creating the envelope is the PWEV function with
time/ amplitude pairs at:

0, 0.0001 / 0.001, 0.3 / 2.5, 0.0001

or using the names of the variables:

0, eps / attack, amp / duration, eps

which gives us the command:
(pwev eps attack amp duration eps)

The second step is to subtract the "eps" amount from each sample.
We can't use the normal "minus sign" because that only works with numbers,
but an equivalent that works with sounds (including control signals) is
"DIFF"

(diff X Y) means "X - Y" and it works with both sounds and numbers, so
to subtracts "eps" from the envelope:

(diff (pwev eps attack amp duration eps))

and assign this as the value of a variable that I called "envelope":

(setf envelope (diff (pwev eps attack amp duration eps) eps))


The final line simply multiplies the generated sound by the envelope.
The only new thing here is that I use "stretch duration", otherwise we
would
have only had one second of sound (because we are still inside the
"abs-env" function.


That's it.
Hope that's useful.

Steve



On 19 May 2015 at 06:05, Stan Bobbitt <sbobbitt@xxxxxxxxxxxx> wrote:
Hi yall,
I have been following this thread and I'm very interested as well.

Stan B
-----Original Message----- From: Annabelle Susan Morison
Sent: Monday, May 18, 2015 7:55 PM

To: audacity4blind@xxxxxxxxxxxxx
Subject: [audacity4blind] Re: Tone Generator

I would kindly appreciate it if you could please send me a detailed
description of this code.

-----Original Message-----
From: audacity4blind-bounce@xxxxxxxxxxxxx
[mailto:audacity4blind-bounce@xxxxxxxxxxxxx] On Behalf Of Steve the
Fiddle
Sent: Monday, May 18, 2015 4:46 PM
To: audacity4blind@xxxxxxxxxxxxx
Subject: [audacity4blind] Re: Tone Generator

The second to last line creates an "envelope" that shapes the note so
that
rather than getting a boring "beeeep" you get a bell-like "ding".
The final line is the one that creates the sound. The actual generator
part
is
(osc-tri frequency) which creates a triangle wave at the specified
frequency,
but we have multiplied that tone by the envelope created in the previous
line.

If you want a more detailed description of the code, just ask.

Steve

On 19 May 2015 at 00:33, Annabelle Susan Morison
<foristnights@xxxxxxxxxxx>
wrote:

What do the last two lines of code mean?

-----Original Message-----
From: audacity4blind-bounce@xxxxxxxxxxxxx
[mailto:audacity4blind-bounce@xxxxxxxxxxxxx] On Behalf Of Steve the
Fiddle
Sent: Monday, May 18, 2015 4:30 PM
To: audacity4blind@xxxxxxxxxxxxx
Subject: [audacity4blind] Re: Tone Generator

You can actually do the whole thing in Nyquist.
Here are 8 lines of code that may be copied and pasted into the
Nyquist prompt.
You will need to select part of a track to generate the note into, but
it does not matter how long the selection is because the duration is
set by the "duration" parameter in the code:

(abs-env
(let ((eps 0.0001)
(attack 0.001)
(amp 0.3)
(duration 2.5)
(frequency 1760))
(setf envelope (diff (pwev eps attack amp duration eps) eps)) (mult
envelope (stretch duration (osc-tri frequency)))))

Steve

On 18 May 2015 at 23:50, Annabelle Susan Morison
<foristnights@xxxxxxxxxxx> wrote:

Could you give me an example of what that would sound like?

-----Original Message-----
From: audacity4blind-bounce@xxxxxxxxxxxxx
[mailto:audacity4blind-bounce@xxxxxxxxxxxxx] On Behalf Of David
Engebretson Jr.
Sent: Monday, May 18, 2015 3:45 PM
To: audacity4blind@xxxxxxxxxxxxx
Subject: [audacity4blind] Re: Tone Generator

Instead of selecting a quarter of a second, select a half second on
either side of the beginning and end of the 1 second file with the
steps I provided. That would be a true triangle

Best,
d


--------------------------------------------------
From: "Annabelle Susan Morison" <foristnights@xxxxxxxxxxx>
Sent: Monday, May 18, 2015 3:39 PM
To: <audacity4blind@xxxxxxxxxxxxx>
Subject: [audacity4blind] Re: Tone Generator

How would someone blind do that, I wonder?

-----Original Message-----
From: audacity4blind-bounce@xxxxxxxxxxxxx
[mailto:audacity4blind-bounce@xxxxxxxxxxxxx] On Behalf Of David
Engebretson Jr.
Sent: Monday, May 18, 2015 3:35 PM
To: audacity4blind@xxxxxxxxxxxxx
Subject: [audacity4blind] Re: Tone Generator

Yah! You could make the sound more bellish by making a sharper
point on the

triangle.

Best,
David


--------------------------------------------------
From: "Annabelle Susan Morison" <foristnights@xxxxxxxxxxx>
Sent: Monday, May 18, 2015 1:42 PM
To: <audacity4blind@xxxxxxxxxxxxx>
Subject: [audacity4blind] Re: Tone Generator

Sounds like a flute to me.

-----Original Message-----
From: audacity4blind-bounce@xxxxxxxxxxxxx
[mailto:audacity4blind-bounce@xxxxxxxxxxxxx] On Behalf Of David
Engebretson Jr.
Sent: Monday, May 18, 2015 1:33 PM
To: audacity4blind@xxxxxxxxxxxxx
Subject: [audacity4blind] Re: Tone Generator

Hey, that's a neat challenge! Here's what I did to create the
tone I've
attached:

1. Generate->Silence->1 second
2. Ctrl+'a' to select all.
3. Alt+'c' (Effect menu)-> Nyquist prompt 4. Typed: (osc-tri 440),
tabbed to OK and pressed enter.
5. Right arrowed about 1/4 of a second, pressed shift+'j' to select.
6. Alt+'c', pressed 'f' to jump to Fade In and pressed Enter.
7. Left arrowed about 1/4 of a second, pressed shift+'k' to select.
8. Alt+'c', pressed 'f' to jump to Fade Out and pressed Enter.

It's kind of fun to Change Speed on the file to get the different
notes.
It
makes it sound a lot more like the plinky sound in the file you
attached.
Change Speed is also under the Effect (alt+'c') menu.

I know it's not exactly like the sound in your file, but maybe it
helps get started creating your own?

Best,
David




--------------------------------------------------
From: "Annabelle Susan Morison" <foristnights@xxxxxxxxxxx>
Sent: Monday, May 18, 2015 12:23 PM
To: <audacity4blind@xxxxxxxxxxxxx>
Subject: [audacity4blind] Re: Tone Generator

I wonder, how would I make triangle tones that sound like piano
notes?
As heard in this example.

-----Original Message-----
From: audacity4blind-bounce@xxxxxxxxxxxxx
[mailto:audacity4blind-bounce@xxxxxxxxxxxxx] On Behalf Of Steve
the Fiddle
Sent: Tuesday, April 28, 2015 5:01 PM
To: audacity4blind@xxxxxxxxxxxxx
Subject: [audacity4blind] Re: Tone Generator

No the built-in generator does not do triangle tones, but you can
generate triangle tones using the Nyquist Prompt effect.

If you select part of a track, open the Nyquist Prompt effect, and
enter the following command (note that the parentheses are
essential), it will generate a 0 dB (full scale) triangle tone in
the selection at 440 Hz. Here is the code:
(osc-tri 440)

For a different frequency, just change the 440 to whatever
frequency you require.
To create a tone at lower amplitude, you can either, apply the
Amplify effect to the generated tone, with a negative
amplification amount, or you can extend the code a little. For
example, to create a 1000 Hz triangle tone with an amplitude of -6
dB (which is half of the full scale amplitude) - the code is:

(mult 0.5 (osc-tri 1000))

Steve

On 28 April 2015 at 23:24, Annabelle Susan Morison
<foristnights@xxxxxxxxxxx> wrote:

Hi, it's Annabelle.
I know the tone generator within Audacity can generate sine,
square, sawtooth, and square no alias tones, but I wonder if it's
possible that this generator can generate triangle tones.


The audacity4blind web site is at
//www.freelists.org/webpage/audacity4blind

Subscribe and unsubscribe information, message archives, Audacity
keyboard commands, and more...

To unsubscribe from audacity4blind, send an email to
audacity4blind-request@xxxxxxxxxxxxx
with subject line
unsubscribe








The audacity4blind web site is at
//www.freelists.org/webpage/audacity4blind

Subscribe and unsubscribe information, message archives, Audacity
keyboard commands, and more...

To unsubscribe from audacity4blind, send an email to
audacity4blind-request@xxxxxxxxxxxxx
with subject line
unsubscribe




The audacity4blind web site is at
//www.freelists.org/webpage/audacity4blind

Subscribe and unsubscribe information, message archives, Audacity
keyboard commands, and more...

To unsubscribe from audacity4blind, send an email to
audacity4blind-request@xxxxxxxxxxxxx
with subject line
unsubscribe


The audacity4blind web site is at
//www.freelists.org/webpage/audacity4blind

Subscribe and unsubscribe information, message archives, Audacity
keyboard commands, and more...

To unsubscribe from audacity4blind, send an email to
audacity4blind-request@xxxxxxxxxxxxx
with subject line
unsubscribe



The audacity4blind web site is at
//www.freelists.org/webpage/audacity4blind

Subscribe and unsubscribe information, message archives, Audacity
keyboard commands, and more...

To unsubscribe from audacity4blind, send an email to
audacity4blind-request@xxxxxxxxxxxxx
with subject line
unsubscribe


The audacity4blind web site is at
//www.freelists.org/webpage/audacity4blind

Subscribe and unsubscribe information, message archives, Audacity
keyboard commands, and more...

To unsubscribe from audacity4blind, send an email to
audacity4blind-request@xxxxxxxxxxxxx
with subject line
unsubscribe



The audacity4blind web site is at
//www.freelists.org/webpage/audacity4blind

Subscribe and unsubscribe information, message archives, Audacity
keyboard commands, and more...

To unsubscribe from audacity4blind, send an email to
audacity4blind-request@xxxxxxxxxxxxx
with subject line
unsubscribe


The audacity4blind web site is at
//www.freelists.org/webpage/audacity4blind

Subscribe and unsubscribe information, message archives, Audacity
keyboard commands, and more...

To unsubscribe from audacity4blind, send an email to
audacity4blind-request@xxxxxxxxxxxxx
with subject line
unsubscribe



The audacity4blind web site is at
//www.freelists.org/webpage/audacity4blind

Subscribe and unsubscribe information, message archives, Audacity
keyboard commands, and more...

To unsubscribe from audacity4blind, send an email to
audacity4blind-request@xxxxxxxxxxxxx
with subject line
unsubscribe


The audacity4blind web site is at
//www.freelists.org/webpage/audacity4blind

Subscribe and unsubscribe information, message archives, Audacity
keyboard
commands, and more...

To unsubscribe from audacity4blind, send an email to
audacity4blind-request@xxxxxxxxxxxxx
with subject line
unsubscribe



The audacity4blind web site is at
//www.freelists.org/webpage/audacity4blind

Subscribe and unsubscribe information, message archives,
Audacity keyboard commands, and more...

To unsubscribe from audacity4blind, send an email to
audacity4blind-request@xxxxxxxxxxxxx
with subject line
unsubscribe



The audacity4blind web site is at
//www.freelists.org/webpage/audacity4blind

Subscribe and unsubscribe information, message archives,
Audacity keyboard commands, and more...

To unsubscribe from audacity4blind, send an email to
audacity4blind-request@xxxxxxxxxxxxx
with subject line
unsubscribe


The audacity4blind web site is at
//www.freelists.org/webpage/audacity4blind

Subscribe and unsubscribe information, message archives,
Audacity keyboard commands, and more...

To unsubscribe from audacity4blind, send an email to
audacity4blind-request@xxxxxxxxxxxxx
with subject line
unsubscribe



The audacity4blind web site is at
//www.freelists.org/webpage/audacity4blind

Subscribe and unsubscribe information, message archives,
Audacity keyboard commands, and more...

To unsubscribe from audacity4blind, send an email to
audacity4blind-request@xxxxxxxxxxxxx
with subject line
unsubscribe


The audacity4blind web site is at
//www.freelists.org/webpage/audacity4blind

Subscribe and unsubscribe information, message archives,
Audacity keyboard commands, and more...

To unsubscribe from audacity4blind, send an email to
audacity4blind-request@xxxxxxxxxxxxx
with subject line
unsubscribe



The audacity4blind web site is at
//www.freelists.org/webpage/audacity4blind

Subscribe and unsubscribe information, message archives,
Audacity keyboard commands, and more...

To unsubscribe from audacity4blind, send an email to
audacity4blind-request@xxxxxxxxxxxxx
with subject line
unsubscribe


The audacity4blind web site is at
//www.freelists.org/webpage/audacity4blind

Subscribe and unsubscribe information, message archives,
Audacity keyboard commands, and more...

To unsubscribe from audacity4blind, send an email to
audacity4blind-request@xxxxxxxxxxxxx
with subject line
unsubscribe

Other related posts: