0
0

Hello.
I would like to know if there is any support (existing or planned) for .NET.
I intend to use FMOD with Visual C# or if necessary with VB .NET.
I got a sample-program to run under Visual C#, but I had to migrate everything by hand.
Thanks for any information. Prem.

  • You must to post comments
0
0

From my understanding of .NET, there seems to be two ways we can go here.

  1. Provide source files for each language that define the types and import the functions from the DLL. This is like the current FMOD release where each API update means updating several source files with the same change.
  2. Provide one assembly that works for all .NET languages. This assembly declares all the types and the functions in a common manner. One source file to produce one assembly for all .NET languages.
  • You must to post comments
0
0

Hi fellow FMOD developers,

I’ve had a good read through this conversation topic and have followed a simple enough path. i.e. Learn a bit about c#, write a wrapper for FMOD.

I can get FMOD playing, stopping, closing no problem.

I don’t know what you guys have got in your wrappers, but for information, I have declard Stream_OpenFile as below. I like how you can convert a normal unicode string type directly into a pointer to a ascii string in c#.

Just out of interest, Is this how other people do it?

[ DllImport( “fmod.dll”, CharSet=CharSet.Auto )]
public static extern int FSOUND_Stream_OpenFile([MarshalAs(UnmanagedType.LPStr)] string FileName, FSOUND_MODES mode, int memlength);

I am having problems with call backs though. I can get C# to handle a callback as shown below.

The problem is that if I call FSOUND_Stream_Stop(streamID); the FMOD DLL seems to throw an exception AFTER it has handled the callback.

A snippet of my code (with error checking and other stuff removed for clarity) is below. It is based on the good old fmod.bas file for VB6 users.

[code:1ruyxsi0]using System.IO;
using System;
using System.Runtime.InteropServices;
using FMODWRAP;
using System.Diagnostics;

namespace FMODWRAP
{
public class FSOUND
{
public enum FSOUND_MODES : int
{
FSOUND_LOOP_OFF = 0x01, // For non looping samples.
FSOUND_8BITS = 0x08, // For 8 bit samples.
FSOUND_16BITS = 0x10, // For 16 bit samples.
FSOUND_MONO = 0x20, // For mono samples.
FSOUND_STEREO = 0x40, // For stereo samples.
FSOUND_2D = 0x2000, // Ignores any 3d processing. overrides FSOUND_HW3D. Located in software.
FSOUND_NORMAL = FSOUND_LOOP_OFF | FSOUND_16BITS | FSOUND_STEREO | FSOUND_2D
}

    public enum FSOUND_INITMODES : int
    {
        FSOUND_INIT_GLOBALFOCUS = 0x02
    }

    [ DllImport( "fmod.dll", CharSet=CharSet.Auto) ]
    public static extern byte FSOUND_Init(int mixrate, int maxchannels, FSOUND_INITMODES Flags);

    [ DllImport( "fmod.dll", CharSet=CharSet.Auto )]
    public static extern byte FSOUND_Close();

    [ DllImport( "fmod.dll", CharSet=CharSet.Auto )]
    public static extern int FSOUND_Stream_OpenFile([MarshalAs(UnmanagedType.LPStr)] string FileName, FSOUND_MODES mode, int memlength);

    [ DllImport( "fmod.dll", CharSet=CharSet.Auto )]
    public static extern int FSOUND_Stream_Play(int channel, int stream);

    [ DllImport( "fmod.dll", CharSet=CharSet.Auto )]
    public static extern byte FSOUND_Stream_Stop(int stream);

    [ DllImport( "fmod.dll", CharSet=CharSet.Auto )]
    public static extern byte FSOUND_Stream_Close(int stream);

    public delegate byte STREAMCALLBACK(IntPtr stream, IntPtr buff, int len, int param);

    [ DllImport( "fmod.dll", CharSet=CharSet.Auto )]
    public static extern byte FSOUND_Stream_SetEndCallback(int stream, STREAMCALLBACK x, int userdata);

    const int FSOUND_FREE = -1;


    public bool Initialise(int BitRate, int Channels, FSOUND.FSOUND_INITMODES modes)
    {
        return FSOUND_Init(BitRate, Channels, modes) == 1;
    }

    public int StreamOpenFile(string filename, FSOUND_MODES mode, int memlength)
    {
        //Note that the OpenFile DLL definition uses the MarshalAs attribute ([MarshalAs(UnmanagedType.LPStr)] string FileName)
        return FSOUND_Stream_OpenFile(filename, mode, memlength);
    }

