Re-sorting the samples of an audio file?

Did anyone see an Audacity plugin or feature that can take an audio file of e.g. 48000 samples long, and re-sort its samples by picking, e.g., every 52800th sample as it keeps cycling through it?

If the picking number (the 52800 in the above illustration) is related to the source’s BPM x sampling frequency, the result might be musical.

Does that make sense? How do you pick the 52800th sample if there are only 48000 samples?

You keep cycling (looping) through the file, counting 48001 at the next loop start.

It could be visualized as if the file looped endlessly for days and you extracted a single sample at repeating time intervals. Which might be larger than a single loop’s length.

So essentially you are picking the 4800th sample? (48000 + 4800 = 52800)
That will give you sample numbers:
4800
9600
14400
19200
24000
28800
33600
38400
43200
48000
52800
then back to 4800…

Assuming that your sample rate is 48000 Hz, all that will give you is a high pitched tone comprising of frequencies 4800 Hz, 9600 Hz, 14400 Hz, 19200 Hz and 24000 Hz.
If your sample rate is not 48000 Hz, you will get the same harmonic pitches based on a fundamental 1/10th of the sample rate.

This Nyquist code will give you one complete cycle (10 samples when selecting every 52800th sample from 48000 samples).
You can use the “Repeat” effect (Audacity Manual) to make the result long enough to play.
The code can be run in the Nyquist Prompt effect (Audacity Manual) on a mono track.

(setq ln 48000) ;number of samples to work with
(setq count 52800)  ;the nth sample

(if (< len ln)
    "Error.nSelection too short."
    (progn
      (setq n (rem count ln))
      (let* ((samples (snd-samples s ln))
             (samplelist (list (aref samples 0))))
        (do ((i n (rem (+ i count) ln)))
            ((= i 0))
          (push (aref samples (1- i)) samplelist))
        (setf out (make-array (length samplelist)))
        (dotimes (i (length samplelist))
          (setf (aref out i)(nth i samplelist)))
        (snd-from-array 0 *sound-srate* out))))

You can find more information about writing Nyquist scripts here: Missing features - Audacity Support