Plugin to find sample value in unsigned integer

Using Nyquist scripts in Audacity.
Post and download new plug-ins.

If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like

Incremental control in audacity plugin using nyquist prompt

Permanent link to this post Posted by abivenera » Mon Aug 29, 2016 6:14 am

I am new to audacity.I am trying to learn nyquist prompt in audacity to develop a plugin.I want to develop a plugin which will provide the sample values of a given audio in a given time range .What I want is that there should be a button in the UI clicking which provides the sample value of next sample in the range and so on till I require.I want to know is it possible ?? Because what I have searched and saw is that using ";control" we can make the user specify a value or using "control" we can make the user select a value from a drop down kind of menu. So is it possible to make a next button that will let me achieve my target ????
abivenera
 
Posts: 11
Joined: Mon Aug 29, 2016 6:09 am
Operating System: Windows 8 or 8.1

Re: Incremental control in audacity plugin using nyquist pro

Permanent link to this post Posted by steve » Mon Aug 29, 2016 10:51 am

Topic moved to the "Nyquist" board.

abivenera wrote:What I want is that there should be a button in the UI clicking which provides the sample value of next sample in the range and so on till I require.I want to know is it possible ??

No, that's not possible. Nyquist in Audacity is not interactive.
What you could do is to make a plug-in that stores a value in the special "*SCRATCH*" variable, then uses that value the next time the plug-in runs.
*SCRATCH* is documented here: http://wiki.audacityteam.org/wiki/Nyqui ... .2A_Symbol

A simple example of using *scratch* is given below. This example can be run in the Nyquist Prompt effect (http://manual.audacityteam.org/man/nyquist_prompt.html).
Code: Select all
;control reset "Reset to zero" choice "No,Yes" 0
;control val "Add to previous value" int "" 1 1 10

(cond
  ((= reset 1)
      (when (boundp '*scratch*)
        (setf *scratch* '*unbound*))
      (format nil "Plug-in has been reset."))
  ((boundp '*scratch*)
      (let ((old *scratch*))
        (setf *scratch* (+ *scratch* val))
        (format nil "~a + ~a = ~a" old val *scratch*)))
  (t  (setf *scratch* val)
      (format nil "0 + ~a = ~a" val *scratch*)))
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 45326
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Plugin to find sample value in unsigned integer

Permanent link to this post Posted by abivenera » Mon Aug 29, 2016 12:41 pm

I am trying to make a plugin in which i want to know the sample value of Nth sample.What I want is that the plugin should ask for the value of N and it must display the value of Nth sample .Is it possible to find the value of Nth sample if the audio is not starting from 0 second , means I want to know the value of Nth sample if I select a region ???? What command to use to get the value of Nth sample. I used -

(print (sref s (+ (/ myvalue (snd-srate s)) (snd-t0 s))))

to find the value of Nth sample from start.But the result shown is in dB (probably) and is also not in agreement with the value of samples i have dumped in a text file...........Any help in this regard ?? I am stuck to this issue for quite some time now.
abivenera
 
Posts: 11
Joined: Mon Aug 29, 2016 6:09 am
Operating System: Windows 8 or 8.1

Re: Plugin to find sample value in unsigned integer

Permanent link to this post Posted by steve » Mon Aug 29, 2016 3:23 pm

Merged topics and moved to Nyquist forum.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 45326
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Plugin to find sample value in unsigned integer

Permanent link to this post Posted by steve » Mon Aug 29, 2016 3:33 pm

abivenera wrote:What command to use to get the value of Nth sample

Try this:
Code: Select all
(abs-env (print (sref *track* (/ sample-number *sound-srate*))))

Note that this uses the "version 4" syntax, so if running in the Nyquist Prompt, ensure that "legacy (version 3) syntax" is NOT selected.
The returned value is 32-bit float, where the linear range is +/- 1.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 45326
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Plugin to find sample value in unsigned integer

Permanent link to this post Posted by steve » Mon Aug 29, 2016 3:46 pm

I suspect that the problem you were running into is due to the way that Nyquist handles time in Audacity.
In "generate" type plug-ins, "local" time is the same as "global" time, where snd-t0 is the start of the selection. Thus 1 second in local time is 1 second in actual (global) time.

In "process" and "analyze" type plug-ins, the default environment is warped such that the length of the selection is 1. Thus 1 second in local time is the length of the selection.

(ABS-ENV behaviour) forces the behaviour to be calculated with actual time values regardless of the type of plug-in.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 45326
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Plugin to find sample value in unsigned integer

Permanent link to this post Posted by abivenera » Tue Aug 30, 2016 8:10 am

@steve
Hii steve the command you specified -

(abs-env (print (sref *track* (/ sample-number *sound-srate*))))

This command is giving me the sample-number and not its value. Can you help me on this ??
abivenera
 
Posts: 11
Joined: Mon Aug 29, 2016 6:09 am
Operating System: Windows 8 or 8.1

Re: Plugin to find sample value in unsigned integer

Permanent link to this post Posted by abivenera » Tue Aug 30, 2016 9:48 am

Even after using ABS-ENV the sample value given by my plugin is different from the sample value dumped in a file by using "Sample-data export" Plugin of audacity. Any help in this regard ???
I am stuck to this issue for quite some time now . Can anyone help me how "Sample-data export" Plugin of audacity is calculating sample values.????
abivenera
 
Posts: 11
Joined: Mon Aug 29, 2016 6:09 am
Operating System: Windows 8 or 8.1

Re: Plugin to find sample value in unsigned integer

Permanent link to this post Posted by steve » Tue Aug 30, 2016 12:16 pm

Tested with the first 20 samples from a mono 440 Hz Sine tone, amplitude 0.8:

Sample Data Export:
Code: Select all
sample-data.txt   1 channel (mono)
Sample Rate: 44100 Hz. Sample values on linear scale.
Length processed: 20 samples 0.00045 seconds.


1   0.00000
2   0.06265
3   0.12505
4   0.18696
5   0.24814
6   0.30834
7   0.36733
8   0.42488
9   0.48075
10   0.53474
11   0.58663
12   0.63622
13   0.68330
14   0.72770
15   0.76924
16   0.80776
17   0.84310
18   0.87514
19   0.90373
20   0.92878



Copied from the Debug output of the Nyquist Prompt (Click the "Debug" button instead of the "OK" button) using this code;
Code: Select all
(setf output "")  ;initialize output string
(setf *float-format* "%.5f")  ;output to 5 decimal places

;; Loop 20 times and return output string to debug window
(dotimes (i 20 (format t output))
  (setf output
    (abs-env
      (format nil "~a~%~a ~a"
          output
          (1+ i)
          (sref *track* (/ i *sound-srate*))))))

;Return output string
output

The output:
Code: Select all

1 0.00000
2 0.06265
3 0.12505
4 0.18696
5 0.24814
6 0.30834
7 0.36733
8 0.42488
9 0.48075
10 0.53474
11 0.58663
12 0.63622
13 0.68330
14 0.72770
15 0.76924
16 0.80776
17 0.84310
18 0.87514
19 0.90373
20 0.92878
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 45326
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Plugin to find sample value in unsigned integer

Permanent link to this post Posted by steve » Tue Aug 30, 2016 12:24 pm

The settings that I used for Sample Data Export:

fullwindow-Sample Data Export-000.png
fullwindow-Sample Data Export-000.png (38.85 KiB) Viewed 1116 times
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 45326
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Next

Return to Nyquist



Who is online

Users browsing this forum: No registered users and 3 guests