0

I am trying to wrap the following function with SWIG so I can call it from Python. The signature is:

    int WebRtcVad_Process(VadInst* handle, int fs, const int16_t* audio_frame,
                  size_t frame_length);

I have the following SWIG file:

    %module webrtc_vad

    %{
    #define SWIG_FILE_WITH_INIT
    #include "webrtc/common_audio/vad/include/webrtc_vad.h"
    %}

    %{
      /* Include in the generated wrapper file */
      typedef unsigned int size_t;
    %}

    %include "stdint.i"
    %include "numpy.i"

    %init %{
      import_array();
    %}

    typedef unsigned int size_t;

    %apply (const int16_t* IN_ARRAY1, unsigned int DIM1) {(const int16_t* audio_frame, size_t frame_length)};
    %include "webrtc/common_audio/vad/include/webrtc_vad.h"

At the end of this, I get the following error: webrtc_vad.i:22: Warning 453: Can't apply (int16_t const *IN_ARRAY1,unsigned int DIM1). No typemaps are defined.

If I drop the unsigned bit in the signature, then it compiles fine but the function signature is carried as-is (i.e. the function expects an int pointer and all that business).

Does anyone have a solution? Thank you very much.

1 Answers1

0

I don't have a complete answer, but I've had a similar question and it might be of some help.

I don't know why swig does not recognize unsigned int as a size because according to the documentation "every int-like type" should work. Using int should be sort of fine though.

My problem was using <stdint.h> types for arrays (like your int16_t) and I've made it work by editing numpy.i:

See also the following: using stdint with swig and numpy

Community
  • 1
  • 1
jochen
  • 413
  • 2
  • 10