Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

132 Neutral

About eReS

  • Rank
  1. Following your hint I also found this explanation http://betterlogic.com/roger/2013/07/openal-soft-how-to-recordsave-to-a-sound-file-save-to-wav-file/, but that fails to create file that I would be able to open. How can I find a reason having no access to very data?
  2. thank you, i try implementing in that manner
  3. Hi,   using OpenAL I read .wav into buffer, connect to source and play source then changing its 3D position. I would like to save that new sound into .wav file but cannot find out how OpenAL would do it.   Alternatively I thought I should record into .wav what my headphones play because that is the sound I want, but I do not find a tutorial for that and never did that before. Audacity for example seems to record "outside world" sounds only..   I would like to record from each loop of my program sound into separate .wav.   Any suggestions appreciated!
  4. Thank you. I am following the suggested link and especially part "Distance law for field sizes (source sizes) since all I have is a size of an object.   I interpret distance (z) as -(sound level) and thus use in the formula. However I am not sure, how to use object.area() having no reference area?? Formula uses r1 and r2 as if they were distances. z = 20*log(r1/r2); since I also read sound intensity falls inversely proportional to square of distance, is that final formula proper? z = 20*log( 1 / (area^2) )
  5. I am detecting object in the image and want to play sound pointing out to direction of object.   Depending on its size sound shall be played from source far away (big z value) and depending on position of object's center (which pixel in image) soud shall be played more left or more right from listener.   How can I write efficient mapping of object size and objects center into those parameters? Below my trial which however does not work good. I tried tuning x by division by 100, and z by 1000000 factor, but sound does not reflect position. I suppose those mappings cannot be linear.. anyone maybe has experience in that? I am doing such things for first time.     // Direction (positive = left side)     float x = -(center.x - (int)cols/2) / 100;     cout << x << endl;     // Distance (positive = far away in front)     float z = 1000000 / area;
  6. Yes. I want to play a beep every 500ms with its location dependent on object. Suppose I get an image with object size and location. (small = far away, left of the image = left from listener). Beep helps me to hear where it is. Then comes next image. I was using the only tutorial I found until that time from youtube and managed the arrow keys control this way below. The part I used for arrow navigation is commented out and directly above is part which I try and cannot make it work. If you could help me out giving an example how to make it work the way I want, I would be grateful. #include <iostream> #include <fstream> #include <cstring> #include <AL/al.h> #include <AL/alc.h> #include <SDL/SDL.h> // install packages for openAL // install packages for SDL using namespace std; bool isBigEndian() {     int a=1; // bigEndian: 0000...1, littleEndian 00000000 100...000     return !((char*)&a)[0]; // Access 1st byte of char array, (1 if littleEndian) } int convertToInt(char* buffer,int len) {     int a=0;     if(!isBigEndian())         for(int i=0;i<len;i++)             ((char*)&a)[i]=buffer[i];     else         for(int i=0;i<len;i++)             ((char*)&a)[3-i]=buffer[i];     return a; } char* loadWAV(const char* fn,int& chan,int& samplerate,int& bps,int& size) {     char buffer[4];     std::ifstream in(fn,std::ios::binary);     in.read(buffer,4);     if(strncmp(buffer,"RIFF",4)!=0)     {         std::cout << "this is not a valid WAVE file"  << std::endl;         return NULL;     }     in.read(buffer,4);     in.read(buffer,4);      //WAVE     in.read(buffer,4);      //fmt     in.read(buffer,4);      //16     in.read(buffer,2);      //1     in.read(buffer,2);     chan=convertToInt(buffer,2);     in.read(buffer,4);     samplerate=convertToInt(buffer,4);     in.read(buffer,4);     in.read(buffer,2);     in.read(buffer,2);     bps=convertToInt(buffer,2);     in.read(buffer,4);      //data     in.read(buffer,4);     size=convertToInt(buffer,4);     char* data=new char[size];     in.read(data,size); // Read very data     return data; } int main(int argc,char** argv) {     int channel,sampleRate,bps,size;     char* data=loadWAV("test.wav",channel,sampleRate,bps,size);     if (!data)     {         std::cout << " no data loaded " << std::endl;         delete[] data;     }     else     {std::cout << " success loading " << std::endl; }     ALCdevice* device=alcOpenDevice(NULL);     if(device==NULL)     {         std::cout << "cannot open sound card" << std::endl;         alcCloseDevice(device);         return 0;     }     ALCcontext* context=alcCreateContext(device,NULL);     if(context==NULL)     {         std::cout << "cannot open context" << std::endl;         alcDestroyContext(context);         return 0;     }     alcMakeContextCurrent(context);     unsigned int bufferid,format;     alGenBuffers(1,&bufferid);     if(channel==1)     {         if(bps==8)         {             format=AL_FORMAT_MONO8;             std::cout << "mono 8" << std::endl;         }else{             format=AL_FORMAT_MONO16;             std::cout << "mono 16" << std::endl;         }     }else{         if(bps==8)         {             format=AL_FORMAT_STEREO8;             std::cout << "stereo 8" << std::endl;         }else{             format=AL_FORMAT_STEREO16;             std::cout << "stereo 16" << std::endl;         }     }     alBufferData(bufferid,format,data,size,sampleRate);     unsigned int sourceid;     alGenSources(1,&sourceid);     alSourcei(sourceid,AL_BUFFER,bufferid);     //alSourcePlay(sourceid);     //SDL_Delay(5000);     ALint state; // ###### HERE PART OF CODE I TRIED AND DID NOT WORK     while(true)     {         float x=1.0,z=0.0;         // Set for sourceid parameter position with x,0,z         alSource3f(sourceid,AL_POSITION,x,0,z);         // Set for sourceid parameter looping sound continuously looping         alSourcei(sourceid,AL_LOOPING,AL_TRUE);         std::cout << "x: " << x << " z: " << z << std::endl;                  alSourcePlay(sourceid);     } // ###### end    /* SDL_Init(SDL_INIT_EVERYTHING);     SDL_Surface* screen=SDL_SetVideoMode(640,480,32,SDL_SWSURFACE);     SDL_Event event;     Uint32 start;     bool running = 1;     bool b[4]={0,0,0,0};     // x: forward, z: to the right     float x=1.0,z=0.0;     while(running)     {         start=SDL_GetTicks();         while(SDL_PollEvent(&event))         {             switch(event.type)             {             case SDL_QUIT:                 running=false;                 break;             case SDL_KEYDOWN:                 switch(event.key.keysym.sym)                 {                 case SDLK_UP:                     b[0]=true;                     break;                 case SDLK_RIGHT:                     b[1]=true;                     break;                 case SDLK_DOWN:                     b[2]=true;                     break;                 case SDLK_LEFT:                     b[3]=true;                     break;                 case SDLK_SPACE:                     alSourcePlay(sourceid);                     state = 1;                     break;                 case SDLK_BACKSPACE:                     alSourceStop(sourceid);                     state = 2;                     break;                 }                 break;                 case SDL_KEYUP:                     switch(event.key.keysym.sym)                     {                     case SDLK_UP:                         b[0]=false;                         break;                     case SDLK_RIGHT:                         b[1]=false;                         break;                     case SDLK_DOWN:                         b[2]=false;                         break;                     case SDLK_LEFT:                         b[3]=false;                         break;                     }                     break;             }         }         if(b[0])             z+=0.3;         if(b[1])             x+=0.3;         if(b[2])             z-=0.3;         if(b[3])             x-=0.3;         // Set for sourceid parameter position with x,0,z         alSource3f(sourceid,AL_POSITION,x,0,z);         // Set for sourceid parameter looping sound continuously looping         alSourcei(sourceid,AL_LOOPING,AL_TRUE);         std::cout << "x: " << x << " z: " << z << std::endl;         cout << " alint state is :" << state << endl;         // Velocity for Doppler effect         float f[]={1,0,0,0,1,0}; // 6DOFs: 3 for looking direction, "upvector"         alListenerfv(AL_ORIENTATION,f); // Set orientation param of listener (no id -> only one listener)         if(1000/30.0>SDL_GetTicks()-start)             SDL_Delay(1000/30.0-(SDL_GetTicks()-start));     } */     alDeleteSources(1,&sourceid);     alDeleteBuffers(1,&bufferid);     alcDestroyContext(context);     alcCloseDevice(device);     delete[] data;     return 0; }
  7. Hello, I make myself familiar with basics of OpenAL. I want to use the library to produce sound (let it be simple beep at first) which will be dependent on the size of an object in front of the player. By dependent I mean its position and a stereo effect. The bigger the object, the closer sound should be. Depending on object position (left/center/right) sound should also "wander" from one side to the other. (either discretized into l/c/r bins, or some (non)linear function for that, I have no experience what should that be of a function for sound) Can you point me out idea how can I make that size- and position-dependent sound moving?   By now I managed to create movable sound source dependent on user pressing arrows from keyboard, sound de/activated by another key. (if wanted I can paste my code however I know it is very basics).   Will be grateful for opinion on that,  thank you. Matt
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!