Jump to content


read listener position from ASCII file


16 replies to this topic

#1 stranomavero

    Member

  • Members
  • PipPip
  • 35 posts

Posted 04 September 2007 - 04:27 PM

hello to everyone!

i'm studying the tutorial http://www.devmaster...rticles/openal/ and i'm trying to modify it a bit,in order to fit it to my purpouses.
I've already got a 3D environment made with OGRE; it outputs the position of the listener as an ASCII file.
How can i make the code for the sound read that position?

any kind of tips and suggestions would be extremely precious...i'm groping in the dark! :)

#2 monjardin

    Senior Member

  • Members
  • PipPipPipPip
  • 1033 posts

Posted 04 September 2007 - 04:31 PM

You could use the Standard Input / Output Streams Library (a.k.a iostreams), or did I misunderstand your question? In any event, using a file to pass this information seems horribly inefficient.
monjardin's JwN Meter (1,2,3,4,5,6):
|----|----|----|----|----|----|----|----|----|----|
*

#3 stranomavero

    Member

  • Members
  • PipPip
  • 35 posts

Posted 05 September 2007 - 09:29 AM

i'm sure it is really inefficient,but the problem is that the 3D environment was made by another department(i'm doing a PhD in a college) and i'm supposed to add the audio.
I have only the final product made with OGRE and not the code.
I'll mention it to them,to see if we can avoid this bottle neck.

I'm a newbie in programming,so can you give few more tips?
what's the command to read the coordinates from the file?

#4 stranomavero

    Member

  • Members
  • PipPip
  • 35 posts

Posted 05 September 2007 - 09:29 AM

ps:thank you very much for you attention! :)

#5 Wernaeh

    Senior Member

  • Members
  • PipPipPipPip
  • 368 posts

Posted 05 September 2007 - 12:57 PM

Hey there :)

That actually depends on how your file is formatted.

Say you have got a simple whitespace terminated ASCII file with three standard format IEEE floating point numbers in it, such as

0.73 0.1112 10.45

Then, you can read in your three coordinates like this
#include <fstream> // Header with std::[i,o]fstream classes

/* .... */

std::ifstream myfile; // Create a new input file stream
myfile.open("FILEDIR\\Filename.txt"); // Connect file stream to file

double x, y, z; // Coordinates
myfile >> x; // Read them out, one by one, whitespace automatically is ignored
myfile >> y;
myfile >> z;

Reading a different format (CSV or similar) might take a bit more time for implementation.

Cheers,
- Wernaeh
Some call me mathematician, some just call me computer guy. Yet, I prefer the term professional weirdo :)

#6 monjardin

    Senior Member

  • Members
  • PipPipPipPip
  • 1033 posts

Posted 05 September 2007 - 03:03 PM

stranomavero said:

I'm a newbie in programming,so can you give few more tips?
Could you post a small example of the ASCII file in question?
monjardin's JwN Meter (1,2,3,4,5,6):
|----|----|----|----|----|----|----|----|----|----|
*

#7 stranomavero

    Member

  • Members
  • PipPip
  • 35 posts

Posted 06 September 2007 - 10:40 AM

first of all,thank u guys for the quick replies!!

this is the format:

x315346.304077 z233442.343323 a25.650650

the user has can't change the height (it's fixed by default at 4m) but only the 2 dimensions of an horizontal plane x,z and the angle a

#8 Wernaeh

    Senior Member

  • Members
  • PipPipPipPip
  • 368 posts

Posted 06 September 2007 - 12:40 PM

Well, this makes things slightly more complicated.

If its just for a small project (i.e. no code reuse, no need for robustness), I'd suggest the following:

std::ifstream infile;
infile.open("filename");

float coordinates[3];
for (int i = 0;
      i < 3;
      ++i)
{
              infile.get();
              infile >> coordinates[i];
}


Note this assumes that there are no errors within the source file (i.e. leading char always present). For a more robust version, invent some sort of error checking on your own :)

Cheers,
- Wernaeh
Some call me mathematician, some just call me computer guy. Yet, I prefer the term professional weirdo :)

#9 stranomavero

    Member

  • Members
  • PipPip
  • 35 posts

Posted 06 September 2007 - 12:49 PM

thank u very much!!!
it might be a stupid question,but i don't get how the code you gave me "understands" the difference between the coordinate of a plan (x,z) and the orientation a.

thanks and sorry for bothering you again

#10 monjardin

    Senior Member

  • Members
  • PipPipPipPip
  • 1033 posts

Posted 06 September 2007 - 04:25 PM

infile.get(); removes the leading character and infile >> coordinates[i]; parses the following floating point number. It doesn't know the difference between xza, rather he is using the known order of the variables.
monjardin's JwN Meter (1,2,3,4,5,6):
|----|----|----|----|----|----|----|----|----|----|
*

#11 stranomavero

    Member

  • Members
  • PipPip
  • 35 posts

Posted 06 September 2007 - 04:41 PM

cool!
i understand.
how should i tell the computer that a is the angle between the user's view and the axis north-south? it was meant for the partition of the sound between the left and right earphone.
do you think it is useless or i don't need it?

#12 monjardin

    Senior Member

  • Members
  • PipPipPipPip
  • 1033 posts

Posted 06 September 2007 - 09:26 PM

Is the user always at the origin?
monjardin's JwN Meter (1,2,3,4,5,6):
|----|----|----|----|----|----|----|----|----|----|
*

#13 stranomavero

    Member

  • Members
  • PipPip
  • 35 posts

Posted 07 September 2007 - 10:12 AM

yes,the user is always in the middle of the screen

#14 monjardin

    Senior Member

  • Members
  • PipPipPipPip
  • 1033 posts

Posted 07 September 2007 - 03:36 PM

OK, I've never used OpenAL, but I imagine you will place the listener at the origin and then use the angle from the file to provide a direction vector for it. In plain English: the library needs to know which way the listener is facing in order to correctly place the sound relative to it in 3D.

EDIT: Alternatively, you could transform your x and z coordinates by rotating them about the origin by a if you only have a single source.
monjardin's JwN Meter (1,2,3,4,5,6):
|----|----|----|----|----|----|----|----|----|----|
*

#15 stranomavero

    Member

  • Members
  • PipPip
  • 35 posts

Posted 07 September 2007 - 03:45 PM

i think i'm giving up to openal...i can't fix a problem with alut.
anyway i have more than one source but i'll try to understand the facing thing by studying a piece of code i found! :)

so do you think it will work reading the ASCII file that way and then defining the angle as you said?

ps:thank you very much for the explanation in plain english...at the present time it's the only language i can understand...C is still too obscure!!! :)

#16 monjardin

    Senior Member

  • Members
  • PipPipPipPip
  • 1033 posts

Posted 07 September 2007 - 03:54 PM

irrKlang just reached version 1.0. It's from the creator of the Irrlicht engine. Perhaps it's easier to use than OpenAL...
monjardin's JwN Meter (1,2,3,4,5,6):
|----|----|----|----|----|----|----|----|----|----|
*

#17 stranomavero

    Member

  • Members
  • PipPip
  • 35 posts

Posted 10 September 2007 - 10:57 AM

thank you very much!
i'm gonna try that engine right now.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users