## Re: [Audacity-nyquist] Reducing the volume on part of a sound.

 Re: [Audacity-nyquist] Reducing the volume on part of a sound. From: David R. Sky - 2006-02-03 05:55:16 ```Hi Rachael, For this, you'd first need to determine the length (duration) of your sample in seconds, which you can only do in Audacity 1.2.3 and later. The global variable len gives you the number of samples in your selection, then you need to calculate time duration by dividing len by the sample rate: (setf dur (/ len *sound-srate*)) Rachael: * I can use the (loud) function to reduce the volume, and (scale-db), but neither seem to work in percentages. Is there a way to find how loud a sound is in decibels? David: For what you want to do, finding the volume isn't necessary. To reduce your full selection a certain percent (eg. 20%), all you'd need to do is (mult 0.8 s) or (scale 0.8 s) or (scale-db (linear-to-db 0.8) s) The above works for mono and stereo audio in Audacity (not all Nyquist functions do but there are ways around this). Rachael: * How do I reduce the volume of a part of a sound? David: I'd use a pwl (piece wise linear) function, which is a series of time/level pairs: (mult (pwl 0 1 start 1 start volume end volume end 1 1) s) You need to be very specific about what level at what time. If for example you left out start 1 then instead of staying at constant volume until your start time, your audio would gradually reduce in volume from time 0 to start time. When you've made a selection in Audacity, pwl works in percentages of the selection duration not time in seconds, so you'd need to calculate the start and end times as percentages of duration dur. Even though it's imprecise, it doesn't appear to matter whether the duration of your volume reduction is greater than the length of your selection: the volume stays at the reduced level until the end of the selection. If you have abrupt jumps in volume as I've done with pwl above, you'll notice a click at the start and end times, you can use a short fade time. Hope this helps David On Fri, 3 Feb 2006, RACHAEL MAREE,HUNT wrote: > > Hi, > > Before subscribing to the list I sent this email to the list and was "awaiting moderation"... I'm a bit impatient, and joined a couple of days later. Here's hoping that I don't get a double post. > > I am a beginner to Nyquist / Lisp. That said, I am attemping to write an Audacity "filter" / plugin. (Hehe!) > > Ideally I would like to select 1-2 seconds of stereo audio in Audacity, tell the plugin a start time (within the sample i.e. 0.5 seconds in), a volume reduction in %, and a reduction length. The plugin would check whether the start time and reduction length fall within the bounds of the sample then reduce only that section of sound. > > Is this even possible? > > Now, I know that Audacity stores the selected sound in the s variable, and that I'd have to write a function to do this. However, there are a few things I don't know... > * I can use the (loud) function to reduce the volume, and (scale-db), but neither seem to work in percentages. Is there a way to find how loud a sound is in decibels? > * How do I reduce the volume of a part of a sound? Do I have to change it to an array / vector? If so, what is the relationship between array members and time? > > Thanks in advance for your help! > > Rachael. > > ```

 [Audacity-nyquist] Reducing the volume on part of a sound. From: RACHAEL MAREE,HUNT - 2006-02-03 00:38:30 Attachments: Message as HTML ```Hi, Before subscribing to the list I sent this email to the list and was = "awaiting moderation"... I'm a bit impatient, and joined a couple of = days later. Here's hoping that I don't get a double post. I am a beginner to Nyquist / Lisp. That said, I am attemping to write an = Audacity "filter" / plugin. (Hehe!)=20 Ideally I would like to select 1-2 seconds of stereo audio in Audacity, = tell the plugin a start time (within the sample i.e. 0.5 seconds in), a = volume reduction in %, and a reduction length. The plugin would check = whether the start time and reduction length fall within the bounds of = the sample then reduce only that section of sound. Is this even possible? Now, I know that Audacity stores the selected sound in the s variable, = and that I'd have to write a function to do this. However, there are a = few things I don't know... * I can use the (loud) function to reduce the volume, and (scale-db), = but neither seem to work in percentages. Is there a way to find how loud = a sound is in decibels? * How do I reduce the volume of a part of a sound? Do I have to change = it to an array / vector? If so, what is the relationship between array = members and time? Thanks in advance for your help! Rachael. ```
 Re: [Audacity-nyquist] Reducing the volume on part of a sound. From: Sami Jumppanen - 2006-02-03 05:49:08 ```> Is there a way to find how loud a sound is in decibels? By calculating it yourself (not in Nyquist here, sorry): dB =3D Log10(peak/max) * 20 This gives zero for max level and negative dB values below that. For example, "half" of the max volume is: Log10(0.5) * 20 =3D -6.0 dB -- Sami "Some-E" Jumppanen sami.jumppanen@... http://netti.nic.fi/~some-e/ ```
 Re: [Audacity-nyquist] Reducing the volume on part of a sound. From: David R. Sky - 2006-02-03 05:55:16 ```Hi Rachael, For this, you'd first need to determine the length (duration) of your sample in seconds, which you can only do in Audacity 1.2.3 and later. The global variable len gives you the number of samples in your selection, then you need to calculate time duration by dividing len by the sample rate: (setf dur (/ len *sound-srate*)) Rachael: * I can use the (loud) function to reduce the volume, and (scale-db), but neither seem to work in percentages. Is there a way to find how loud a sound is in decibels? David: For what you want to do, finding the volume isn't necessary. To reduce your full selection a certain percent (eg. 20%), all you'd need to do is (mult 0.8 s) or (scale 0.8 s) or (scale-db (linear-to-db 0.8) s) The above works for mono and stereo audio in Audacity (not all Nyquist functions do but there are ways around this). Rachael: * How do I reduce the volume of a part of a sound? David: I'd use a pwl (piece wise linear) function, which is a series of time/level pairs: (mult (pwl 0 1 start 1 start volume end volume end 1 1) s) You need to be very specific about what level at what time. If for example you left out start 1 then instead of staying at constant volume until your start time, your audio would gradually reduce in volume from time 0 to start time. When you've made a selection in Audacity, pwl works in percentages of the selection duration not time in seconds, so you'd need to calculate the start and end times as percentages of duration dur. Even though it's imprecise, it doesn't appear to matter whether the duration of your volume reduction is greater than the length of your selection: the volume stays at the reduced level until the end of the selection. If you have abrupt jumps in volume as I've done with pwl above, you'll notice a click at the start and end times, you can use a short fade time. Hope this helps David On Fri, 3 Feb 2006, RACHAEL MAREE,HUNT wrote: > > Hi, > > Before subscribing to the list I sent this email to the list and was "awaiting moderation"... I'm a bit impatient, and joined a couple of days later. Here's hoping that I don't get a double post. > > I am a beginner to Nyquist / Lisp. That said, I am attemping to write an Audacity "filter" / plugin. (Hehe!) > > Ideally I would like to select 1-2 seconds of stereo audio in Audacity, tell the plugin a start time (within the sample i.e. 0.5 seconds in), a volume reduction in %, and a reduction length. The plugin would check whether the start time and reduction length fall within the bounds of the sample then reduce only that section of sound. > > Is this even possible? > > Now, I know that Audacity stores the selected sound in the s variable, and that I'd have to write a function to do this. However, there are a few things I don't know... > * I can use the (loud) function to reduce the volume, and (scale-db), but neither seem to work in percentages. Is there a way to find how loud a sound is in decibels? > * How do I reduce the volume of a part of a sound? Do I have to change it to an array / vector? If so, what is the relationship between array members and time? > > Thanks in advance for your help! > > Rachael. > > ```
 RE: [Audacity-nyquist] Reducing the volume on part of a sound. From: RACHAEL MAREE,HUNT - 2006-02-08 07:35:17 Attachments: application/ms-tnef ```Hi, thanks for your suggestions. I have put them in a simple function, but I = am unable to get the function to work... How does Audacity call a = nyquist function in a plugin? I am currently using Audacity 1.2.3.=20 Here's the psuedo-code version: ; audacity header ; three controls with variables volR (int for percentage), volLen (real = for seconds), startTime (real for seconds) (defun changeVol (s volR volLen startTime)=20 ( ; setting duration, start and end time as percentages, and volume to = a "real" percent (mult (pwl 0 1 start 1 start volume end volume end 1 1) s) ) ) When I run the code version of this it doesn't return any audio. So I = thought that I had to call the function. I know that audacity treats any = line in the plugin as a command. So I tried adding the following after = defining the function: (changeVol (s volR volLen startTime) but still no audio was returned... Going back to grass-roots, I tried creating a simple scale plugin. ;audacity headers ;a control with variable scaleVol (int for percentage) (defun scaleVol (s scaleVol) ((scale-db (linear-to-db (/ scaleVol 100)) s)) ) Which still returned no audio. What am I missing? Thanks again! Rach' -----Original Message----- From: audacity-nyquist-admin@... on behalf of David R. = Sky Sent: Fri 2/3/2006 6:55 PM To: audacity-nyquist@... Subject: Re: [Audacity-nyquist] Reducing the volume on part of a sound. =20 Hi Rachael, For this, you'd first need to determine the length (duration) of your sample in seconds, which you can only do in Audacity 1.2.3 and later. The global variable len gives you the number of samples in your selection, then you need to calculate time duration by dividing len by the sample rate: (setf dur (/ len *sound-srate*)) Rachael: * I can use the (loud) function to reduce the volume, and (scale-db), but neither seem to work in percentages. Is there a way to find how loud a sound is in decibels? David: For what you want to do, finding the volume isn't necessary. To reduce your full selection a certain percent (eg. 20%), all you'd need to do is (mult 0.8 s) or (scale 0.8 s) or (scale-db (linear-to-db 0.8) s) The above works for mono and stereo audio in Audacity (not all Nyquist functions do but there are ways around this). Rachael: * How do I reduce the volume of a part of a sound? David: I'd use a pwl (piece wise linear) function, which is a series of time/level pairs: (mult (pwl 0 1 start 1 start volume end volume end 1 1) s) You need to be very specific about what level at what time. If for example you left out start 1 then instead of staying at constant volume until your start time, your audio would gradually reduce in volume from time 0 to start time. When you've made a selection in Audacity, pwl works in percentages of the selection duration not time in seconds, so you'd need to calculate the start and end times as percentages of duration dur. Even though it's imprecise, it doesn't appear to matter whether the duration of your volume reduction is greater than the length of your selection: the volume stays at the reduced level until the end of the selection. If you have abrupt jumps in volume as I've done with pwl above, you'll notice a click at the start and end times, you can use a short fade time. Hope this helps David On Fri, 3 Feb 2006, RACHAEL MAREE,HUNT wrote: > > Hi, > > Before subscribing to the list I sent this email to the list and was = "awaiting moderation"... I'm a bit impatient, and joined a couple of = days later. Here's hoping that I don't get a double post. > > I am a beginner to Nyquist / Lisp. That said, I am attemping to write = an Audacity "filter" / plugin. (Hehe!) > > Ideally I would like to select 1-2 seconds of stereo audio in = Audacity, tell the plugin a start time (within the sample i.e. 0.5 = seconds in), a volume reduction in %, and a reduction length. The plugin = would check whether the start time and reduction length fall within the = bounds of the sample then reduce only that section of sound. > > Is this even possible? > > Now, I know that Audacity stores the selected sound in the s variable, = and that I'd have to write a function to do this. However, there are a = few things I don't know... > * I can use the (loud) function to reduce the volume, and (scale-db), = but neither seem to work in percentages. Is there a way to find how loud = a sound is in decibels? > * How do I reduce the volume of a part of a sound? Do I have to = change it to an array / vector? If so, what is the relationship between = array members and time? > > Thanks in advance for your help! > > Rachael. > > ```
 RE: [Audacity-nyquist] Reducing the volume on part of a sound. From: David R. Sky - 2006-02-08 20:51:58 ```Hi Rachael, I've enclosed my comments within #| comments... |# which you can use when you have a lot of comments, without worrying about word wrapping. A ; comment must not be word wrapped, as your first comment within your defun below does. Also, could you send plain text attachments, I can't read Windows attachments since I'm using DOS for text editing. use Notepad to do this. because I couldn't read your attachment, I wasn't able to check your "genuine" code. This way of sending attachments seems to be standard for Nyquist plug-ins. When you have a problem with a plug, click on 'debug' when you run it, which will give you specific feedback about what's wrong. You may not understand the message, but we will. If you're using Windows, control+a control+c doesn't work to copy the message into your clipboard, use shift+f11 select all, shift+f11 copy. Then you can paste your clipboard into your email to us. David ; audacity header ; three controls with variables volR (int for percentage), volLen (real for seconds), startTime (real for seconds) (defun changeVol (s volR volLen startTime) #| You have one more left paren than right paren, make sure there are equal numbers of both. |# ( ; setting duration, start and end time as percentages, and volume to a "real" percent (mult (pwl 0 1 start 1 start volume end volume end 1 1) s) ) ) When I run the code version of this it doesn't return any audio. So I thought that I had to call the function. I know that audacity treats any line in the plugin as a command. So I tried adding the following after defining the function: (changeVol (s volR volLen startTime) #| After you've defined a function such as yours: (changeVol s volR volLen startTime) |# ```
 Re: [Audacity-nyquist] Reducing the volume on part of a sound. From: Dominic Mazzoni - 2006-02-08 22:43:35 ```Hi, Here's how Nyquist works within Audacity: when you execute a plug-in function, the current selected audio is stored in the variable "s". All of your Nyquist code is executed line-by-line, and the result of the final expression is what is returned to Audacity - if it's audio, that audio will replace your previous selection. A defun doesn't actually _do_ anything, it just defines a function. So what you need to do is add a line at the bottom that actually applies the function to s, for example: (defun changeVol (s x y z) ... ) (changeVol s 0.1 0.3 0.5) In place of 0.1, 0.3, 0.5, you could stick control parameters, of course. I hope that makes sense. - Dominic RACHAEL MAREE,HUNT wrote: > Hi, > > thanks for your suggestions. I have put them in a simple function, but I am unable to get the function to work... How does Audacity call a nyquist function in a plugin? I am currently using Audacity 1.2.3. > > Here's the psuedo-code version: > > ; audacity header > ; three controls with variables volR (int for percentage), volLen (real for seconds), startTime (real for seconds) > > (defun changeVol (s volR volLen startTime) > ( ; setting duration, start and end time as percentages, and volume to a "real" percent > (mult (pwl 0 1 start 1 start volume end volume end 1 1) s) > ) > ) > > When I run the code version of this it doesn't return any audio. So I thought that I had to call the function. I know that audacity treats any line in the plugin as a command. So I tried adding the following after defining the function: > (changeVol (s volR volLen startTime) > but still no audio was returned... > > Going back to grass-roots, I tried creating a simple scale plugin. > > ;audacity headers > ;a control with variable scaleVol (int for percentage) > > (defun scaleVol (s scaleVol) > ((scale-db (linear-to-db (/ scaleVol 100)) s)) > ) > > Which still returned no audio. What am I missing? > > Thanks again! > > Rach' > > -----Original Message----- > From: audacity-nyquist-admin@... on behalf of David R. Sky > Sent: Fri 2/3/2006 6:55 PM > To: audacity-nyquist@... > Subject: Re: [Audacity-nyquist] Reducing the volume on part of a sound. > > Hi Rachael, > > For this, you'd first need to determine the length (duration) of > your sample in seconds, which you can only do in Audacity 1.2.3 and > later. The global variable len gives you the number of samples in > your selection, then you need to calculate time duration by > dividing len by the sample rate: > > (setf dur (/ len *sound-srate*)) > > Rachael: * I can use the (loud) function to reduce the volume, > and (scale-db), but neither seem to work in percentages. Is there > a way to find how loud a sound is in decibels? > > David: For what you want to do, finding the volume isn't necessary. > To reduce your full selection a certain percent (eg. 20%), all > you'd need to do is > > (mult 0.8 s) > > or > > (scale 0.8 s) > > or > > (scale-db (linear-to-db 0.8) s) > > The above works for mono and stereo audio in Audacity (not all > Nyquist functions do but there are ways around this). > > Rachael: * How do I reduce the volume of a part of a sound? > > David: I'd use a pwl (piece wise linear) function, which is a > series of time/level pairs: > > (mult (pwl 0 1 start 1 start volume end volume end 1 1) s) > > You need to be very specific about what level at what time. If for > example you left out > > start 1 > > then instead of staying at constant volume until your start time, > your audio would gradually reduce in volume from time 0 to start > time. > > When you've made a selection in Audacity, pwl works in percentages > of the selection duration not time in seconds, so you'd need to > calculate the start and end times as percentages of duration dur. > > Even though it's imprecise, it doesn't appear to matter whether the > duration of your volume reduction is greater than the length of > your selection: the volume stays at the reduced level until the end > of the selection. > > If you have abrupt jumps in volume as I've done with pwl above, > you'll notice a click at the start and end times, you can use a > short fade time. > > Hope this helps > > David > > On Fri, 3 Feb 2006, RACHAEL MAREE,HUNT wrote: > >> Hi, >> >> Before subscribing to the list I sent this email to the list and was "awaiting moderation"... I'm a bit impatient, and joined a couple of days later. Here's hoping that I don't get a double post. >> >> I am a beginner to Nyquist / Lisp. That said, I am attemping to write an Audacity "filter" / plugin. (Hehe!) >> >> Ideally I would like to select 1-2 seconds of stereo audio in Audacity, tell the plugin a start time (within the sample i.e. 0.5 seconds in), a volume reduction in %, and a reduction length. The plugin would check whether the start time and reduction length fall within the bounds of the sample then reduce only that section of sound. >> >> Is this even possible? >> >> Now, I know that Audacity stores the selected sound in the s variable, and that I'd have to write a function to do this. However, there are a few things I don't know... >> * I can use the (loud) function to reduce the volume, and (scale-db), but neither seem to work in percentages. Is there a way to find how loud a sound is in decibels? >> * How do I reduce the volume of a part of a sound? Do I have to change it to an array / vector? If so, what is the relationship between array members and time? >> >> Thanks in advance for your help! >> >> Rachael. >> >> > ```