Building Rubberband 2.0.1 support on Windows is broken (+ fix)

I’m trying to enable Rubberband support, both in my own TE project, and also in the PitchAndTimeDemo, but I’m getting build errors on Windows. I’m using Rubberband 2.0.1.

I’ve tried both compiling directly from source within the project via TRACKTION_BUILD_RUBBERBAND as well as linking to a static library that I built from Rubberband source. In both cases I seem to get the same errors.

The files producing the errors are:

  • StretcherChannelData.cpp
  • StretcherImpl.cpp
  • StretcherProcess.cpp
  • tracktion_TimeStretch.cpp

And the errors include:

  • Error C2589 ‘(’: illegal token on right side of ‘::’ (compiling source file …\JuceLibraryCode\include_tracktion_engine_timestretch.cpp)
  • Error C3536 ‘numToDropThisTime’: cannot be used before it is initialized (compiling source file …\JuceLibraryCode\include_tracktion_engine_timestretch.cpp) PitchAndTimeDemo_App c:\dev\tracktion_engine\modules\tracktion_engine\timestretch\tracktion_timestretch.cpp 477
  • Error C2660 ‘RubberBand::RubberBandStretcher::Impl::ChannelData::setSizes’: function does not take 0 arguments (compiling source file …\JuceLibraryCode\include_tracktion_engine_timestretch.cpp) PitchAndTimeDemo_App c:\dev\cymaticsomatics\prismplayer\lib\rubberband\src\stretcherimpl.cpp 815
  • Error (active) E0040 expected an identifier PitchAndTimeDemo_App C:\Dev\tracktion_engine\modules\tracktion_engine\timestretch\tracktion_TimeStretch.cpp 438
  • Error C2059 syntax error: ‘)’ (compiling source file …\JuceLibraryCode\include_tracktion_engine_timestretch.cpp) PitchAndTimeDemo_App c:\dev\cymaticsomatics\prismplayer\lib\rubberband\src\stretcherchanneldata.cpp 123
  • Error C2144 syntax error: ‘unknown-type’ should be preceded by ‘)’ (compiling source file …\JuceLibraryCode\include_tracktion_engine_timestretch.cpp) PitchAndTimeDemo_App c:\dev\cymaticsomatics\prismplayer\lib\rubberband\src\stretcherimpl.cpp 815

There are actually 64 errors in total, so that is just a sampling. The weird thing is, they basically all seem to have to do with the use of std::min and std::max. References to std::min and std::max both resolve ok. I’m using Visual Studio 2019, but Platform Toolset v141 (2017, since the pip has a 2017 exporter by default).

Update: The use of std::min and std::max seem fine by itself, but somehow when referencing Rubberband classes and namespace there is some kind of issue with std::min and std::max. Is there a version of Rubberband known to work that perhaps I could try? Maybe some recent changes to Rubberband have created an issue? Building Rubberband 2.0.1 from source worked fine, it’s just the inclusion into TE project.

Found it! This stackoverflow post describes the issue.

So it turns out windows.h defines macros named min and max like so:

#define min(a,b)            (((a) < (b)) ? (a) : (b))
#define max(a,b)            (((a) > (b)) ? (a) : (b))

So in order to not have those macros get mangled with std::min and std::max you need to add #define NOMINMAX before other includes.

It could probably go elsewhere, but I put this at the top of trakction_TimeStretch.cpp and it compiled and worked without issue:

 #define NOMINMAX
1 Like

Thanks for the report.
This change should fix it? Rubber Band: Fixed an issue building rubberband from source · Tracktion/tracktion_engine@25fb32d · GitHub

Tested and verified working. Thanks!