Jump to content
  • Advertisement
Sign in to follow this  
NickC

Alut.alutLoadMemoryFromFile = 0?

This topic is 2697 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello

This is my first post on this forum, so I am sorry if I write something against the rules...

I started game programming in C# a couple of weeks ago, and now I am trying to include sound support in my project with the openAL library. Everything works perfectly, except: if it wants to do

IntPtr data = Alut.alutLoadMemoryFromFile(path, out format, out size, out frequency);

it says data is 0.

Here is some of the full code of my class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tao.OpenAl;
using System.IO;

...

namespace Engine
{
public class SoundManager
{
...
public SoundManager()
{
Alut.alutInit();
...
}
...

Dictionary<string, SoundSource> _soundIdentifier = new dictionary<string, SoundSource>();
public void LoadSound(string soundId, string path)
{
// Generate a buffer.
int buffer = -1;
Al.alGenBuffers(1, out buffer);
int errorCode = Al.alGetError();
System.Diagnostics.Debug.Assert(errorCode == Al.AL_NO_ERROR);
int format;
float frequency;
int size;
System.Diagnostics.Debug.Assert(File.Exists(path));
IntPtr data = Alut.alutLoadMemoryFromFile(path, out format, out size, out frequency);
System.Diagnostics.Debug.Assert(data != IntPtr.Zero);
// Load wav data into the generated buffer.
Al.alBufferData(buffer, format, data, size, (int)frequency);
// Everything seems ok, add it to the library.
_soundIdentifier.Add(soundId, new SoundSource(buffer, path));
}
}
}

I guess this is enough code to let you show.

The .wav file it wants to load is in my bin/debug folder (it gives no error at System.Diagnostics.Debug.Assert(File.Exists(path)).
I added the right references, and I also added the alut.dll file in de bin/debug folder.

Is there someone who is familiar with openAL or C# who could tell me what my problem is?

thanks
Nick


Share this post


Link to post
Share on other sites
Advertisement
maybe a stupid question, but where should I put the statement Al.alGetError()? I already used one at the third line of my loadsound method, so why use it twice?

thanks
Nick

Share this post


Link to post
Share on other sites
Quote:
where should I put the statement Al.alGetError()?


Right after the call to alutLoadMemoryFromFile.

Quote:
I already used one at the third line of my loadsound method, so why use it twice?


Because the error state can change after every OpenAL method you call.

Look at the documentation for alGetError for more info.

Share this post


Link to post
Share on other sites
thanks,

I put it everywhere in the loadsound method and when I put a breakpoint and look at every line it says AL.ALGetError() is 0. So that doesn't really help me...

Share this post


Link to post
Share on other sites

public void LoadSound(string soundId, string path)
{
// Generate a buffer.
int buffer = -1;
Al.alGenBuffers(1, out buffer);
int errorCode = Al.alGetError();
System.Diagnostics.Debug.Assert(errorCode == Al.AL_NO_ERROR);
int format;
float frequency;
int size;
System.Diagnostics.Debug.Assert(File.Exists(path));

IntPtr data = Alut.alutLoadMemoryFromFile(path, out format, out size, out frequency);
int errorCode2 = Al.alGetError();
System.Diagnostics.Debug.Assert(data != IntPtr.Zero);
// Load wav data into the generated buffer.
Al.alBufferData(buffer, format, data, size, (int)frequency);
// Everything seems ok, add it to the library.
_soundIdentifier.Add(soundId, new SoundSource(buffer, path));
}

Share this post


Link to post
Share on other sites
I am so sorry, for my questions but what should I exactly do? Could you post 2 or three lines plz? You say I can get more information about Alut.alutLoadMemoryFromFile not working by using AL.ALGetError(), but AL.ALGetError = 0! And what should I do with if errorCode2 == Al.AL_NO_ERROR if I already know it is (I put a breakpoint and checked the values of every line (F11)).

Share this post


Link to post
Share on other sites
After this line:

int errorCode2 = Al.alGetError();

add this:

if (errorCode2 != Al.AL_NO_ERROR)
{
// Report error
}


If the value of errorCode2 really is Al.AL_NO_ERROR, then I'm not sure what to do.

Share this post


Link to post
Share on other sites

This topic is 2697 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!