0
101 Dec 05, 2007 at 12:17

Hi guys!

I have another problem related to my project.
I need my code to read a noise map (dB levels on an area, created with noise prediction software) and then play different sound samples according to the dB levels.
I have no problems in playing the sounds and mixing them with OpenAL.
I was just wondering which is the best way to export the noise map from my noise prediction software to make it easily readable by my code.

Any suggestions and hel will be more than appreciated! :)

#### 2 Replies

0
101 Dec 11, 2007 at 16:12

I kind of know how to do…but i still have some troubles in translating it into C++! :)

I think i should read the text file into a buffer and then read the buffer into an array.

After that i have to find the match for the position of the user (both x and y) into the array and then get the correspondent dB value.

any help?

0
101 Dec 12, 2007 at 12:32

hello everyone!

this is my attempt…it doesn’t give me any errors but it’s not working!
:(

what’s wrong with it??

// Set up a loop !

mindist=0;
while(mindist<100){

// Read the coordinates if the file is available

ifstream corfile("C:\\Program Files\\Metropolis\\VirtualDublin\\media\\audio\\coordinates.txt");
if(corfile) {

// leading character has to be stripped off

corfile >> leader; corfile >> x;
corfile >> leader; corfile >> y;
corfile >> leader; corfile >> theta;

corfile.close(); }

// Ok we have the position

cout << "\nPosition .. (" << x << "," << y << ")\n";
cout << "Angle ..... " << theta << " degrees \n";

float xm,ym,gm,hm,dBm;
string line;
ifstream myfile ("noisemap.txt");
if (myfile.is_open())
{
while (! myfile.eof() )
{
corfile >> leader; corfile >> xm;
corfile >> leader; corfile >> ym;
corfile >> leader; corfile >> gm;
corfile >> leader; corfile >> hm;
corfile >> leader; corfile >> dBm;
}
myfile.close();
}

else cout << "Unable to open file";

//find the match

inside=true;
mindist=1000;

for (int i=0;;i++){
xdiff=xm-x;
ydiff=ym-y;
int flag = 0;    // set flag to off
if (xdiff<5 && ydiff<5)   // if match is found
{
flag = 1;   // turn flag on
//break ;    // break out of for loop
}
if (flag)    // if flag is TRUE (1)
{
cout<< "dB(A) level= " << dBm <<".\n";
}
//switch between dB levels and play a wav file

int j;
if (dBm<60) j=1;
else if (60<=dBm<70) j=2;
else if (70<=dBm<80) j=3;
else if(dBm>=80) j=4;

switch (j){
case 1:
alSourcef(g_sources[0],AL_GAIN,0.5);
break;
case 2:
alSourcef(g_sources[0],AL_GAIN,1);
break;
case 3:
alSourcef(g_sources[1],AL_GAIN,0.5);
break;
case 4:
alSourcef(g_sources[1],AL_GAIN,1);
break;
}

if(dist<0) inside=false;
if(fabs(dist)<mindist) mindist=fabs(dist);

// cout << "Distance from road " << i << " is " << dist << "\n";

}

// waste some time a quarter of a second for the moment

Sleep(deltat);
metrotime=metrotime+deltat;

}

// Graceful exit

alutExit();

cout << "\n\nYou must be in Rathmines by now : keyhit to exit ... "; getch();
return EXIT_SUCCESS;

}