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

## 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.
}
}
}

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 on other sites
Use Al.alGetError(). The possible error codes for alutLoadMemoryFromFile() are listed here.

##### Share on other sites
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 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.

##### 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 on other sites
Can you post the new code? (using source tags)

##### Share on other sites
[code]
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.
}[/code]

##### Share on other sites
You're not checking the value of errorCode2...

##### 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 on other sites
After this line:

int errorCode2 = Al.alGetError();

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 on other sites
thanks

doesn't really help, but...good new: I found my error!

After the statement

Alut.alutInit();

I put

int error 3 = Alut.alutGetError();

obviously the error is 519, after some search this is Alut.ALUT_ERROR_OPEN_DEVICE.
So the eroor went at initializing alut.

what should I do now?

Nick

##### Share on other sites
I apologize, I should have realized that alut has its own GetError method.

The only thing I can recommend is looking for OpenAL tutorials and code samples, making sure you can get them to work, and then figuring out how your code is different.

##### Share on other sites
Hi,
I found something similar with your code when I was reading the book <<C-#.Game.Programming.-.For.Serious.Game.Creation>> and now I have the same question, that it returns 0, but my alutInit() Function works well, it doesn't give an errorCode, plus, two functions---Al.alGenSources(this is from a function called DiscoverChannel(1,out src)) and Al.alGenBuffers(1, out buffer)-- don't seem to work as expected because src and buffer stay the same (that is, -1) after those functions.
I just started learning C#, and I happened to find that your question has been posted for quite a time, did you solve your own ? I really appreciate it if you could share some experience.~~

##### Share on other sites
[quote name='Jaaack' timestamp='1299120254' post='4781250']
Hi,
I found something similar with your code when I was reading the book <<C-#.Game.Programming.-.For.Serious.Game.Creation>> and now I have the same question, that it returns 0, but my alutInit() Function works well, it doesn't give an errorCode, plus, two functions---Al.alGenSources(this is from a function called DiscoverChannel(1,out src)) and Al.alGenBuffers(1, out buffer)-- don't seem to work as expected because src and buffer stay the same (that is, -1) after those functions.
I just started learning C#, and I happened to find that your question has been posted for quite a time, did you solve your own ? I really appreciate it if you could share some experience.~~

[/quote]

Please don't reply to old posts like this - the OP isn't necessarily around any more and doesn't necessarily remember what happened. You don't really have the same question either.