    public class Stream
    {
        public int StreamID = -1;
        public int ChannelID = -1;

        public Stream(string f)
        {
            StreamID = FSOUND_Stream_OpenFile(f, FSOUND.FSOUND_MODES.FSOUND_NORMAL, 0);
        }

        public void Play()
        {
            ChannelID = FSOUND_Stream_Play(FSOUND_FREE, StreamID);
            STREAMCALLBACK myCallBack = new STREAMCALLBACK(StreamEndCallback);
            FSOUND_Stream_SetEndCallback(StreamID, myCallBack, 0);
            Debug.WriteLine("FSOUND_Stream_SetEndCallback called.");
        }
        public byte StreamEndCallback(IntPtr stream, IntPtr buff, int len, int param)
        {
            Debug.WriteLine("StreamEndCallback fired.");
            FSOUND_Stream_Close(StreamID);
            return 0;
        }

        public void Stop()
        {              
            FSOUND_Stream_Stop(StreamID);
        }
    }
}

}[/code:1ruyxsi0]

I’ve tried making the callback static, didn’t make any difference.

Does anyone have any ideas what I might me doing wrong?

Would anyone care to send me thier wrapper if they have callbacks working?

Many thanks,

Andy

  • You must to post comments
0
0

[quote="Sly":1nhbx6fy]I just tried to do a small test in C#. I got a small assembly going with init and close working, but got stuck at trying to pass a String to a function that expects a char *.

Not that I’m really serious about using C#. To me it still feels like too much work to do the simplest thing.[/quote:1nhbx6fy]

I know exactly what you mean. I had this problem however a quick look in Petzold managed to shed some light on it. You need to use a StringBuilder found in System.Text.

David Glover

  • You must to post comments
0
0

Sweet! I’m assuming that Seth knows a bit more about .NET than us .NET newbies. :)

  • You must to post comments
0
0

I’d imagine you would have things like Fmod.Sound, Fmod.Music, etc.? I’m just starting to read stuff about .NET for both C# and Delphi for .NET.

  • You must to post comments
0
0

An hour or two to learn how to use it properly in C# (with no prior C# experience). Another couple of hours to get several FMOD functions into the wrapper along with the test app while playing around with different ways of implementing them.

  • You must to post comments
0
0

[quote="Sly":hhguwgex]If I’m right, using Managed C++ could make an assembly that interfaces to the DLL without using Interop?[/quote:hhguwgex]

That is correct. Like I said, I have done this quite a bit for projects at work.

For FMod I was thinking of just wrapping the C structs in managed structs, using constants for the C #defines and possibly two other structs; one for the Sound functions and one for the Music functions. I would just create static methods on the structs that coincide with each of the FMod function calls. This would be the most direct way without having to come up with a good class design. In the future it would be nice to move to something more OO but, as a first pass, I think it would work well.

What do people think about that? If anything else has been done in this area I would also like to know about it. I don’t want to reinvent the wheel if I do not have to.

Rob

  • You must to post comments
0
0

Hello all,
I’m new to the forums, new to the FMOD SDK and looking forward to doing some development with it in C#. I’ve found that with some good documentation, porting the function calls with PInvoke to C# is relatively easy. I’ve already done media applications with BASS and Miles in C#. – 3 – 8 band equalizers, Shoutcast playback, etc. DirectX 9 is seriously lacking features of an audio SDK like FMOD. I’d be happy to post my results/source code to the list if anyone is interested and if there is a place to do so.

  • You must to post comments
0
0

Coding callback in c#, you need to use delegates… (correct me if i am wrong)

you replace c++ pointers in c# to ref

Hope it helps…

still thinking of my wrapper…

Regards,
Chua Wen Ching :p

  • You must to post comments
0
0

Okay. Since i can’t play much fmod with c#!

I will come back next time, when fmod is ready!

😆

Thank you.

Regards,
Chua Wen Ching :p

  • You must to post comments
0
0

I am using Compact .NET Framework on pocket pc 2002 in c#.

I used win32 version of fmod.dll for testing on my xp using Compact .NET Framework and everything worked. However, downloading the app to my pocket pc and using ARM version of fmodce.dll(3.63), the .ogg file(any file) refuses to load. I am using the following to load:

[code:2vb5ni0e]
[DllImport("fmod.dll", EntryPoint="FSOUND_Sample_Load", SetLastError=false)]
private static extern IntPtr FSOUND_Sample_Load(int index, string name_or_data, uint inputmode, int memlength);
[/code:2vb5ni0e]

