0
0

I am trying to use option above. When I try

[code:2tbrjb9q]
private byte[] buffer;
//buffer is filled by reading from file
IntPtr buf;
unsafe
{
GCHandle gch = GCHandle.Alloc(buffer, GCHandleType.Pinned);
buf = gch.AddrOfPinnedObject();
}
//now buf is of IntPtr type

        //result = system.createSound(buffer, FMOD.MODE.SOFTWARE | FMOD.MODE.OPENMEMORY, ref exinfo, ref sound); //works
        result = system.createSound(buf, FMOD.MODE.SOFTWARE | FMOD.MODE.OPENMEMORY_POINT, ref exinfo, ref sound);
        ERRCHECK(result);

[/code:2tbrjb9q]

compiler (VS2008) complains that it can not find overload:

[code:2tbrjb9q]
Error 1 The best overloaded method match for ‘FMOD.System.createSound(string, FMOD.MODE, ref FMOD.CREATESOUNDEXINFO, ref FMOD.Sound)’ has some invalid arguments C:\Documents and Settings\...
Error 2 Argument ‘1’: cannot convert from ‘System.IntPtr’ to ‘string’ C:\Documents and Settings\...
[/code:2tbrjb9q]

Which overload should I use? The one with the string???

Hope somenone can help.
ZoranK

  • You must to post comments
0
0

Hi,

Take a look at the loadfrommemory example

  • You must to post comments
0
0

Many thanks for trying to help me out. Though I am not sure you understood my problem.

Of course, I studied "loadfrommemory.cs" very, very carefully. I actully use code from this example as skeleton to construct openmemory_point example. Problem is that mode.openmemory_point is structurally very different from mode.openmemory.

For example in the "loadfrommemory.cs" the data is passed as byte array. There is a specific overload that can be used for that purpose:

system.createSound(byte[] data, …)

However, all other overloads are of the type

system.createSound(string name_of_data, …)

and this creates problems (at least for me). I do not know how to cheat c# compiler to pass pointer to "byte[] data" as string pointer. c# does not allow that due to type safety (string is special type, it is reference type but a special reference type).

Bellow, is what I tried and how it behaves

[code:3srl5r0g]
//code bellow should lock buffer array from Garbage Collector
IntPtr bufPointer;
unsafe
{
GCHandle gch = GCHandle.Alloc(buffer, GCHandleType.Pinned);
bufPointer = gch.AddrOfPinnedObject();
}
// here buffer is locked and bufPointer points to it.
....
//result = system.createSound(buffer, FMOD.MODE.SOFTWARE | FMOD.MODE.OPENMEMORY, ref exinfo, ref sound); //works
//result = system.createSound(buffer, FMOD.MODE.SOFTWARE | FMOD.MODE.OPENMEMORY_POINT, ref exinfo, ref sound); // throws result = err_memory_iop
result = system.createSound((string*)bufPointer.ToPointer(), FMOD.MODE.SOFTWARE | FMOD.MODE.OPENMEMORY_POINT, ref exinfo, ref sound); //compilation error
[/code:3srl5r0g]

In the last line compiler complains "The best overloaded method match for ‘FMOD.System.createSound(string, FMOD.MODE, ref FMOD.CREATESOUNDEXINFO, ref FMOD.Sound)’ has some invalid arguments" and "Argument ‘1’: cannot convert from ‘string*’ to ‘string’".

Of course, as you can see, I am far from c# expert. Perhaps it is possible just that I do not know how to do it.

To begin, which overload shoud I use?

All the help appreciated
ZoranK

  • You must to post comments
0
0

You need to use the ByteArray overload, it should work if you just pass in the byte array that you have.

Also, if you are using an adpcm/mp2/mp3, FMOD_CREATECOMPRESSEDSAMPLE also needs to be specified for it to work. Please read the documentation for the FMOD_OPENMEMORY_POINT flag.

In the loadfrommemory example, i simply changed the playsound to:

[code:38btn2a9]
result = system.createSound(audiodata, (FMOD.MODE.SOFTWARE | FMOD.MODE.OPENMEMORY_POINT | FMOD.MODE.CREATECOMPRESSEDSAMPLE), ref exinfo, ref sound);
[/code:38btn2a9]

and it works fine.

  • You must to post comments
0
0

Many thanks for help. Indeed, it works thought I noticed antoher problem:

If I use wav instead of mp3 file then it throws err_memory_iop

[code:1njz3ui4]
//length = LoadFileIntoMemory("../../../../examples/media/wave.mp3");
length = LoadFileIntoMemory("../../../../examples/media/drumloop.wav");
....
result = system.createSound(audiodata, (FMOD.MODE.SOFTWARE | FMOD.MODE.OPENMEMORY_POINT | FMOD.MODE.CREATECOMPRESSEDSAMPLE), ref exinfo, ref sound);
ERRCHECK(result);
[/code:1njz3ui4]

Same error if I take away "FMOD.MODE.CREATECOMPRESSEDSAMPLE" option. Have no clue what could be the problem… Why is it behaving like that (refusing wav file)?

ZoranK

  • You must to post comments
0
0

drumloop.wav is 8bit, FMOD_OPENEMEMORY_POINT doesn’t work for 8bit pcm data either.

Also, it looks like the FMOD errors are off by one in the c# wrapper. It should be returning FMOD_ERR_MEMORY_CANTPOINT, not FMOD_ERR_MEMORY_IOP, I’ll get this fixed up for our next release.

  • You must to post comments
Showing 5 results
Your Answer

Please first to submit.