0
0

Hi everyone,

It seems many of you have gotten your .NET wrapper to work (or importing the fmod DLL directly).

I’m working on my project and having difficulty. I saw something similar in another thread: basically I’m always getting an error 9 when playing the file (file not found). I’ve tried all kinds of combinations for the path, no luck.

I’m wondering if the string I’m passing in is not getting marshalled correctly; can someone post a sample of how you passed in a char * filename from .NET?

Thanks!
Brian

  • You must to post comments
0
0

I figured this out — thanks to some previous posts, it was simple, just adding a terminating character to the byte array.

-Brian

  • You must to post comments
0
0

It seems that many folks have written .NET / c# wrappers for the mobile device, but I simply have no idea where to start to compile my own as I am never written a wrapper class before. I have a project that desperately requires a C# wrapper, and was wondering if anyone could help me out with either pointers to get me started or provide me with a dll that they have written? It would save me from reinventing the wheel too 😉 I would give credit to them in my final project if they would be so kind!
Thanks!

  • You must to post comments
0
0

This should get you started:

using System.Runtime.InteropServices;

[DllImport(“fmodce.dll”) ]
public static extern bool FSOUND_Init(
int mixrate,
int maxsoftwarechannels,
uint flags);
[DllImport(“fmodce.dll”) ]
public static extern IntPtr FSOUND_Sample_Load(
int index,
byte[] name_or_data,
uint inputmode, int offset, int length);

Repeat for the other functions you are interested in. Once you have them linked like this, you can call them just like regular .net function.

  • You must to post comments
0
0

ok, I’ve started to write my wrapper in .NET, and have a few of the more important functions and Enums written. However, when I try to play a stream I get this error on my device:

A Native Exception Has Occurred.

ExcetionCode: 0x0000005
ExceptionAddress: 0x0175d9e0
Reading: 0x000004d8
OK to terminate
CANCEL to debug

Here’s my code in the application:
if (!AeFmodce.FSOUND_Init(44100, 32, 0)) {ApplicationEx.Exit(); }
IntPtr stream = new IntPtr();
stream = AeFmodce.FSOUND_Stream_Open(GlobalSettings.strAppDir + “\SF141598-01-01-01.mp3”,FSOUND.Enums.FSOUND_MODES.FSOUND_NORMAL,0,0);
int i = AeFmodce.FSOUND_Stream_Play(-1,stream);

And here’s the first couple of functions in my wrapper class:
public class AeFmodce
{
[DllImport (“fmodce.dll”)]
public static extern void FSOUND_Close();
[DllImport (“fmodce.dll”)]
public static extern IntPtr FSOUND_Stream_AddSyncPoint(ref IntPtr FSOUND_STREAM_stream,uint pcmoffset,string name);
[DllImport(“fmodce.dll”)]
internal static extern int _flushall();
[DllImport(“fmodce.dll”) ]
public static extern bool FSOUND_Init(int mixrate,int maxsoftwarechannels,FSOUND.Enums.FSOUND_INIT_FLAGS flags);
[DllImport(“fmodce.dll”) ]
public static extern IntPtr FSOUND_Sample_Load( int index, byte[] name_or_data, uint inputmode, int offset, int length);
[DllImport (“fmod.dll”)]
public static extern bool FSOUND_Stream_Close(IntPtr FSOUND_STREAM_stream);
[DllImport(“fmodce.dll”)]
public static extern string FSOUND_Stream_SetBufferSize(int ms);
[DllImport(“fmodce.dll”)]
public static extern IntPtr FSOUND_Stream_Open(string name_or_data,FSOUND.Enums.FSOUND_MODES mode,int offset,int length);
[DllImport(“fmodce.dll”)]
public static extern IntPtr FSOUND_Stream_Create(IntPtr FSOUND_STREAMCALLBACK_callback,int lenbytes,FSOUND.Enums.FSOUND_MODES mode,int samplerate,IntPtr userdata);
[DllImport (“fmodce.dll”)]
public static extern int FSOUND_Stream_Play(int channel,IntPtr FSOUND_STREAM_stream);
[DllImport (“fmodce.dll”)]
public static extern bool FSOUND_Stream_Stop(IntPtr FSOUND_STREAM_stream);

Any ideas what’s going on? ANY help would be much appreciated because I’m really stuck on this and losing hope that I will ever get it working.
Thanks!

  • You must to post comments
0
0

HI everyone,,

well, I am having the same problem. I am always getting error#9 (File No Found) although I am using an OpenFileDialog to get the full path. I also tried to input the path in different formats.

You mentioned something about adding a terminating character to the byte array. can you explain what do you mean by that? can you please write the code for adding this “terminating” character?

Thanks in advance

and goodluck

-Moayad