MarshallAs attribute is not supported by CNF of course, and CharSet attribyte also doesn’t seem to affect the outcome.

The error code I do get is 9. I assume it’s “File Not Found” error. CNF code just right before the pinvoke confirms that the file exists, and I am wondering why FMOD is not able to. I suspect the function is not getting the filename correctly. Note that the code works perfectly on my xp using the same CNF. The culprit must be either FMOD itself or how CNF is passing the filename string to FMOD.

Any ideas? 😡

  • You must to post comments
0
0

The .NET port does not have to be done in C#. .NET assemblies can be made in any .NET language. Borland has a Delphi for .NET compiler preview available and Microsoft is bringing out Visual C++ for .NET soon.

  • You must to post comments
0
0

Thanks!

I receive your files!

Just wondering..

I definitely need fmod.dll right!

How do you know:

1)

FSOUND_LOOP_OFF = 0x00000001
–> why must it be 0x0….1 and not 0x…2 – where you get this info from?

2)

All the enums are also based on the orginal fmod?

3) Did you refer to any fmod API when you create the wrapper? Just wonder how you get to know how many functions and types that available in fmod!

4) Once i compile the wrapper, i can add references to fmod? So the Fmod.Sound.cs is a different project with Main.cs right?

5) Lastly, i can implement fmod in a game engine! Coz the game engine sound is lousy!

6) Must i place the fmod.dll in the windows/system32 folder?

Just to confirm!

Thanks anyway!

Regards,
Chua Wen Ching :p

  • You must to post comments
0
0

I had started on a class-based C# wrapper (yes, it used PInvoke). Hadn’t finished it because I really don’t have much interest in .NET as yet.

  • You must to post comments
0
0

[quote="Sly":3b32kzg2]From my understanding of .NET, there seems to be two ways we can go here.

  1. Provide source files for each language that define the types and import the functions from the DLL. This is like the current FMOD release where each API update means updating several source files with the same change.

  2. Provide one assembly that works for all .NET languages. This assembly declares all the types and the functions in a common manner. One source file to produce one assembly for all .NET languages.[/quote:3b32kzg2]

From past experience of P/Invoke number 2 is likely to be the best answer by far. By picking a language (I always use C# as somehow it feels cleaner with P/Invoke) and then creating objects as you would in C++, you can make the native api available to anyone in any .Net language.

There is really no need to consider number 1, a class defined in C# and put in an assembly is accessible from ALL other .Net capable languages. Nice eh? That’s sort of why when you see ArrayList() used in several different languages it looks kinda freaky.

Generally I always ‘hide’ the native calls inside a class and only ‘allow’ that class to use the calls, making the FMod.Net API just a wrapper over the existing ones. Rather than have one source file you could just group all of the existing FMod calls into a class.

Using P/Invoke allows you to define C# structs to match any C ones you have and then marshall directly between the managed and unmanaged types. DotNet even has IntPtr which you can treat like a void *.

There is a lot of code in C# SDL that you could look at for clues (cssdl.sourceforge.net), it’s fairly obvious in there what is happening.

Feel free to ignore this advice (I’m not sure I’ve clarified anything), I only came here with a MacOS X linking problem … but I can’t resist getting involved in P/Invoke problems :)

  • You must to post comments
0
0

[quote="asmcon":143luq2k]Just out of interest, Is this how other people do it?

[ DllImport( “fmod.dll”, CharSet=CharSet.Auto )]
public static extern int FSOUND_Stream_OpenFile([MarshalAs(UnmanagedType.LPStr)] string FileName, FSOUND_MODES mode, int memlength);
[/quote:143luq2k]
I declare the function exactly the same way except I leave out the [MarshalAs(UnmanagedType.LPStr)]. Still works.

[quote:143luq2k]I am having problems with call backs though. I can get C# to handle a callback as shown below.

The problem is that if I call FSOUND_Stream_Stop(streamID); the FMOD DLL seems to throw an exception AFTER it has handled the callback.
[/quote:143luq2k]
Are you using the stdcall version of FMOD? That is a requirement since .NET does not how to handle cdecl functions. As for the error when returning from the callback, yes we are all getting that. Not sure how to handle that one. But we will keep trying.

  • You must to post comments
0
0

So far I have got a C# console application loading and playing a stream using a FMOD assembly (fmodnet.dll). The sample code for a simple stream player is below.

