• Struggling hard

Hi everyone,
I'm trying to make a patch where I load a sound into an array, then, i read different moment of the sound in a random order (so i start at the sample X for an x sample duration) but i don't want the same moment to be read 2 times and i really don't see how could i do that !
Any suggestions ?
Thank you all

Toostupefiant

• Posts 12 | Views 2492
• @Toostupefiant Here are some solutions for random without repetition: https://forum.pdpatchrepo.info/topic/12621/stack-overflow-question/6

• @Toostupefiant There could be another way, but the easiest way to get a non-repeating [random] is to use [urn] from the cyclone library.
The problem with [random] is that you can stop a value from sequentially repeating....... but cannot (easily) stop a repeat later in the sequence.
no_repeat.pd
David.

• @whale-av Yes, urn has a different task from simply avoiding direct repetition.

Here is a vanilla urn: vurn.zip

• Hi,
I linked a quick view of a part of the patch. I think that Vurn would not work because it will not know which samples have been read (du to the duration of the playback (number on the left with "durée_de_lecture"). I don't knowif it's clearer.
I thought about maybe delete the samples from the array after they've been read but it seems like we can't, with a message, delete something in the array. Am i wrong or is there a way ?
Thank you for ur help still !

• @Toostupefiant So you want to partition the table into N segments (that don't overlap and cover the entire table) and then play back all the segments in some random order?

• @jameslo This would be the simplest way to do it. Divide the length of the array through the length of the samples, so you have the number of samples, urn or random over this number and multiply by the sample length again to find the starting point.

• @ingox Doesn't that assume all segments have the same length? It looks like @toostupefiant wants lengths to be randomized too.

(edit: looking more carefully at @toostupefiant's patch, I'm not sure where I got the impression that lengths had to be randomized, so I agree with @ingox, that would be the simplest)

• @jameslo said:

@Toostupefiant So you want to partition the table into N segments (that don't overlap and cover the entire table) and then play back all the segments in some random order?

That's exactly what I want to do, but i don't know how could i make none overlaping samples . But the sample have to be from various length and be randomized (like from one song the first length is gonna be 10 sec, i load a new song the first lenght is 3 sec)
Do you have any idea how could i do that, i think with array but i'm really not good with these.
(sorry btw for the very late answer I was struggling on another project haha)

• @jameslo If the samples are all added to the same array?
Total samples known.
Sum of all the non repeating random numbers can be known.
Divide the total samples by the "random sum"
Multiply each random number by the answer.
Random has to be zero to "n".
Not sure how you load all the samples end to end into the array though.
David.

• @Toostupefiant Definitely learn to use arrays, in particular, [tabwrite] and [tabread}. Make 2 arrays, one to save the segment start indexes and one to hold their lengths. Next, decide what the minimum and maximum length of each segment should be, in number of samples. With these numbers at hand, you can use [random] to generate a random segment length. When you load the sound file, save its length to use for comparison later.

Now, to construct a random partitioning of your sound file, start at start index 0 (i.e. the beginning of your sound file) and generate a random length. That defines your first segment, segment #0, but it also tells you what the next start index is, for segment #1. Save each start and length generated this way in your two arrays. Repeat until you've reached or gone past the end of the sound file. Keep track of the number of segments you generate because you'll need that for when you play them back at random. Pick a number less than or equal to the number of segments, look up its start in the start array and its length in the length array. Pass them to whatever you use for playback.

If you can manage that, then you'll probably want to protect against uselessly short last segments. That's a matter of looking at how much is left after each step of segment definition, and making some adjustment if it's less than your max + min segment length. I'm being vague about the adjustment because it just depends what compromise you want, e.g. you could just decide to ignore the last segment.

• Okay, thank you both for your kind explanation i'll try this week-end !

Posts 12 | Views 2492
Internal error.

Oops! Looks like something went wrong!