Re: [Audacity-nyquist] Reducing the volume on part of a sound.
A free multi-track audio editor and recorder
Brought to you by:
aosiniao
From: Dominic M. <do...@au...> - 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: aud...@li... on behalf of David R. Sky > Sent: Fri 2/3/2006 6:55 PM > To: aud...@li... > 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. >> >> > |