Convert 96khz interleaved mono audio to 48khz stereo with nyquist

Help for Audacity on Windows.
Forum rules
ImageThis forum is for Audacity on Windows.
Please state which version of Windows you are using,
and the exact three-section version number of Audacity from "Help menu > About Audacity".


Audacity 1.2.x and 1.3.x are obsolete and no longer supported. If you still have those versions, please upgrade at https://www.audacityteam.org/download/.
The old forums for those versions are now closed, but you can still read the archives of the 1.2.x and 1.3.x forums.
steve
Site Admin
Posts: 80679
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Convert 96khz interleaved mono audio to 48khz stereo with nyquist

Post by steve » Fri Aug 07, 2020 9:35 pm

As a proof of concept (this won't work with long tracks, but it works with the sample that you posted)

1. Import the track normally (it imports as mono, 96000 Hz)
2. Change the track sample rate to 48000 (from the track's drop-down menu https://manual.audacityteam.org/man/aud ... _menu.html)
3. Duplicate the track (Select the track, then "Ctrl + D")
4. Join the two tracks to create a stereo track (https://manual.audacityteam.org/man/spl ... racks.html)

The above steps need to be done manually, then we will use Nyquist to do the number crunching.

5. Apply this code to the track using the Nyquist Prompt (https://manual.audacityteam.org/man/nyquist_prompt.html)

Code: Select all

;version 4
(setf ln (truncate len))
(setf input (snd-fetch-array  (aref *track* 0) ln ln))
(setf ln  (/ ln 2))
(setf left (make-array ln))
(setf right (make-array ln))
(dotimes (i ln)
  (setf (aref left i) (aref input (* 2 i)))
  (setf (aref right i) (aref input (1+ (* 2 i)))))

(vector
  (snd-from-array 0 48000 left)
  (snd-from-array 0 48000 right))

Notice that the result is identical to Import RAW with a 44 sample offset.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

8bit_coder
Posts: 32
Joined: Sun Dec 03, 2017 4:31 am
Operating System: Windows 8 or 8.1

Re: Convert 96khz interleaved mono audio to 48khz stereo with nyquist

Post by 8bit_coder » Fri Aug 07, 2020 10:24 pm

Ah, I see why it can't be used for long tracks. It's using an array, and if we go by the 32bit length that an array can be, we get about 11 hours and 30 minutes that it can process before we run out of memory. I'm going to try and see if there's more elegant ways to do this(doing all the steps in one command) but it's going to be difficult since there's surprisingly little documentation and examples about doing this kind of stuff using nyquist(that are up to date anyways) that I could find by googling. But so far, the solution does seem to be working as intended. Even if 11 hours is the limit, I'm still fine with just trying to get the script to do the rest of the work. So far I've been able to find that force-srate can make nyquist use a different sample rate(albeit it doesn't correctly CHANGE the track's sampling rate) but it seems like step 3 and 4's taking a mono track and making it into stereo is a bit harder than it sounds since it seems like nyquist can't "create" or remove tracks, it can only modify existing ones. I tried making a macro to do those steps but I didn't see a command for "make stereo track" so I couldn't get much past that.

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

Re: Convert 96khz interleaved mono audio to 48khz stereo with nyquist

Post by steve » Sat Aug 08, 2020 9:46 am

8bit_coder wrote:
Fri Aug 07, 2020 10:24 pm
we get about 11 hours and 30 minutes that it can process before we run out of memory.
It'll be less than that because the sound array uses slightly over 18 bytes per sample.

The way that longer selections would be handled in Nyquist is to use a fixed array size, and make repeated calls to snd-fetch-array, which steps through the "sound" collecting consecutive samples. The output would still need to be assembled in RAM unless written directly to disk.

8bit_coder wrote:
Fri Aug 07, 2020 10:24 pm
I'm going to try and see if there's more elegant ways to do this
There is a fast and easy way to do this - use "Import RAW".

8bit_coder wrote:
Fri Aug 07, 2020 10:24 pm
it's going to be difficult since there's surprisingly little documentation
Nyquist documentation:
https://manual.audacityteam.org/man/nyquist.html
https://wiki.audacityteam.org/wiki/Nyqu ... _Reference
https://www.cs.cmu.edu/~rbd/doc/nyquist/
https://www.cs.cmu.edu/~rbd/doc/nyquist/indx.html
https://www.audacity-forum.de/download/ ... -index.htm
https://www.audacity-forum.de/download/ ... -index.htm
http://dept-info.labri.fr/~idurand/ense ... ation.html
https://wiki.audacityteam.org/wiki/Category:Nyquist
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Post Reply