// SONARBackEnd.cpp : Defines the entry point for the console application. // //#include "opencv2/core/core.hpp" //#include "opencv2/highgui/highgui.hpp" //#include "opencv2/imgproc/imgproc.hpp" #include #include #include #include #include #include #include "AL/al.h" #include "AL/alc.h" #include "math.h" using namespace rs; using namespace std; #define verticalsources 16 //#define AspectRatio 0.75 //#define fovDeg 58.5 #define PI 3.1415926535 #define CASE_RETURN(err) case (err): return "##err" int xSize = 320; int ySize = 240; //User parameters for audio stuff float freq = 200.f; int horizontal_steps = 20; float freqInc = 1.15f; int stepDelay = 35; const char* al_err_str(ALenum err) { switch (err) { CASE_RETURN(AL_NO_ERROR); CASE_RETURN(AL_INVALID_NAME); CASE_RETURN(AL_INVALID_ENUM); CASE_RETURN(AL_INVALID_VALUE); CASE_RETURN(AL_INVALID_OPERATION); CASE_RETURN(AL_OUT_OF_MEMORY); } return "unknown"; } #undef CASE_RETURN #define __al_check_error(file,line) \ do { \ ALenum err = alGetError(); \ for(; err!=AL_NO_ERROR; err=alGetError()) { \ std::cerr << "AL Error " << al_err_str(err) << " at " << file << ":" << line << std::endl; \ } \ }while(0) #define al_check_error() \ __al_check_error(__FILE__, __LINE__) void init_al() { ALCdevice *dev = NULL; ALCcontext *ctx = NULL; const char *defname = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER); std::cout << "Default device: " << defname << std::endl; dev = alcOpenDevice(defname); ctx = alcCreateContext(dev, NULL); alcMakeContextCurrent(ctx); } void exit_al() { ALCdevice *dev = NULL; ALCcontext *ctx = NULL; ctx = alcGetCurrentContext(); dev = alcGetContextsDevice(ctx); alcMakeContextCurrent(NULL); alcDestroyContext(ctx); alcCloseDevice(dev); } void readUserParamFile() { ifstream readFile; readFile.open("UserParameters.txt"); /*if(!readFile.good()){ while(!readFile.good()){ char buff[100]; std::string current_working_dir(buff); cout << "loc is: " << current_working_dir << endl; cout << "Enter file location" << endl; string loc; cin >> loc; readFile.open(loc); } }*/ if (readFile.good()) { readFile >> freq; readFile >> freqInc; readFile >> horizontal_steps; readFile >> stepDelay; } printf("freq is %3.2f, freq increment is %2.2f\n horizontal steps is %d, step delay is %d ms\n", freq, freqInc, horizontal_steps, stepDelay); readFile.close(); } int const INPUT_WIDTH = 320; int const INPUT_HEIGHT = 240; int const FRAMERATE = 0; context _rs_ctx; device& _rs_camera = *_rs_ctx.get_device( 0 ); intrinsics _depth_intrin; intrinsics _color_intrin; bool _loop = true; // Initialize the application state. Upon success will return the static app_state vars address bool initialize_streaming( ) { bool success = false; if( _rs_ctx.get_device_count( ) > 0 ) { //_rs_camera.enable_stream( rs::stream::color, INPUT_WIDTH, INPUT_HEIGHT, rs::format::rgb8, FRAMERATE ); _rs_camera.enable_stream( rs::stream::depth, INPUT_WIDTH, INPUT_HEIGHT, rs::format::z16, FRAMERATE ); _rs_camera.start( ); success = true; } return success; } int main() { readUserParamFile(); //OpenAL stuff---------------------------------- unsigned short pointdist; float pointdistnorm; float angle; float zdist; float xdist; init_al(); ALuint buf[verticalsources]; alGenBuffers(verticalsources, buf); al_check_error(); /* Fill buffer with Sine-Wave */ float seconds = 1; float amplitude = 0.1f; float rolloff = 0.77f; unsigned sample_rate = 22050; size_t buf_size = seconds * sample_rate; short *samples; samples = new short[buf_size]; //Set up the frequencied buffers for (int q = 0; q < verticalsources; q++){ for (int i = 0; i