Alut.alutLoadMemoryFromFile = 0?

Started by
12 comments, last by Zahlman 13 years, 1 month ago
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


Advertisement
Use Al.alGetError(). The possible error codes for alutLoadMemoryFromFile() are listed here.
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
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.
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...
Can you post the new code? (using source tags)

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));
}
You're not checking the value of errorCode2...
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)).
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.

This topic is closed to new replies.

Advertisement