Go Back   Cockos Incorporated Forums > REAPER Forums > ReaScript, JSFX, REAPER Plug-in Extensions, Developer Forum

Reply
 
Thread Tools Display Modes
Old 08-28-2014, 04:37 AM   #1
msmucr
Human being with feelings
 
Join Date: Jun 2009
Location: Praha, Czech republic
Posts: 595
Default Resample active takes of selected items using SoX - next thingie

Hi folks,
next thingie is here.

- output is always 24bit WAV rendered to active project directory
- resampled files are added as new takes to items
- headroom is introduced to avoid possible sample clipping at resampled output, level loss is compensated by increase of new take volume
- skips files, which are already at required rate, so if used for processing of all project items, only ones with different samplerate will be processed. Similarly if file is used several times at your project, it will be resampled only once.
- you can customize called command, file and take naming, default headroom on top of script

- requires working SoX installation
- requires latest beta of SWS extensions (due to Breeder's nice BR_SetTakeSourceFromFile)
- executable needs to be either in system path or you'll have to modify sox_path variable with full path to your SoX installation

remarks:
- tested with Python 2.7 on Win7, but theoretically it should work also on OS X with different Python versions (if not, let me know).
- it hangs UI of Reaper during longer processing. It could be possibly reworked for use of beyond. python package to avoid this, but it will complicate standard installation and setup
- processing can't be easily aborted once script is started, that is also why i did popup at start without straight conversion of selected items to project rate
- it can be possibly modified to threaded version with queues and parallel processing via SoX workers, but it is slightly related to previous point and looks like unnecessary fuss to me.. ;-)

I've done it mainly as helper for working with 48k projects for video, where are often placed tracks from music or FX libraries with CD rates. Another side effect is also consolidation linked material from elsewhere to project folder at common rate.

Maybe, you'll find it also useful.

Download link:
https://stash.reaper.fm/21644/resample_items_sox.py

and example:


UPDATE: Finally, i had chance to try it on OS X, there is need to call SoX executable within its shell when not using list of arguments. It works that way also on Windows, but it hides cmd.exe windows, where is progress of SoX processing. Forget to mention first and added special config variable "subprocess_shell" for it.


Michal

Last edited by msmucr; 08-28-2014 at 07:39 AM. Reason: MacOS X compatiblity, sox_path variable
msmucr is offline   Reply With Quote
Old 02-08-2015, 02:46 PM   #2
David Else
Human being with feelings
 
Join Date: Mar 2012
Posts: 610
Default

THANKS for this script, it is perfect for what i would like to do. I am a total novice at scripts.

Unfortunately I can't get it to work

I have installed the latest Sox, 4.77 reaper (portable) / 2.6.0 SWS Extension and 64 bit Python 3.4.2 using Windows 7 64 bit.

The script is running ok as it knows when the sample rate is the same and says so.

When I try to convert i get this error:

Processing 03-150207_1806.wav... Error during processing of C:\Temp\03-150207_1806.wav
sox -S --multi-threaded --buffer 32768 "C:\Temp\03-150207_1806.wav" -b 24 -r 44100 "C:\Users\David\Documents\REAPER Media\03-150207_1806 (44100).wav" gain -1.0 rate -v -s dither

and here is where it gets really weird! when i copy the error message out of the reaper error message window and into the command prompt it turns into this:

C:\Program Files (x86)\sox-14-4-1>sox batch-example.bat -S --multi-threaded --bu
ffer 32768 "C:\Temp\03-150207_1806.wav" -b 24 -r 44100 batch-example.bat "C:\Use
rs\David\Documents\REAPER Media\03-150207_1806 (44100).wav" gain -1.0 rate -v -s
dither

Where is the "batch-example.bat" coming from?! Could this be the error?

I don't know if Sox is even running. It seems if I edit out the extra spaces (after "sox \" and between "\ and \") in the following line it creates a valid sox command line (WITHOUT the invisible "batch-example.bat") in the reaper error message window, but it still won't run.

resampler_command = "sox \
-S --multi-threaded --buffer 32768 \"{infile}\" -b 24 -r {rate} \
\"{outfile}\" gain {gain} rate -v -s dither"
subprocess_shell = True


