π π A Python library for audio.
C audioaudio-processingaudio-productionaudio-researchaudio-unitaugmentationjucemachine-learningpybind11pythonvst3vst3-host
Attempt to appease MSVC.
Peter Sobot4c6d786e8071
diff --git a/pedalboard/plugins/MP3Compressor.h b/pedalboard/plugins/MP3Compressor.hindex 82a469c..98008b3 100644--- a/pedalboard/plugins/MP3Compressor.h+++ b/pedalboard/plugins/MP3Compressor.h@@ -16,7 +16,11 @@*/#include "../Plugin.h"++extern "C" {#include <lame.h>+}+namespace Pedalboard {@@ -71,14 +75,6 @@ private:hip_t hip;};-void lame_throw_error_handler(const char *format, va_list ap) {- int errorLength = 512;- char errorBuffer[errorLength + 1];- snprintf(errorBuffer, errorLength, format, ap);- throw std::runtime_error("MP3 encoder threw an error: " +- std::string(errorBuffer));-}-class MP3Compressor : public Plugin {public:virtual ~MP3Compressor(){};@@ -102,8 +98,6 @@ public:if (!encoder || specChanged) {reset();- lame_set_errorf(encoder.getContext(), lame_throw_error_handler);-if (lame_set_in_samplerate(encoder.getContext(), spec.sampleRate) != 0) {throw std::runtime_error("MP3 encoder failed to set input sample rate.");@@ -300,4 +294,4 @@ inline void init_mp3_compressor(py::module &m) {&MP3Compressor::setVBRQuality);}-}; // namespace Pedalboard+}; // namespace Pedalboard\ No newline at end of filediff --git a/setup.py b/setup.pyindex 66c1312..0882380 100644--- a/setup.py+++ b/setup.py@@ -26,7 +26,7 @@ from distutils.unixccompiler import UnixCCompilerDEBUG = bool(int(os.environ.get('DEBUG', 0)))# C or C++ flags:-ALL_COMPILER_FLAGS = [+BASE_CPP_FLAGS = ['-Wall',]ALL_INCLUDES = []@@ -89,8 +89,13 @@ ALL_CPPFLAGS.extend(ALL_SOURCE_PATHS += list(Path("vendors/rubberband/single").glob("*.cpp"))# LAME/mpglib:-# (man, this code is portable)-ALL_CFLAGS.extend(["-includevendors/lame_config.h", "-DHAVE_MPGLIB"])+LAME_FLAGS = ["-DHAVE_MPGLIB"]+LAME_CONFIG_FILE = str(Path("vendors/lame_config.h").resolve())+if platform.system() == "Windows":+ LAME_FLAGS.append(f"/FI{LAME_CONFIG_FILE}")+else:+ LAME_FLAGS.append(f"-include{LAME_CONFIG_FILE}")+ALL_CFLAGS.extend(LAME_FLAGS)ALL_SOURCE_PATHS += list(Path("vendors/lame/libmp3lame").glob("*.c"))ALL_SOURCE_PATHS += list(Path("vendors/lame/mpglib").glob("*.c"))ALL_INCLUDES += [@@ -217,8 +222,10 @@ else:def patch_compile(original_compile):+ """+ On GCC/Clang, we want to pass different arguments when compiling C files vs C++ files.+ """def new_compile(obj, src, ext, cc_args, extra_postargs, *args, **kwargs):- print(f"\n\nIn new_compile with obj={obj}, src={src}, ext={ext}, cc_args={cc_args}, extra_postargs={extra_postargs}")_cc_args = cc_argsif ext in ('.cpp', '.cxx', '.cc', '.mm'):@@ -243,11 +250,18 @@ class BuildC_CxxExtensions(build_ext):build_ext.build_extensions(self, *args, **kwargs)+if platform.system() == "Windows":+ # The MSVCCompiler extension doesn't support per-file command line arguments,+ # so let's merge all of the flags into one list here.+ BASE_CPP_FLAGS.extend(ALL_CPPFLAGS)+ BASE_CPP_FLAGS.extend(ALL_CFLAGS)++pedalboard_cpp = Pybind11Extension('pedalboard_native',sources=ALL_RESOLVED_SOURCE_PATHS,include_dirs=ALL_INCLUDES,- extra_compile_args=ALL_COMPILER_FLAGS,+ extra_compile_args=BASE_CPP_FLAGS,extra_link_args=ALL_LINK_ARGS,libraries=ALL_LIBRARIES,language="c++",diff --git a/vendors/lame_config.h b/vendors/lame_config.hindex c7259d5..4ad6cd1 100644--- a/vendors/lame_config.h+++ b/vendors/lame_config.h@@ -1,3 +1,4 @@+#ifndef __cplusplus#include <stdlib.h>#ifndef CONFIGMS_H_INCLUDED@@ -55,20 +56,20 @@#define HAVE_MEMCPY#if defined(_MSC_VER) || defined(__BORLANDC__)-#pragma warning( disable : 4305 )- typedef __int8 int8_t;- typedef __int16 int16_t;- typedef __int32 int32_t;- typedef __int64 int64_t;-- typedef unsigned __int8 uint8_t;- typedef unsigned __int16 uint16_t;- typedef unsigned __int32 uint32_t;- typedef unsigned __int64 uint64_t;-- typedef float float32_t;- typedef double float64_t;-#elif defined (__GNUC__)+#pragma warning(disable : 4305)+typedef __int8 int8_t;+typedef __int16 int16_t;+typedef __int32 int32_t;+typedef __int64 int64_t;++typedef unsigned __int8 uint8_t;+typedef unsigned __int16 uint16_t;+typedef unsigned __int32 uint32_t;+typedef unsigned __int64 uint64_t;++typedef float float32_t;+typedef double float64_t;+#elif defined(__GNUC__)#define __int8_t_definedtypedef unsigned char uint8_t;@@ -82,41 +83,29 @@ typedef signed int int32_t;#endiftypedef long double ieee854_float80_t;-typedef double ieee754_float64_t;-typedef float ieee754_float32_t;+typedef double ieee754_float64_t;+typedef float ieee754_float32_t;#ifdef HAVE_MPGLIB-# define DECODE_ON_THE_FLY 1+#define DECODE_ON_THE_FLY 1#endif-#ifdef LAME_ACM-/* memory hacking for driver purposes */-#define calloc(x,y) acm_Calloc(x,y)-#define free(x) acm_Free(x)-#define malloc(x) acm_Malloc(x)--#include <stddef.h>-void *acm_Calloc( size_t num, size_t size );-void *acm_Malloc( size_t size );-void acm_Free( void * mem);-#endif /* LAME_ACM */-#define LAME_LIBRARY_BUILD-#ifdef HAVE_NASM- #if (defined(__ICL) && (__ICL >= 450))- #define HAVE_XMMINTRIN_H- #elif defined(_MSC_VER)- #include <malloc.h>- #ifdef _mm_malloc- #define HAVE_XMMINTRIN_H- #endif- #endif+#if (defined(__ICL) && (__ICL >= 450))+#define HAVE_XMMINTRIN_H+#elif defined(_MSC_VER)+#include <malloc.h>+#ifdef _mm_malloc+#define HAVE_XMMINTRIN_H+#endif+#endif#endif#if defined(_M_X64) && !defined(HAVE_XMMINTRIN_H)- #define HAVE_XMMINTRIN_H+#define HAVE_XMMINTRIN_H#endif#endif+#endif\ No newline at end of file