# Detect number of offsets in a sample

**URL:** <https://in-thread.sonic-pi.net/t/detect-number-of-offsets-in-a-sample/8970>\
**Category:** Support, Help & Resources\
**Created:** [June 21, 2024, 11:28am UTC](https://in-thread.sonic-pi.net/t/detect-number-of-offsets-in-a-sample/8970 "2024-06-21T11:28:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![brendanmac](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/brendanmac/32/2809_2.png) [@brendanmac](https://in-thread.sonic-pi.net/u/brendanmac)\
**Post date:** [June 21, 2024, 11:28am UTC](https://in-thread.sonic-pi.net/t/detect-number-of-offsets-in-a-sample/8970/1 "2024-06-21T11:28:08Z")

</div>

Hi  
I am aware that we can use num\_slices to dictate how many slices to chop a loop into, but is there a way to ask SPi “how many onsets in this sample”?

I suppose I could use Audacity or Ableton to tell me; hang on. . .

Anyway, this isn’t mission-critical, just messing with sample slicing today.

PD-Pi

---

<div class="post-metadata">

**Author:** ![brendanmac](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/brendanmac/32/2809_2.png) [@brendanmac](https://in-thread.sonic-pi.net/u/brendanmac)\
**Post date:** [June 21, 2024, 11:48am UTC](https://in-thread.sonic-pi.net/t/detect-number-of-offsets-in-a-sample/8970/2 "2024-06-21T11:48:54Z")

</div>

A.12 Sample Slicing is another option 😉

As is

> [@Playing with Sample onset values UPDATED](https://in-thread.sonic-pi.net/t/playing-with-sample-onset-values-updated/1090):
>
> I have deleted the original content of this post, which had errors, and was inefficient. Instead, below is a function which enables you to extract data on all the onsets of a given sample. It is based on the last example (35) on the sample command in the lang section of the help file. l = lambda {|c| puts c ; c[0]} sample :loop\_tabla, onset: l This uses a lambda function to print maps of all the onsets detected for a sample as it plays the first onset (number 0) The…
