igorgad / dpm

30 stars 5 forks source link

TypeError: in method 'vstRender_renderAudio', argument 2 of type 'float *' #1

Closed drscotthawley closed 6 years ago

drscotthawley commented 6 years ago

Hi Igor! I was able to build vstRedner and run it. At the very end of train.py, when it calls to render the noise, I get an error.

The VST I used is just a free Linux VST called 'ButterComp' (http://www.airwindows.com/category/dynamics/)

$ python train.py 
/opt/anaconda/envs/py36/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
JUCE v5.2.0
Attempting to load VST: /home/shawley/vst-dpm/NewUpdates/LinuxVST/ButterComp.so
Creating VST instance: ButterComp
Initialising VST: ButterComp (1.0.0.0)
Attempting to load VST: /home/shawley/vst-dpm/NewUpdates/LinuxVST/ButterComp.so
Creating VST instance: ButterComp
Initialising VST: ButterComp (1.0.0.0)
Traceback (most recent call last):
  File "train.py", line 58, in <module>
    r = vst_render.renderAudio(noise)
  File "/home/shawley/vst-dpm/vstRender/vstRender.py", line 113, in renderAudio
    return _vstRender.vstRender_renderAudio(self, input)
TypeError: in method 'vstRender_renderAudio', argument 2 of type 'float *'

(That h5py warning comes from numpy as is ignorable.)

This must be the swig error you were talking about: https://stackoverflow.com/questions/32692575/how-to-convert-numpy-ndarray-to-c-float

I modified vstRender.i...

$ cat vstRender.i
%module vstRender

%{
    #define SWIG_FILE_WITH_INIT
    #include "vstRender.h"
%}

%include "numpy.i"
%init %{
import_array();
%}
%apply ( float* IN_ARRAY1 ) { (float* input ) };

%include "vstRender.h"

At first it couldn't find numpy.i, so I grabbed it...

$ cd vstRender/src
$ curl -LO https://github.com/numpy/numpy/blob/master/tools/swig/numpy.i

Tried making

$ cd ..
$ make
swig3.0 -c++ -python -outdir . -o ./src/vstRender_wrap.cpp ./src/vstRender.i
./src/numpy.i:7: Error: Syntax error in input(1).
Makefile:49: recipe for target 'swig' failed
make: *** [swig] Error 1

I ended up asking a StackExchange post about this. We'll see who writes back.

drscotthawley commented 6 years ago

Oh, duhh. When I downloaded numpy.i, I got all kinds of HTML tags. Should have used curl -LO https://raw.githubusercontent.com/numpy/numpy/master/tools/swig/numpy.i

With the proper numpy.i, the build error changes to...

$ make
swig3.0 -c++ -python -outdir . -o ./src/vstRender_wrap.cpp ./src/vstRender.i
mkdir -p build/intermediate/Debug
g++  -MMD -DLINUX=1 -DDEBUG=1 -D_DEBUG=1 -DJUCER_LINUX_MAKE_6D53C8B4=1 -DJUCE_APP_VERSION=1.0.0 -DJUCE_APP_VERSION_HEX=0x10000 -I/usr/include/alsa -I/usr/include/freetype2 -pthread -I/opt/anaconda/pkgs/python-3.6.0-0/include/python3.6m -I./VST3_SDK -I./JuceLibraryCode -I./JuceLibraryCode/modules -I/opt/anaconda3/include/python3.6m  -march=native -fPIC -g -ggdb -O0 -fPIC  -std=c++11  -DJucePlugin_Build_VST=0 -DJucePlugin_Build_VST3=0 -DJucePlugin_Build_AU=0 -DJucePlugin_Build_AUv3=0 -DJucePlugin_Build_RTAS=0 -DJucePlugin_Build_AAX=0 -DJucePlugin_Build_Standalone=0 -fPIC -fvisibility=hidden -o "build/intermediate/Debug/vstRender_wrap.o" -c "src/vstRender_wrap.cpp"
src/vstRender_wrap.cpp:3128:31: fatal error: numpy/arrayobject.h: No such file or directory
compilation terminated.
Makefile:61: recipe for target 'build/intermediate/Debug/vstRender_wrap.o' failed
make: *** [build/intermediate/Debug/vstRender_wrap.o] Error 1

So I added in to the Makefile a -I/opt/anaconda/pkgs/numpy-1.12.1-py36_0/lib/python3.6/site-packages/numpy/core/include so it could find arrayobject.h, rebuilt vstRender.so, re-ran train.py... and still got the same error from the start.

igorgad commented 6 years ago

Hi Scott,

thanks for your interest in this project. I just committed some updates to make renderAudio function work, it needs further testing though. Now I am trying to make setParams function to work properly.

On Sat, Apr 28, 2018 at 5:03 PM, Scott Hawley notifications@github.com wrote:

Oh, duhh. When I downloaded numpy.i, I got all kinds of HTML tags. Should have used curl -LO https://raw.githubusercontent.com/numpy/numpy/master/tools/ swig/numpy.i

With the proper numpy.i, the build error changes to...

$ make swig3.0 -c++ -python -outdir . -o ./src/vstRender_wrap.cpp ./src/vstRender.i mkdir -p build/intermediate/Debug g++ -MMD -DLINUX=1 -DDEBUG=1 -D_DEBUG=1 -DJUCER_LINUX_MAKE_6D53C8B4=1 -DJUCE_APP_VERSION=1.0.0 -DJUCE_APP_VERSION_HEX=0x10000 -I/usr/include/alsa -I/usr/include/freetype2 -pthread -I/opt/anaconda/pkgs/python-3.6.0-0/include/python3.6m -I./VST3_SDK -I./JuceLibraryCode -I./JuceLibraryCode/modules -I/opt/anaconda3/include/python3.6m -march=native -fPIC -g -ggdb -O0 -fPIC -std=c++11 -DJucePlugin_Build_VST=0 -DJucePlugin_Build_VST3=0 -DJucePlugin_Build_AU=0 -DJucePlugin_Build_AUv3=0 -DJucePlugin_Build_RTAS=0 -DJucePlugin_Build_AAX=0 -DJucePlugin_Build_Standalone=0 -fPIC -fvisibility=hidden -o "build/intermediate/Debug/vstRender_wrap.o" -c "src/vstRender_wrap.cpp" src/vstRender_wrap.cpp:3128:31: fatal error: numpy/arrayobject.h: No such file or directory compilation terminated. Makefile:61: recipe for target 'build/intermediate/Debug/vstRender_wrap.o' failed make: *** [build/intermediate/Debug/vstRender_wrap.o] Error 1

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/igorgad/dpm/issues/1#issuecomment-385202037, or mute the thread https://github.com/notifications/unsubscribe-auth/AFiAyDBjtHxlqD7nOMKkX7G7Dezy3xuFks5ttMr3gaJpZM4Tri51 .

drscotthawley commented 6 years ago

Ok, great! I was able to build and run, and at least now I get a segmentation fault! ;-) Could be the plugin I'm using...

