Random tracks playing with random intervals

Hello again :slight_smile:

I am trying to play a list of audio snippets in random order alternated by silent gaps of random durations.
So, even after the setup running for long time it is not predictable which audio snippet is played and how long the silence lasts.

What is the best/simplest way to do that with Audacity?

If it cannot be done with Audacity, what other system/setup can I use?

Thank you as always! :slight_smile:

Any suggestion anybody? :slight_smile:

Thank you :slight_smile:

Well, the good news is it can be done in Audacity. The bad news is it is anything but simple. You will have to use either nyquist or python - most users find python easier. And no, you cannot currently do this with macros.

For tips on getting started, see: Scripting

Please note the requirements of this job are the exact opposite of a computer program. Make a carefully controlled music production with precise, pre-determined silences.

Random sound and silence collections would be a nightmare to program even with an advanced language.

There is a famous legacy problem of getting a computer to produce random anything.



Thank you kozikowski and jademan :slight_smile:

It looks like scripting is the best solution.

I agree.
(I would try with Python, but any full-featured scripting language should do).
One big advantage of using scripting is that you don’t need to use disk space for the silences - just tell the script to wait for a random length of time before playing the next audio file.

NB: a truly random selection could play the same snippet twice in a row …

Thank you @Steve and @Trebor,

yes truly random can play the same snippet twice in a row. I can avoid that with scripting which is also the reason I am thinking of using that.

I have seen that many plugins are developed in C/C++. I know them relatively well.
How easy and time-consuming is it to do as plugin instead?

Where can I find some examples of very simple plugins so I can see the minimal code structure/setup required?

And where can I find the full API for C/C++ interfacing?

Thank you

The Audacity plug-in API is designed for plug-ins that act on the current project, or part(s) of the current project. The number and length of the “snippets” that you want to randomise, and the total length of randomised clips + silences will determine whether or not it is practical to use Audacity for the task.

If they are fairly short snippets, and the total length of randomised snippets + silences is not too long, then it is likely to be possible to create a plug-in with Nyquist.
The “.ny” files here are all Nyquist plug-ins: https://github.com/audacity/audacity/tree/master/plug-ins
Links to Nyquist documentation: https://forum.audacityteam.org/t/manuals-and-reference-material/32817/1

Rick_123 wrote:

Where can I find some examples of very simple plugins so I can see the minimal code structure/setup required?
And where can I find the full API for C/C++ interfacing?

There are many types of plugins, namely VST, AU, LADSPA and LV2.
(There are other mad ones like AAX used by Pro-tools, but that is a whole other sad story).
All of the above are written in C/C++ and can be compiled for the following OS’es:

VST - Windows, Mac, Linux (Note that 32 and 64 bit VSTs exist).

VSTi - used for plugins that generate sound, for example software synths and drum machines.
Audacity does not support VSTi at all.

AU - Mac Only

LADSPA - Linux, Windows, Mac (Mostly used on Linux and easiest to learn and cross compile).
Note that LADSPA has been superseded by LV2, but is still very common.
As far as I know, Audacity ships with one or two LADSPA effects.
(Obviously compiled for the target OS).

LV2 - Only Linux as far as I know, could be wrong.

All of the above require quite a bit of DSP knowledge along with C/C++ experience.
Some like VST, also require a non open source SDK, in this case from Steinberg.
A compiler (and linker) are also required along with header files.

For Windows, Visual Studio is the “normal” IDE to use which includes a compiler.
For Mac, Xcode is the norm, probably uses a modified gcc or clang.
For Linux, you have loads of options and the compiler can be gcc or g++ for C and C++ respectively.

Another gotcha when compiling any of the above types, is selecting the correct CPU type.
By that, I don’t mean just “Intel” but type of CPU such as Core DUO, Celeron, i5, i7, etc
As some don’t have certain instruction sets/extensions that may be required to carry out the DSP code in the plug-in.

All in all, your best bet for now, try go with Nyquist (based on Xlisp).
It has many DSP primitives and functions built in, making your life much easier.
It’s also not a compiled plug-in, so it has other advantages.

