Jump to content


import a noise map and reproduce sound at set dB levels


2 replies to this topic

#1 stranomavero

    Member

  • Members
  • PipPip
  • 35 posts

Posted 05 December 2007 - 12:17 PM

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 stranomavero

    Member

  • Members
  • PipPip
  • 35 posts

Posted 11 December 2007 - 04:12 PM

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?

#3 stranomavero

    Member

  • Members
  • PipPip
  • 35 posts

Posted 12 December 2007 - 12:32 PM

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";

   

   

//read the noisemap txt file


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;    

    

    

}







1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users