I have also tried changing the sox_path = "" to the correct install directory, no change. Really hope I can get this to work!
__________________
----------> Debian Linux Distribution = Computing Joy & Freedom <----------
David Else is offline   Reply With Quote
Old 02-10-2015, 04:20 PM   #3
David Else
Human being with feelings
 
Join Date: Mar 2012
Posts: 610
Default

OK... sorry to be impatient, but has ANYONE got this working with a newer Reaper version? If so I will keep trying... mega thanks!!!
__________________
----------> Debian Linux Distribution = Computing Joy & Freedom <----------
David Else is offline   Reply With Quote
Old 04-23-2017, 09:35 AM   #4
loji
Human being with feelings
 
Join Date: Jan 2010
Location: NYC
Posts: 30
Default Working in 5.40

I have this working in reaper 5.40
w/ SWS extension 2.8.8 on OSX 10.9.5


Python is already installed on OSX.
then Install Sox . use terminal to copy sox to /usr/bin (ReaScript errors when sox is in usr/local/bin/) .. you'll need to sudo

also copy the above python script into REAPER/Scripts (Option>Show Reaper resource path..)

and set up a custom action to call the resample script.

here's the arguments to change how Sox resamples : http://sox.sourceforge.net/Docs/FAQ

Thanks for building this front-end!


.... What I'd love some help with is adding some options to the .py to run different strings of Sox commands.

Like 3 or 4 buttons that ask : resampler process command 1,2,3,4 when it asks about rate and gain.

resampler_command = "sox \
-S --multi-threaded --buffer 32768 "{infile}" -b 24 -r {rate} "{outfile}" gain {gain} rate -v -s dither"
subprocess_shell = True

That way you can make one liner phase, one anti-alised, etc ... Does anyone know how to do this?

Last edited by loji; 04-23-2017 at 10:39 AM.
loji is offline   Reply With Quote
Old 04-23-2017, 04:51 PM   #5
junh1024
Human being with feelings
 
Join Date: Feb 2014
Posts: 240
Default

I have to question your motive as I don't think you fully understand what you're doing

-Reaper automatically resamples to your proj SR and you can force SR and choose SR quality by pressing alt-Enter. sinc16/64 should be fine for playback purposes. In fact, FL iirc uses 6 point hermite for playback.

-Sox SRC may have default settings (bandpass etc), that might be worse than sinc.

-Unless you're doing very silly things like resmapling 1khz to 384khz with LQ filters, you shouldn't hear much difference between any SRC

-MP3 is not 16bit. Nor is it 24. Its some kind of floating point, which can have peaks above 0dB (not uncommon) So by converting to fixed point 24bit, you're possibly clipping even before you do SRC. (c http://src.infinitewave.ca/faq.html "Are most SRCs really that bad?" )

If you want to fix all these problems and avoid a rabbit hole, it's just simply best & easiest to use reaper SRC options.

Last edited by junh1024; 04-23-2017 at 05:11 PM.
junh1024 is offline   Reply With Quote
Old 04-26-2017, 08:24 AM   #6
SaulT
Human being with feelings
 
Join Date: Oct 2013
Location: Seattle, WA
Posts: 876
Default

Would a take fx be applied before an SRC like this? Being able to apply an oversampled limiter before SRC would fix that potential concern. Seems like that should be easy to do, somehow.
SaulT is offline   Reply With Quote
Old 04-27-2017, 08:56 AM   #7
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,110
Default

Quote:
Originally Posted by David Else View Post
OK... sorry to be impatient, but has ANYONE got this working with a newer Reaper version? If so I will keep trying... mega thanks!!!
Works here on Win too with Reaper 5.40+ / Python 3.3.

One catch seems to be that it's problematic if the filepath to SoX contains whitespace(s).
What worked for me is either installing SoX in a path that doesn't contain whitespace or (in case of path contain whitespace) putting in "sox_path" in the script something like this
Code:
  
"\"[SoX install path]\""
(i.e. double quotes with escape sequence).

So in your case I think that should be:
Code:
sox_path = "\"C:\\Program Files (x86)\\sox-14-4-1\""

