Nearest Neighbor Upsampling

The result is “brighter” sounding than other methods because of the distortion that it creates.

Anyway, I thought it was an interesting exercise, so I’ve written some code for you.

One thing that Nyquist cannot do is to change the track sample rate, so you will need to do that manually.
To change the track sample rate, use the track drop down menu. See here: Audacity Manual The Sample Rate settings are described at the bottom of the page.

So let’s say that you want to up-sample using the “nearest neighbour” method by a factor of 3:
If the track sample rate it, say, 8000 Hz, then you will need to change it to 3 x 8000 = 24000 Hz. (the track will now sound high pitched and speeded up).

Next we will do the resampling.
From the Effect menu, select the Nyquist Prompt effect.
Copy and paste this code into the Nyquist Prompt text box:

(setq multiplier 3) ; an integer


(defun bad-resample (sig num)
  (setq size 1000)
  (setf s-array (make-array (* num size)))
  (setf end-array
    (if (/= (rem (truncate len) size) 0)
      (make-array (* num (rem (truncate len) size)))
      nil))
  (setf output (s-rest 0))
  (dotimes (count (truncate (/ len size)))
    (fill-array s-array sig num)
    (setf output
      (sim
        output
        (at-abs (/ (* count num size) *sound-srate*)
          (cue (snd-from-array 0 *sound-srate* s-array))))))
  (if end-array
    (progn
      (fill-array end-array sig num)
      (sim
        output
        (at-abs (/ (* (truncate (/ len size)) (* num size)) *sound-srate*)
          (cue (snd-from-array 0 *sound-srate* end-array)))))
    output))

(defun fill-array (s-a sig times)
  (dotimes (count (/ (length s-a) times))
    (let ((next (snd-fetch sig)))
      (dotimes (i times)
        (setf (aref s-a (+ i (* count times))) next)))))

(multichan-expand #'bad-resample s (truncate multiplier))

Apply the effect.

Note that the first line sets the “upsampling” ratio. If you want to upsample 4 times, change:

(setq multiplier 3) ; an integer

to:

(setq multiplier 4) ; an integer