0

I'm trying to integrate SoundTouch (https://www.surina.net/soundtouch/) as a shared library into a cross-platform Qt app. The version in the Ubuntu repos seems to provide a C++ interface like this:

this->soundTouchHandle = new SoundTouch();
this->soundTouchHandle->setSampleRate(44100);
this->soundTouchHandle->setChannels(2);

this->soundTouchHandle->setSetting(SETTING_USE_AA_FILTER, 1);
this->soundTouchHandle->setPitch(this->pitchScalingFactor);

But it seems like the normal way to use it on Windows is through the SoundTouchDLL C wrapper (which provides the __cdecl exports):

this->soundTouchHandle = soundtouch_createInstance();
soundtouch_setSampleRate(this->soundTouchHandle, 44100);
soundtouch_setChannels(this->soundTouchHandle, 2);

soundtouch_setSetting(this->soundTouchHandle, SETTING_USE_AA_FILTER, 1);
soundtouch_setPitch(this->soundTouchHandle, this->pitchScalingFactor);

If I understand correctly, Linux doesn't need the __cdecl annotations, the C-based SoundTouchDLL interface is specifically for windows. SoundTouchDLL.h clearly contains windows-specific code (e.g. #include <windows.h>). On the other hand, the core C++ SoundTouch library doesn't include annotations for exporting any symbols with __cdecl, so it can't be used as a shared library (DLL) on Windows, the C interface is required.

Have I understood this correctly? Is it really normal to use the C API for SoundTouch on Windows, but use the C++ API on Linux? Is there any way to use the same API on both platforms (preferably without having to modify SoundTouch)?

Nick W.
  • 1,050
  • 2
  • 9
  • 21
  • Have you tried calling the C API functions on Linux? – Ben Voigt Jan 19 '17 at 22:33
  • Yes, in a manner of speaking. If you include the SoundTouchDLL.h file with the C interface on Linux, you get `expected constructor, destructor, or type conversion before '(' token` on every line that uses `extern "C" __declspec(dllimport)`. – Nick W. Jan 19 '17 at 22:43
  • I guess I could create my own linux-specific C wrapper file, but that's exactly the sort of thing I'm trying to avoid. – Nick W. Jan 19 '17 at 22:44
  • I can get it to compile on Linux if I add a few `#ifdef`s to remove platform-specific annotations like `__cdecl`. I'll wait in hope for better answers (surely I'm not the only one with this problem??). For now I'm going to fork it on GitHub and update the C interface. I'll post a link back here with my changes. – Nick W. Jan 19 '17 at 22:52
  • After about a day of effort, I managed to iron out a version of the C API that works on both Windows (MSVC) and Linux (GCC). https://github.com/unyieldinggrace/SoundTouch – Nick W. Jan 20 '17 at 13:52

0 Answers0