SWIG-ruby problem with FMOD

Hello everybody,

I'm just trying to use SWIG to create some Ruby bindings for FMOD (http://www.fmod.org/)

Using the simplest example from the examples that ship with the FMOD mac api, where there is a main.c file that simply plays a sound file...

I tried the following:

swig -ruby main.i

where main.i contained:

/* main.i */
%module main
%{
/* Put header files here (optional) */

#include "fmod.h"

%}

extern int main();

Then, I did (because doing it the extconf.rb didn't work either, gave same error as below):

gcc -fno-common -g -O2 -pipe -fno-common -I/usr/local/lib/ruby/1.8/powerpc-darwin -c main.c main_wrap.c

and

cc -dynamic -bundle -undefined suppress -flat_namespace -L'/usr/lib' -o Main.bundle main_wrap.o -ldl -lobjc

That got me a Main.bundle...

After that, I loaded Ruby's interactive shell, irb and did:

irb(main):001:0> require 'main'
=> true
irb(main):002:0> Main.main()
(irb):2: [BUG] Bus Error
ruby 1.8.1 (2004-03-15) [powerpc-darwin]

Abort trap

I don't understand why it isn't play the soundfile...complete n00b alert here...any hints would be much appreciated!

Below, the main.c file for reference:

/

···

*===============================================================================================
  SIMPLEST
  Copyright (c), Firelight Technologies Pty, Ltd, 1999,2004.

  This is the simplest way to play a song through FMOD. It is basically Init, Load, Play!
===============================================================================================*/

#include <stdio.h>
#include <stdlib.h>

#include "../../api/inc/fmod.h"
#include "../../api/inc/fmod_errors.h" /* optional */
#include "../../api/inc/wincompat.h"

int main()
{
  FMUSIC_MODULE *mod = NULL;

  if (FSOUND_GetVersion() < FMOD_VERSION)
  {
    printf("Error : You are using the wrong DLL version! You should be using FMOD %.02f\n", FMOD_VERSION);
    exit(1);
  }

  /*
      INITIALIZE
  */
  if (!FSOUND_Init(44100, 64, FSOUND_INIT_GLOBALFOCUS))
  {
    printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));
    exit(1);
  }

  /*
      LOAD SONG
  */

#if defined(__MACH__) || defined(WIN32)
  mod = FMUSIC_LoadSong("../../media/invtro94.s3m");
#else
  mod = FMUSIC_LoadSong(":::media:invtro94.s3m");
#endif
  if (!mod)
  {
    printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));
    exit(1);
  }

  /*
      PLAY SONG
  */

  FMUSIC_PlaySong(mod);

  /*
      UPDATE INTERFACE
  */

  printf("Press any key to quit\n");
  printf("=========================================================================\n");
  printf("Playing %s...\n", FMUSIC_GetName(mod));
  do
  {
         printf("\rorder = %d/%d, row = %d/%d channels playing = %d cpu usage = %.02f%% ", FMUSIC_GetOrder(mod), FMUSIC_GetNumOrders(mod), FMUSIC_GetRow(mod), FMUSIC_GetPatternLength(mod, FMUSIC_GetOrder(mod)), FSOUND_GetChannelsPlaying(), FSOUND_GetCPUUsage());
         fflush(stdout);
         Sleep(100);
  } while (!kbhit());

  getch();

  printf("\n");

  /*
      FREE SONG AND SHUT DOWN
  */

  FMUSIC_FreeSong(mod);
  FSOUND_Close();

     return 0;
}

David Plans Casal wrote:

Hello everybody,

I'm just trying to use SWIG to create some Ruby bindings for FMOD (http://www.fmod.org/\)

Using the simplest example from the examples that ship with the FMOD mac api, where there is a main.c file that simply plays a sound file...

I tried the following:

swig -ruby main.i

SWIG doesn't know what to do with main(). It only wants to see the function prototypes in the library header files. You'll have to write your own main() equivalent in Ruby.

SWIG is cool, but it's not simple. If you're new to it, I'd suggest doing a couple of really simple examples first. Get a wrapper working for

-- begin sum.h
int sum(int a, int b);
-- end sum.h

-- begin sum.c
int sum(int a, int b)
{
     return a + b;
}
-- end sum.c

and you'll be on your way.

Steve