Last edited by nofish; 04-27-2017 at 09:05 AM.
nofish is offline   Reply With Quote
Old 05-03-2017, 12:09 PM   #8
Jonas Ekstrom
Human being with feelings
 
Jonas Ekstrom's Avatar
 
Join Date: Feb 2017
Location: Stockholm
Posts: 98
Default

This is cool!
Any chance to get this working with the final cd src?
__________________
Jonas Ekstrom
www.northmastering.com
Jonas Ekstrom is offline   Reply With Quote
Old 09-03-2021, 09:43 AM   #9
BartR
Human being with feelings
 
BartR's Avatar
 
Join Date: Oct 2014
Location: Belgium
Posts: 1,627
Default

Installed now.

I got this error: Script execution error

Traceback (most recent call last):
File "resample_items_sox.py", line 23, in <module>
from sws_python import *
ImportError: No module named sws_python

With the standard

then I decaled the C:\python27 (installed on Win10 via the store):

No Python dynamic library found for any compatible version, using custom path c:\Python27
Extension not supported: "py"

I tried also with the 3.9. Same result

Script execution error

Traceback (most recent call last):
File "resample_items_sox.py", line 23, in <module>
from sws_python import *
ModuleNotFoundError: No module named 'sws_python'
__________________
Reaper: always the most up-to-date.
O.S.: Windows 11 Pro
ReaPack (with bilingual Tutorials): https://bit.ly/ReaPack_Repository

Last edited by BartR; 09-03-2021 at 10:03 AM.
BartR is online now   Reply With Quote
Old 09-03-2021, 04:41 PM   #10
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,110
Default

^ First make sure that Reaper 'sees' Python correctly.
Here it looks like this:


Then when installing SWS make sure the 'Python ReaScript support' tickbox is ticked.
nofish is offline   Reply With Quote
Old 09-04-2021, 01:44 PM   #11
BartR
Human being with feelings
 
BartR's Avatar
 
Join Date: Oct 2014
Location: Belgium
Posts: 1,627
Default

Quote:
Originally Posted by nofish View Post
^ First make sure that Reaper 'sees' Python correctly.
Here it looks like this:


Then when installing SWS make sure the 'Python ReaScript support' tickbox is ticked.
Hi Nofish

yes Python is correctly seen by Reaperas you shown in your screenshot.
Min is in AppData\Local\Programs\Python\Python39 the rest is identical to your screenshot.
And SWS was installed with Python support.
After have rad you I've remade the installation to be sure.

But I only can confirm the issue I wrote. Id doesn't work.
And it's a pity because I find this really a great way
__________________
Reaper: always the most up-to-date.
O.S.: Windows 11 Pro
ReaPack (with bilingual Tutorials): https://bit.ly/ReaPack_Repository
BartR is online now   Reply With Quote
Old 09-04-2021, 02:10 PM   #12
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,110
Default

Do you see the files sws_python.py and sws_python64.py in your <Reaper resource path>/Scripts folder?
Because these are the files the resample_items_sox.py script doesn't seem to find, from the error message.
If you have these files, does the resample_items_sox.py script reside in the same folder?
If no, try copying the two sws_python.. files there.
nofish is offline   Reply With Quote
Old 09-04-2021, 02:38 PM   #13
BartR
Human being with feelings
 
BartR's Avatar
 
Join Date: Oct 2014
Location: Belgium
Posts: 1,627
Default

Quote:
Originally Posted by nofish View Post
Do you see the files sws_python.py and sws_python64.py in your <Reaper resource path>/Scripts folder?
Because these are the files the resample_items_sox.py script doesn't seem to find, from the error message.
If you have these files, does the resample_items_sox.py script reside in the same folder?
If no, try copying the two sws_python.. files there.
Thank you so much Nofish.
The Python script was in a different folder.
I did guess that it was an invariant because it can be given by default (some kind of $path variable)

Yes now it works and I'm very glad for this.

Again thank you :-)
__________________
Reaper: always the most up-to-date.
O.S.: Windows 11 Pro
ReaPack (with bilingual Tutorials): https://bit.ly/ReaPack_Repository
BartR is online now   Reply With Quote
Old 09-04-2021, 02:49 PM   #14
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,110
Default

Nice, you're welcome.
nofish is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 04:03 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.