One disadvantage, is the Xlisp syntax, loads of brackets, but once you get used to that, it’s pretty easy.

There is (old) free Windows standalone software which will chop up and shuffle a WAV
Stefan Bion’s EVP maker … https://youtu.be/3kCoIDdgovE?t=72
But it does not match your brief: the points at which the audio is chopped are random.

Thank you Trebor and Paul,

The audio snippets are a total of 30 to 50 between 2 and 10 seconds long each and are pre-recorded either as different MP3 files or all in single track spaced apart each starting at a fixed predefined timestamp of the track (if all in a single track the entire length would be maximum 10 minutes long at most). And the silences I was thinking of just implementing it programmatically.

Some questions:

  1. Which of the above two solutions (separate MP3 audio snippets or single long track with all audio snippets in the same track) is preferred?
  2. Which plugin would you suggest I’d use?
  3. Yes I was thinking of using Visual Studio. Why do I need DSP knowledge if all I need is to play random track?

Also, following your most recent two replies about the plugin, it might be easier/simpler/faster to learn Python?
If I will decide to learn Python instead of making a plugin, then the only other question is:
4) would it be better to have the snippets in separate files or all in a single one and pulling each one randomly form their fixed known position in the track?

Thank you again :slight_smile:

Do you have a list of start times? If so, how is that formatted?

Like a sound board with a random option, which exists …

“Can play a random sound from a list of sounds. Just select multiple files when adding a hotkey!”


Thank you Steve and Trebor,

@Steve, yes, I can make the start times whatever I like/need them to be. No restriction on that point. Why? Do you have some solution?

Thank you both :slight_smile:

I have a possible solution (using Nyquist to run macro commands), but I’m not going to have much time over the next few days due to work/life commitments. If you to take a look yourself, see here: https://manual.audacityteam.org/man/nyquist_macros.html

Thank you Steve!

Sorry it took so long to get back to you.

Here’s some Nyquist code that may be run in the Nyquist Prompt effect.
It assumes that we are starting with a mono track containing audio clips from 0 to 2.5 seconds, 2.5 to 5 seconds … 12 to 15 seconds.
Gaps between the clips will be a random value less than 5 seconds.

I tested this code in Audacity 3.0.2, but it should work in any recent version of Audacity. Adapt as necessary.

;; List of audio clips to randomise, formatted as list of
;; start times and end times.
(setf clips '((0 2.5) (2.5 5) (5 10) (10 12) (12 15)))

(setf max-gap 5.0)  ;maximum gap between clips

; Initialise an empty list
(setf randclips ())

;; Populate 'randclips' with randomised copy of 'clips'
;; This allows us to use each clip once, in a random order.
(dotimes (i (length clips))
  (setf clip (nth (random (length clips)) clips))
  (setf clips (delete clip clips :test 'equal))
  (push clip randclips))

;; test
;(print randclips)

;; Assuming mono sounds
(aud-do "NewMonoTrack:")
(setf paste-time 0) ;paste next clip at time position

(dotimes (i (length randclips) "")
  (setf clip (nth i randclips))
  (setf clipdur (- (second clip) (first clip)))
  (setf sildur (* max-gap (rrandom)))
  ;; Copy an audio clip from first track to 2nd track
  (aud-do "SelectTracks:Mode=Set Track=0 TrackCount=1")
  (aud-do-command "SelectTime:" :end (second clip) :start (first clip))
  (aud-do "Copy:")
  (aud-do "SelectTracks:Mode=Set Track=1 TrackCount=1")
  ;; test
  ;(print paste-time)
  (aud-do-command "SelectTime:" :end paste-time :start paste-time)
  (aud-do "Paste:")
  ; Update paste position for next clip
  (setf paste-time (+ paste-time sildur clipdur)))

Well, the good news is it can be done in Audacity. The bad news is it is anything but simple. You will have to use either nyquist or python - most users find python easier. And no, you cannot currently do this with macros****

Did you have something to contribute to this discussion sarang?