David, I found the solution to passing strings to FMOD. Just use String as the parameter type. A class type is already a pointer anyway. It seems to work fine.

I have callbacks working as well, but I get an exception raised if I try to call Fmod.Sound.Stream.GetTime() in the while loop when using the callback. If I do not get the stream time in the while loop, no exception is raised. If I use Fmod.Sound.IsPlaying() instead of the callback, no exception is raised. I can’t work this problem out yet.

Oh, and yes you have to use stdcall version of FMOD to get callbacks working properly.

[code:2pdk2e7a]
using System;
using Fmod;

class MainClass
{
// static bool ended = false;

// public static byte EndStreamCallback(uint stream, uint buff, int len, int param)
// {
// ended = true;
// return 0;
// }

public static void Main(string[] args)
{
Fmod.Sound.Init(44100, 32, 0);
Console.WriteLine("FMOD initialised");

uint stream = Fmod.Sound.Stream.OpenFile("..\\..\\media\\jules.mp3", Fmod.Modes.FSOUND_NORMAL, 0);
if (stream == 0)
  Console.WriteLine("Stream open failed");
else
{
  Console.WriteLine("Stream opened");

// Fmod.Sound.Stream.Callback endCallback = new Fmod.Sound.Stream.Callback(EndStreamCallback);
// Fmod.Sound.Stream.SetEndCallback(stream, endCallback, 0);

  int channel = Fmod.Sound.Stream.Play(Fmod.Misc.FSOUND_FREE, stream);

  while (Fmod.Sound.IsPlaying(channel) != 0)

// while (!ended)
{
Console.Write("\r" + Fmod.Sound.Stream.GetTime(stream) + "ms");
}
Console.WriteLine("\nStream ended");

  Fmod.Sound.Stream.Stop(stream);

  Fmod.Sound.Stream.Close(stream);
  Console.WriteLine("Stream closed");
}
Fmod.Sound.Close();
Console.WriteLine("FMOD closed");

}
}
[/code:2pdk2e7a]

  • You must to post comments
0
0

I doubt the path is wrong, since I am using exactly the same path with CNF and it locates it and confirms it’s there (of course I can’t really load it cause it’s ogg).

\My Documents\Personal\x.ogg

seems like a pretty standard path. I tried setting the current directory to it first. No luck.

Sorry about the thread. I will move the discussion to fmod ce.

  • You must to post comments
0
0

Isn’t it possible to just use the VB wrapper with VB.Net?

  • You must to post comments
0
0

[quote="chuawenching":2ys6b823]1)

FSOUND_LOOP_OFF = 0x00000001
–> why must it be 0x0….1 and not 0x…2 – where you get this info from?
[/quote:2ys6b823]From fmod.h.

[quote:2ys6b823]2)

All the enums are also based on the orginal fmod?
[/quote:2ys6b823]Copied straight across from fmod.h.

[quote:2ys6b823]3) Did you refer to any fmod API when you create the wrapper? Just wonder how you get to know how many functions and types that available in fmod!
[/quote:2ys6b823]I referred solely to fmod.h.

[quote:2ys6b823]4) Once i compile the wrapper, i can add references to fmod? So the Fmod.Sound.cs is a different project with Main.cs right?
[/quote:2ys6b823]Use Fmod.Sound.cs to compile an assembly. I called my assembly fmodnet. Then use Main.cs to compile a console application. I called my application fmodtest. Add fmodnet as a reference in the fmodtest project. Put fmodnet.dll and fmod.dll (use the stdcall version of fmod.dll available on the downloads page if you wish to use callbacks) in the same directory as fmodtest.exe. Now run fmodtest.exe.

[quote:2ys6b823]5) Lastly, i can implement fmod in a game engine! Coz the game engine sound is lousy!
[/quote:2ys6b823]Of course you can. You can do anything the FMOD license allows you to do.

[quote:2ys6b823]6) Must i place the fmod.dll in the windows/system32 folder?
[/quote:2ys6b823]You can put fmod.dll anywhere in the search path. When a DLL is loaded, Windows searches paths in the following order…
1. The directory from which the application loaded.
2. The current directory.
3. The Windows system directory.
4. The Windows directory.
5. The directories that are listed in the PATH environment variable.

Just remember to use the stdcall version of fmod.dll if you wish to use callbacks. I have had some problems getting callbacks working properly so far, so I would recommend not using them just yet.

  • You must to post comments
Showing 1 - 20 of 75 results
Your Answer

Please first to submit.