Start with random track

Hello dear community,

I am new to this forum, so I hope it is the right topic I am posting my question in.
I am using audacity in Windows 10, and wanted to know if it’s possible to script
that when I am opening a wav file which contains multiple tracks, the first track that plays alters randomly.

Here I posted a screenshot of my audacity panel:
http://prnt.sc/1zsikbu


I have 3 tracks, named 0,1 and 2.

I would like to script, that it either starts with track 0, 1 or 2.
Also it would be desirable, if the tracks following after the first one are also chosen randomly.



Thank you in advance


Kind regards
AlphaOne

Why not just set your player to “shuffle” / “random play”?

Hi steve,

thank you for your quick answer.

My wav file is used by a programm and I need this function to be integrated in the wav.

I unfortunately can’t change / script the programm.


Kind regards
AlphaOne

Perhaps you could say more about why you need to script this and how you intend to use it.

The obvious answer is to manually import the tracks one at a time in “random” order (or any order that you want them).

Hi steve,

I need it for a slot game I am programming.
Everytime you spin the reels there is a background sound
but it shouldn’t be always the same.
The background sound is programmed to be feeded from a single *.wav file.

The first time you click spin it should randomly decide which track the wav file is
playing.

So to say, everytime you access the file it chooses one of the 3 tracks randomly.

So do you want six versions of the WAV file, one with the sounds in the orders “1, 2, 3”, “2, 1, 3”, “2, 3, 1”, “3, 1, 2”, “3, 2 1”, and finally “1, 3, 2”?

Yes, kinda

but it all has to be in a single *.wav file
since I can’t access the “code” of the programm only the resource files

I’m still trying to understand…

Do you want one big WAV file with the same three clips many times over in pseudo-random order:
1, 3, 1, 2, 3, 2, 2, 3, 1, 2, 1, 3, 3, 3, 1, 2, …

exactly, that’s what I want.

So, also when open the .wav file in the windows player,
each time it starts off with a different sound (track) so to say

actually,

it doesn’t matter with what track it starts off,
it should just be random everytime (like you posted above)

Do you know the exact length of the three sounds (“exact”)?
Are they all the exact same length?

yes sure,

Sound 1 has: 02,897s
Sound 2 has: 00,280s
Sound 3 has: 01,087s

Ok, it’s a bit trickier because they are different lengths.

How does your app know how long, and from what start point to play the sound?
For example, if the “random” order is “3, 2, 2, 3” then to play the 4th sound (sound 3), it must start at 1.087 + 0.280 + 0.280 = 1.647 seconds, and play for 1.087 seconds.

The programm knows that it should play the sound as long as the reels spin.
Now, the single sounds are shorter than the reel spin time, but audacity merges the tracks.

Unfortunately, I can’t tell the programm to start off from second e.g. 2 in the wav file,
so I thought everytime it is played, a different track would play.

If the length difference poses a problem, I can try to make them all the same length

If all the sounds are the same length, then you can randomise them like this:

Here I have three sounds, each is 2.0 seconds duration:

Tracks001.png
Put them all into one track like this:

First Track001.png
Select the entire track (all three clips), and apply this code with the Nyquist Prompt effect (See: https://manual.audacityteam.org/man/nyquist_prompt.html)

(setf repeats 20) ;number of sounds
(setf dur 2.0)    ; length of each sound in seconds

(let ((a (extract-abs 0 dur *track*))
      (b (extract-abs dur (* 2 dur) *track*))
      (c (extract-abs (* 2 dur) (* 3 dur) *track*)))
  (setf sounds (list a b c))
  (extract-abs
    0 (* repeats dur)
    (seqrep (i repeats) (cue (nth (random 3) sounds)))))

Note that the first line sets the total number of sounds in the final track (in this case, 20, but adjust as necessary).

The second line sets the length of each sound, which in my case is exactly 2.0 seconds.

The result is a single track with the sounds randomised, for example as below, but because it is random it will be different each time.

First Track002.png

Ok thank you very much.

But, how do I put them together like this ?
Is cutting one track with ctrl + x and adding with ctr + v sufficient ?

Perhaps you could upload the WAV files in your reply - short WAV files can be attached directly to a forum post (see: https://forum.audacityteam.org/t/how-to-attach-files-to-forum-posts/24026/1)

Because when I do this, it says “Nyquist returned the value 0,267000” and nothing else happens…

Ok, now I ran it with the debug function and, in short, it returned: “error: In EXTRACT-ABS, 3rd argument (sound) must be a sound, got a 2-channel SOUND”

Ok, got it.
The tracks need to be mono.

Thank you very much for the answer, it works out but I actually need to run the nyquist command everytime
in Audacity.

Is there a possibility to “run this command”, everytime when I doubleclick the wav file ? (or the app does…)