Re-sorting the samples of an audio file?

Effects, Recipes, Interfacing with other software, etc.
Forum rules
If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like
Post Reply
mrdelurk
Posts: 4
Joined: Fri Jan 09, 2015 5:07 am
Operating System: Please select

Re-sorting the samples of an audio file?

Post by mrdelurk » Fri Jan 09, 2015 5:19 am

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.

steve
Site Admin
Posts: 80751
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Re-sorting the samples of an audio file?

Post by steve » Fri Jan 09, 2015 12:48 pm

mrdelurk wrote:e.g. 48000 samples long, and re-sort its samples by picking, e.g., every 52800th sample as it keeps cycling through it?
Does that make sense? How do you pick the 52800th sample if there are only 48000 samples?
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

mrdelurk
Posts: 4
Joined: Fri Jan 09, 2015 5:07 am
Operating System: Please select

Re: Re-sorting the samples of an audio file?

Post by mrdelurk » Sat Jan 10, 2015 2:11 am

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.

steve
Site Admin
Posts: 80751
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Re-sorting the samples of an audio file?

Post by steve » Sat Jan 10, 2015 2:08 pm

mrdelurk wrote:You keep cycling (looping) through the file, counting 48001 at the next loop start.
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 (http://manual.audacityteam.org/o/man/repeat.html) to make the result long enough to play.
The code can be run in the Nyquist Prompt effect (http://manual.audacityteam.org/o/man/ny ... rompt.html) on a mono track.

Code: Select all

(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: http://wiki.audacityteam.org/wiki/Nyqui ... _Reference
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Post Reply