views:

91

answers:

1

Can anyone help me on playing a file from a memorystream using FMOD or any other way?

So far i have this:
Variables

    private FMOD.System _fmod = null;
    private FMOD.Sound _sound = null;
    private FMOD.Channel _channel = null;

Code

        var file = File.ReadAllBytes("test.ogg");
        //MessageBox.Show("Bytes from file: " + file.Length);

        FMOD.Factory.System_Create(ref _fmod);

        var result = _fmod.init(2, FMOD.INITFLAGS.NORMAL, (IntPtr)null);
        if(result != FMOD.RESULT.OK) ShowError(result);

        var info = new FMOD.CREATESOUNDEXINFO();

        result = _fmod.createStream(file, MODE.CREATESTREAM, ref info,  ref _sound);
        if (result != RESULT.OK) ShowError(result);

Any help would be greatly appreciated

+1  A: 

Firstly I highly recommend you take a look at the "loadfrommemory" example that ships with FMOD (it has a C# version too). But to answer your question here:

  1. You need to populate some members of the FMOD.CREATESOUNDEXINFO structure:

    info.cbsize = Marshal.SizeOf(info); info.length = file.Length;

  2. You need to tell FMOD you are providing in-memory data with the OPENMEMORY flag:

    result = _fmod.createStream(file, MODE.CREATESTREAM | MODE.OPENMEMORY, ref info, ref _sound);

That should be all you need to get going.

Mathew Block
WOW< how did i not see the examples_csharp!!!??? You are an absolute saviour!!! wish i could give u all my points :P thanks for the help!!
LnDCobra
:D :D :D :D :D :D you're a god :) i thought i will never get my music player which i need to make for my dissertation working!!! :) FMOD is great!!!
LnDCobra
Hey thanks, this is working now, but i have another problem, if i only fill, lets say, 10% of the buffer, then start playing, then carry on filling the buffer, the sound stop playing once it reaches the 10% mark. Do you know why that could be?
LnDCobra
By using MODE.OPENMEMORY you are telling FMOD to copy the data pointed to by 'file' into its internal buffers. You could use MODE.OPENMEMORY_POINT but there are better solutions for streaming such as user created sounds with read callbacks.
Mathew Block