  • You must to post comments
0
0

I use it in my smartphone alarm projects.
(http://sourceforge.net/projects/spalarm)

The problem which casue “file not found” is that FMOD use ANSI encoding,
but .NET use Unicode encoding. so I use the following code to encode string.
It will cause problem if the filename is not the system defalut encoding text.

byte[] filenames = Encoding.Default.GetBytes(filename+’\0′);

using the source code, to play the mp3 file, for example:

FMOD fmod = new FMOD();
FSOUND_Stream soundstream = new FSOUND_Stream();
soundstream.Open(soundfile, (uint)FSOUND_MODE.FSOUND_LOOP_NORMAL, 0, 0);
if (soundstream.Ptr != IntPtr.Zero)
{
fmod.Stream_Play(0, soundstream);
}

====
using System;
using System.Text;
using System.Runtime.InteropServices;

namespace FMODE_CE
{

#region FSOUND_MODES
/*[DESCRIPTION]   
Sample description bitfields, OR them together for loading and describing samples.
NOTE.  If the file format being loaded already has a defined format, such as WAV or MP3, then 
trying to override the pre-defined format with a new set of format flags will not work.  For
example, an 8 bit WAV file will not load as 16bit if you specify FSOUND_16BITS.  It will just
ignore the flag and go ahead loading it as 8bits.  For these type of formats the only flags
you can specify that will really alter the behaviour of how it is loaded, are the following.
---------
Looping behaviour - FSOUND_LOOP_OFF, FSOUND_LOOP_NORMAL, FSOUND_LOOP_BIDI 
Load destination - FSOUND_HW3D, FSOUND_HW2D, FSOUND_2D
Loading behaviour - FSOUND_NONBLOCKING, FSOUND_LOADMEMORY, FSOUND_LOADRAW, FSOUND_MPEGACCURATE, FSOUND_MPEGHALFRATE, FSOUND_FORCEMONO
Playback behaviour - FSOUND_STREAMABLE, FSOUND_ENABLEFX
PlayStation 2 only - FSOUND_USECORE0, FSOUND_USECORE1, FSOUND_LOADMEMORYIOP    
---------
See flag descriptions for what these do.
]
*/
public enum FSOUND_MODE : uint
{
    FSOUND_LOOP_OFF     =   0x00000001, /* For non looping samples. */
    FSOUND_LOOP_NORMAL  =   0x00000002, /* For forward looping samples. */
    FSOUND_LOOP_BIDI    =   0x00000004,  /* For bidirectional looping samples.  (no effect if in hardware). */
    FSOUND_8BITS        =   0x00000008,  /* For 8 bit samples. */
    FSOUND_16BITS       =   0x00000010,  /* For 16 bit samples. */
    FSOUND_MONO         =   0x00000020,  /* For mono samples. */
    FSOUND_STEREO       =   0x00000040,  /* For stereo samples. */
    FSOUND_UNSIGNED     =   0x00000080,  /* For user created source data containing unsigned samples. */
    FSOUND_SIGNED       =   0x00000100,  /* For user created source data containing signed data. */
    FSOUND_NORMAL       = (FSOUND_16BITS | FSOUND_SIGNED | FSOUND_MONO)
}
#endregion

public class FMOD : IDisposable
{
    private bool initialized;
    public FMOD()
    {
        init();
    }

    private void init()
    {
        int smartphone_rate = 22050;
        FSOUND_Init(smartphone_rate, 48, 0);
        initialized = true;
    }

    public int Stream_Play(int channel, FSOUND_Stream stream)
    {
        return FSOUND_Stream_Play(channel, stream.Ptr);
    }

    public bool Stream_Stop(FSOUND_Stream stream)
    {
        return FSOUND_Stream_Stop(stream.Ptr) != 0;
    }

    public bool Music_Play(FMUSIC_Module music)
    {
        return FMUSIC_PlaySong(music.Ptr) != 0;
    }

    public bool Music_Stop(FMUSIC_Module music)
    {
        return FMUSIC_StopSong(music.Ptr) != 0;
    }

    public bool Stream_SetLoopCount(FSOUND_Stream stream, int count)
    {
        return FSOUND_Stream_SetLoopCount(stream.Ptr, count) != 0;
    }

    public bool SetVolume(int channel, int volume)
    {
        return FSOUND_SetVolume(channel, volume) != 0;
    }

    public bool SetMasterVolume(int volume)
    {
        return FSOUND_SetSFXMasterVolume(volume) != 0;
    }

    ~FMOD()
    {
        Dispose();
    }

    #region IDisposable

    public void Dispose()
    {
        if (initialized)
        {
            FSOUND_Close();
            initialized = false;
        }
    }

    #endregion


    #region FSMOD dll functions
    [DllImport("fmodce", EntryPoint="FSOUND_Close", SetLastError=true)]
    private extern static void FSOUND_Close();

    [DllImport("fmodce", EntryPoint="FSOUND_Init", SetLastError=true)]
    private extern static sbyte FSOUND_Init(int mixrate, int maxsoftwarechannels, uint flags);

    [DllImport("fmodce", EntryPoint="FSOUND_Stream_Play", SetLastError=true)]
    private extern static int FSOUND_Stream_Play(int channel, IntPtr stream);

    [DllImport("fmodce", EntryPoint="FSOUND_Stream_Stop", SetLastError=true)]
    private extern static sbyte FSOUND_Stream_Stop(IntPtr stream);

    [DllImport("fmodce", EntryPoint="FSOUND_Stream_SetLoopCount", SetLastError=true)]
    private extern static sbyte FSOUND_Stream_SetLoopCount(IntPtr stream, int count);

    [DllImport("fmodce", EntryPoint="FMUSIC_PlaySong", SetLastError=true)]
    private extern static sbyte FMUSIC_PlaySong(IntPtr music);

    [DllImport("fmodce", EntryPoint="FMUSIC_StopSong", SetLastError=true)]
    private extern static sbyte FMUSIC_StopSong(IntPtr music);

    [DllImport("fmodce", EntryPoint="FSOUND_SetVolume", SetLastError=true)]
    private extern static sbyte FSOUND_SetVolume(int channel, int volumn);

    [DllImport("fmodce", EntryPoint="FSOUND_SetSFXMasterVolume", SetLastError=true)]
    private extern static sbyte FSOUND_SetSFXMasterVolume(int volumn);

    #endregion

}

public class FMUSIC_Module : IDisposable
{
    private IntPtr _ptr;

    public IntPtr Ptr
    {
        get { return _ptr;  }
    }

    public FMUSIC_Module()
    {
        _ptr = IntPtr.Zero;
    }

    ~FMUSIC_Module()
    {
        Dispose();
    }

    public void Open(string filename)
    {
        Open(filename, 0, 0, 0);
    }

    public void Open(string filename, uint mode, int offset, int length)
    {
        Dispose();
        byte[] filenames = Encoding.Default.GetBytes(filename+'\0');
        GCHandle hfile = GCHandle.Alloc(filenames, GCHandleType.Pinned);
        IntPtr pfilename = (IntPtr)((int)hfile.AddrOfPinnedObject() + 4);
        //_ptr = FMUSIC_LoadSongEx(pfilename, offset, length, mode, IntPtr.Zero, 0);
        _ptr = FMUSIC_LoadSong(pfilename);
        if(hfile.IsAllocated) { hfile.Free(); }
    }


    #region IDisposable

    public void Dispose()
    {
        if (_ptr != IntPtr.Zero)
        {
            FMUSIC_FreeSong(_ptr);
            _ptr = IntPtr.Zero;
        }

    }

    #endregion


    #region FSMOD dll functions
    [DllImport("fmodce", EntryPoint="FMUSIC_LoadSongEx", SetLastError=true)]
    private extern static IntPtr FMUSIC_LoadSongEx(IntPtr name_or_data,int offset, int length, uint mode, IntPtr sample, int samplecount);

    [DllImport("fmodce", EntryPoint="FMUSIC_LoadSong", SetLastError=true)]
    private extern static IntPtr FMUSIC_LoadSong(IntPtr name_or_data);

    [DllImport("fmodce", EntryPoint="FMUSIC_FreeSong", SetLastError=true)]
    private extern static sbyte FMUSIC_FreeSong(IntPtr music);
    #endregion

}

public class FSOUND_Stream : IDisposable
{
    private IntPtr _ptr;

    public IntPtr Ptr
    {
        get { return _ptr;  }
    }

    public FSOUND_Stream()
    {
        _ptr = IntPtr.Zero;
    }

    ~FSOUND_Stream()
    {
        Dispose();
    }

    public void Open(string filename)
    {
        Open(filename, 0, 0, 0);
    }

    public void Open(string filename, uint mode, int offset, int length)
    {
        Dispose();
        byte[] filenames = Encoding.Default.GetBytes(filename+'\0');
        GCHandle hfile = GCHandle.Alloc(filenames, GCHandleType.Pinned);
        IntPtr pfilename = (IntPtr)((int)hfile.AddrOfPinnedObject() + 4);
        _ptr = FSOUND_Stream_Open(pfilename, mode, offset, length);
        if(hfile.IsAllocated) { hfile.Free(); }
    }

    #region IDisposable

    public void Dispose()
    {
        if (_ptr != IntPtr.Zero)
        {
            FSOUND_Stream_Close(_ptr);
            _ptr = IntPtr.Zero;
        }
    }

    #endregion

    #region FSMOD dll functions
    [DllImport("fmodce", EntryPoint="FSOUND_Stream_Close", SetLastError=true)]
    private extern static sbyte FSOUND_Stream_Close(IntPtr ptr);
    [DllImport("fmodce", EntryPoint="FSOUND_Stream_Open", SetLastError=true)]
    private extern static IntPtr FSOUND_Stream_Open(IntPtr name_or_data, uint mode, int offset, int length);
    #endregion
}

}

  • You must to post comments
Showing 6 results
Your Answer

Please first to submit.