# Zero Crossing detection

**URL:** <https://forum.audacityteam.org/t/zero-crossing-detection/26237>\
**Category:** Nyquist\
**Created:** [September 10, 2012, 7:51pm UTC](https://forum.audacityteam.org/t/zero-crossing-detection/26237 "2012-09-10T19:51:54Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![Paul\_L](https://forum.audacityteam.org/letter_avatar_proxy/v4/letter/p/7c8e57/32.png) [@Paul\_L](https://forum.audacityteam.org/u/Paul_L)\
**Post date:** [April 25, 2013, 5:17pm UTC](https://forum.audacityteam.org/t/zero-crossing-detection/26237/21 "2013-04-25T17:17:50Z")

</div>

I do not understand your answer. The function get-duration takes a number, not a sound. I do not find a Nyquist function called “len”. Are you referring to global variables?

---

<div class="post-metadata">

**Author:** ![steve](https://forum.audacityteam.org/letter_avatar_proxy/v4/letter/s/f19dbf/32.png) [@steve](https://forum.audacityteam.org/u/steve)\
**Post date:** [April 25, 2013, 6:16pm UTC](https://forum.audacityteam.org/t/zero-crossing-detection/26237/22 "2013-04-25T18:16:35Z")

</div>

From the manual:  
**(get-duration dur) [LISP]  
Gets the actual duration of of something starting at a local time of 0 and ending at a local time of dur times the current sustain. For convenience, _rslt_ is set to the global time corresponding to local time zero**  
The implication for this for effects in Audacity is that you can get the duration of a selection with (get-duration 1)

LEN is a global that gives the number of samples in a selection.  
It is also used by Audacity for estimating the progress bar, which can be useful in generator plug-ins as you can provide a hint to Audacity of how long it will take to generate a sound by setting LEN to the expected length of the generated sound (provided that is known from the start).

---

<div class="post-metadata">

**Author:** ![Paul\_L](https://forum.audacityteam.org/letter_avatar_proxy/v4/letter/p/7c8e57/32.png) [@Paul\_L](https://forum.audacityteam.org/u/Paul_L)\
**Post date:** [April 25, 2013, 6:34pm UTC](https://forum.audacityteam.org/t/zero-crossing-detection/26237/23 "2013-04-25T18:34:11Z")

</div>

I see then, I can avoid snd-length in the special case that the sound of interest is s. I can write my functions to handle the general case but take advantage of that too.

---

<div class="post-metadata">

**Author:** ![Paul\_L](https://forum.audacityteam.org/letter_avatar_proxy/v4/letter/p/7c8e57/32.png) [@Paul\_L](https://forum.audacityteam.org/u/Paul_L)\
**Post date:** [April 25, 2013, 7:35pm UTC](https://forum.audacityteam.org/t/zero-crossing-detection/26237/24 "2013-04-25T19:35:41Z")

</div>

Are integrate and snd-inverse and sref-inverse not implemented in native C++ but in Lisp?

I thought this method would perform better than writing loops calling snd-fetch because the inner loops would not be in Lisp, which is the point of doing it that way. But I haven’t seen superior performance. Maybe there is needless inefficiency somewhere in my elaborations of it.

---

<div class="post-metadata">

**Author:** ![Robert\_J\_H](https://forum.audacityteam.org/letter_avatar_proxy/v4/letter/r/b38774/32.png) [@Robert\_J\_H](https://forum.audacityteam.org/u/Robert_J_H)\
**Post date:** [April 25, 2013, 8:53pm UTC](https://forum.audacityteam.org/t/zero-crossing-detection/26237/25 "2013-04-25T20:53:23Z")

</div>

Those are all C++ implementations (sometimes translated automatically from an \*.al file)

```plaintext
(print (type-of (symbol-function 'snd-integrate)))

```

Almost all functions with ‘snd-’ in front are of that Kind.  
The high Level functions add in General multi-channel abilities and global behaviour (Timing, warp, loudness, sustain, Stretch and transpose).  
The Problem lies in the automatical Translation, which is certainly not optimised (and the Memory/Sound Management in General).

---

<div class="post-metadata">

**Author:** ![Paul\_L](https://forum.audacityteam.org/letter_avatar_proxy/v4/letter/p/7c8e57/32.png) [@Paul\_L](https://forum.audacityteam.org/u/Paul_L)\
**Post date:** [April 25, 2013, 10:34pm UTC](https://forum.audacityteam.org/t/zero-crossing-detection/26237/26 "2013-04-25T22:34:25Z")

</div>

Oh, heck. This tells me trigger and integrate are closures and not subrs. My attemps to improve on the time of SilenceMarker are getting nowhere. It seems I really can’t do better than repeated snd-fetch. I thought integrate and trigger would be magic. Did I waste a lot of time for nothing?

---

<div class="post-metadata">

**Author:** ![Robert\_J\_H](https://forum.audacityteam.org/letter_avatar_proxy/v4/letter/r/b38774/32.png) [@Robert\_J\_H](https://forum.audacityteam.org/u/Robert_J_H)\
**Post date:** [April 25, 2013, 10:42pm UTC](https://forum.audacityteam.org/t/zero-crossing-detection/26237/27 "2013-04-25T22:42:13Z")

</div>

Don’t worry, there exist low-level variants of them.  
There’s no Looping in xlisp code in this functions anyway (only the adaptions I mentioned before).  
You can view the source code for a high-Level function by typing:

```plaintext
(grindef 'yin)

```

The low-level function is hidden within this code. If a bad Argument error is returned, you’ve reached the lowest Level.

[Previous page](https://forum.audacityteam.org/t/zero-crossing-detection/26237.md?page=1)
