# How to Delete unnecessary parts from a sample? (in SP, no external software)

**URL:** <https://in-thread.sonic-pi.net/t/how-to-delete-unnecessary-parts-from-a-sample-in-sp-no-external-software/4968>\
**Category:** Support, Help & Resources\
**Created:** [January 12, 2021, 7:22am UTC](https://in-thread.sonic-pi.net/t/how-to-delete-unnecessary-parts-from-a-sample-in-sp-no-external-software/4968 "2021-01-12T07:22:05Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chip\_luxury\_E.W.A](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/chip_luxury_e.w.a/32/1756_2.png) [@Chip\_luxury\_E.W.A](https://in-thread.sonic-pi.net/u/Chip_luxury_E.W.A)\
**Post date:** [January 12, 2021, 7:22am UTC](https://in-thread.sonic-pi.net/t/how-to-delete-unnecessary-parts-from-a-sample-in-sp-no-external-software/4968/1 "2021-01-12T07:22:05Z")

</div>

HELLO ALL,  
is there any way to delate unnecessary parts of a sample?  
lets say I’m sampled 4 second at 96khz, there is a 1 second of silence in the beginning of the recording and 1 second in the end until I pressed stop-recording and i want to load from 96001 sample to 288k sample (96\*3) in a new variable or sample,  
like in the akai mpc where the first edit is to delete unwanted parts of the sample.  
THANKS  
edit: for a fast workflow I’m asking about doing this inside sonic-pi on the flow of the code.

---

<div class="post-metadata">

**Author:** ![ethancrawford](https://avatars.discourse-cdn.com/v4/letter/e/a88e4f/32.png) [@ethancrawford](https://in-thread.sonic-pi.net/u/ethancrawford)\
**Post date:** [January 12, 2021, 7:35am UTC](https://in-thread.sonic-pi.net/t/how-to-delete-unnecessary-parts-from-a-sample-in-sp-no-external-software/4968/2 "2021-01-12T07:35:13Z")

</div>

Are you talking about using external software to alter (or produce a new sample from) the file in question?  
If so, Audacity is a useful open source audio editing tool that I’m sure many folks here on the forum are quite happy with for this sort of thing.

> **[Home](https://www.audacityteam.org/)**
>
> Welcome to Audacity
> 
> 
> Audacity® is free, open source, cross-platform audio software for multi-track recording and editing.
> 
> Audacity is available for Windows®, Mac®, GNU/Linux® and other operating systems. Check our feature list, Wiki and...

(There are no doubt many alternatives as well 🙂)

---

<div class="post-metadata">

**Author:** ![Chip\_luxury\_E.W.A](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/chip_luxury_e.w.a/32/1756_2.png) [@Chip\_luxury\_E.W.A](https://in-thread.sonic-pi.net/u/Chip_luxury_E.W.A)\
**Post date:** [January 12, 2021, 7:39am UTC](https://in-thread.sonic-pi.net/t/how-to-delete-unnecessary-parts-from-a-sample-in-sp-no-external-software/4968/3 "2021-01-12T07:39:06Z")

</div>

Thanks but no,  
I’m familiar with Audacity but I’m asking about sonic pi capabilities to edit samples with out the need of external software, for a fast workflow…  
(I will edit the title)

---

<div class="post-metadata">

**Author:** ![ethancrawford](https://avatars.discourse-cdn.com/v4/letter/e/a88e4f/32.png) [@ethancrawford](https://in-thread.sonic-pi.net/u/ethancrawford)\
**Post date:** [January 12, 2021, 7:46am UTC](https://in-thread.sonic-pi.net/t/how-to-delete-unnecessary-parts-from-a-sample-in-sp-no-external-software/4968/4 "2021-01-12T07:46:45Z")

</div>

In that case, the documentation for `sample` shows that you can play sections of samples by using the `start:` and `finish:` opts, but they work on a scale of 0 - 1 as a proportion of the sample length, not in units of audio samples. You could use this to calculate the precise audio samples to play. (Or, if you are determined to produce a new sample not containing the silence, wrap the calculated sample region in a `:record` fx to produce a new sample directly in Sonic Pi).

---

<div class="post-metadata">

**Author:** ![Chip\_luxury\_E.W.A](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/chip_luxury_e.w.a/32/1756_2.png) [@Chip\_luxury\_E.W.A](https://in-thread.sonic-pi.net/u/Chip_luxury_E.W.A)\
**Post date:** [January 12, 2021, 7:55am UTC](https://in-thread.sonic-pi.net/t/how-to-delete-unnecessary-parts-from-a-sample-in-sp-no-external-software/4968/5 "2021-01-12T07:55:04Z")

</div>

I use the start: and finish: but with num\_slices: it slice with the part I don’t want…  
I’ll try this :record THANKS!

---

<div class="post-metadata">

**Author:** ![ethancrawford](https://avatars.discourse-cdn.com/v4/letter/e/a88e4f/32.png) [@ethancrawford](https://in-thread.sonic-pi.net/u/ethancrawford)\
**Post date:** [January 12, 2021, 7:56am UTC](https://in-thread.sonic-pi.net/t/how-to-delete-unnecessary-parts-from-a-sample-in-sp-no-external-software/4968/6 "2021-01-12T07:56:47Z")

</div>

Sure. A code example of your current attempt (and then an explanation of what you are wanting it to do, if that would help to make it any clearer than what you wrote in your first post) would be helpful for a bit more context 🙂

---

<div class="post-metadata">

**Author:** ![ethancrawford](https://avatars.discourse-cdn.com/v4/letter/e/a88e4f/32.png) [@ethancrawford](https://in-thread.sonic-pi.net/u/ethancrawford)\
**Post date:** [January 12, 2021, 8:04am UTC](https://in-thread.sonic-pi.net/t/how-to-delete-unnecessary-parts-from-a-sample-in-sp-no-external-software/4968/7 "2021-01-12T08:04:21Z")

</div>

I think however, that _possibly_, your issue could be related to the following comment in the `sample` documentation for the `slice:` opt:

> If start: or finish: opts are used in addition to slice: then they will work within the slice rather than the whole sample.

(Unless you are not specifically using the `slice:` opt)

---

<div class="post-metadata">

**Author:** ![nlb](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/nlb/32/997_2.png) [@nlb](https://in-thread.sonic-pi.net/u/nlb)\
**Post date:** [January 12, 2021, 10:00am UTC](https://in-thread.sonic-pi.net/t/how-to-delete-unnecessary-parts-from-a-sample-in-sp-no-external-software/4968/8 "2021-01-12T10:00:26Z")

</div>

Hi,

> **[Sonic Pi - sample slicing — The MagPi magazine](https://magpi.raspberrypi.org/articles/sonic-pi-sample-slicing)**
>
> In his latest musical coding piece, Sonic Pi creator Sam Aaron shows us how to slice and dice audio samples

and

the full article written by Sam himself

> **[The MagPi magazine](https://magpi.raspberrypi.org/issues/45/pdf/download)**
>
> The official Raspberry Pi magazine

page 54

---

<div class="post-metadata">

**Author:** ![Wayne](https://avatars.discourse-cdn.com/v4/letter/w/0ea827/32.png) [@Wayne](https://in-thread.sonic-pi.net/u/Wayne)\
**Post date:** [January 14, 2021, 11:20am UTC](https://in-thread.sonic-pi.net/t/how-to-delete-unnecessary-parts-from-a-sample-in-sp-no-external-software/4968/9 "2021-01-14T11:20:01Z")

</div>

There is also the sample `onset` parameter, which may be good enough for your needs. [Can someone explain "Onset" - #2 by mrbombmusic](https://in-thread.sonic-pi.net/t/can-someone-explain-onset/1533/2)

---

<div class="post-metadata">

**Author:** ![binarysweets](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/binarysweets/32/2683_2.png) [@binarysweets](https://in-thread.sonic-pi.net/u/binarysweets)\
**Post date:** [January 14, 2021, 2:45pm UTC](https://in-thread.sonic-pi.net/t/how-to-delete-unnecessary-parts-from-a-sample-in-sp-no-external-software/4968/10 "2021-01-14T14:45:06Z")

</div>

Hi, this is the best I could come up with  
[Edit, removed duplicate ticks!]

```ruby
use_bpm 160
live_loop :test do ; tick
  s = :loop_amen
  s_length = 1.753
  s_start = 0.435 # 0
  s_end = 1.3 # 1.753
  starts = (line s_start, s_end, steps: 16, inclusive: true)
  finishes = (line starts[1], starts[15], steps: 15, inclusive: true)
  
  sample s,
    start: (starts.take(15)[look]/s_length),
    finish: (finishes[look]/s_length),
    amp: 4,
    beat_stretch: 4
  
  sleep 0.25
end
```