python train.py 
/opt/anaconda/envs/py36/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
JUCE v5.2.0
Attempting to load VST: /home/shawley/vst-dpm/NewUpdates/LinuxVST/ButterComp.so
Creating VST instance: ButterComp
Initialising VST: ButterComp (1.0.0.0)
Attempting to load VST: /home/shawley/vst-dpm/NewUpdates/LinuxVST/ButterComp.so
Creating VST instance: ButterComp
Initialising VST: ButterComp (1.0.0.0)
Segmentation fault (core dumped)

Interesting that it creates the instance twice and initializes twice.

Anyway, since this particular issue is now solved, I'll close this.

igorgad commented 6 years ago

Yes, that's interesting, the same thing happens to me here, maybe a mono and stereo plugin version in the same shared object file?. Anyway, I just update the repo with setParams working.

In the current implementation, the renderAudio call updates the contents of the argument array in place, i.e. memory must be allocated in python in the form of a np.float32 1D array. This might cause some problems with multi-channel audio leading to segfault errors. However, for now, the idea is to use only mono plugins, need to check this latter.

regards, Igor.

On Sat, Apr 28, 2018 at 5:18 PM, Scott Hawley notifications@github.com wrote:

Closed #1 https://github.com/igorgad/dpm/issues/1.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/igorgad/dpm/issues/1#event-1600267290, or mute the thread https://github.com/notifications/unsubscribe-auth/AFiAyMMMw3HqjaT0g2erAN8U7vAQrw-lks5ttM6jgaJpZM4Tri51 .