void StereoRecorder::Record(const gmtl::Vec3f& dir, float a, float t, float dist, int band, int kf) { const float dot = gmtl::dot(dir,getRightEar(kf)); const float time_difference = head_size / 343.0f; const int s_right = (int) ((t-(dot*time_difference))*44100.0); const int s_left = (int) ((t+(dot*time_difference))*44100.0); const float width = sqrt(dist); const float ampl = 2.0f * a / width; float ampl_left = ampl; float ampl_right = ampl; const float intensity_difference = fabs(dot); // Interaural intensity differences are higher for the high frequency bands const float factor = powf(head_absorption[band],intensity_difference*head_size); if ( dot < 0 ) { ampl_right *= factor*factor; } else { ampl_left *= factor*factor; } const int w = (int) ceil(width); const float step_left = ampl_left / w; const float step_right = ampl_right / w; for ( int i = 0; i < w; ++ i ) { _Sample(i+s_left,ampl_left,0); ampl_left -= step_left; _Sample(i+s_right,ampl_right,1); ampl_right -= step_right; } }
void MonoRecorder::Record(const gmtl::Vec3f& dir, float a, float t, float dist, int band, int kf) { const int s = (int) (t*44100.0); #ifdef USE_FILTER const float width = sqrt(dist); float ampl = 2.0f * a / width; const int w = (int) ceil(width); const float step = ampl / w; for ( int i = 0; i < w; ++ i ) { _Sample(i+s,ampl); ampl -= step; } #else _Sample(s,a); #endif }
int KG3DProfile_Manager_Imp::_ThreadFunction() { int nResult = false; int nRetCode = false; DWORD dwSampleTime = 0; int nSleepTime = 0; DWORD dwBegigTime = 0; FILE *fpOutput = NULL; char szLogFileName[PATH_MAX]; time_t tmtNow = 0; struct tm tmNow; RECORDER_MAP::iterator it; size_t uColumnCount = 0; nSleepTime = 4000; // wait some time to skip engine init while (nSleepTime > 0) { KG_PROCESS_SUCCESS(m_nExitFlag); ::Sleep(100); nSleepTime -= 100; } tmtNow = time(NULL); localtime_r(&tmtNow, &tmNow); nRetCode = snprintf( szLogFileName, sizeof(szLogFileName) - 1, "Profile\\KG3DEngineProfile_%d%2.2d%2.2d_%2.2d%2.2d%2.2d.csv", tmNow.tm_year + 1900, tmNow.tm_mon + 1, tmNow.tm_mday, tmNow.tm_hour, tmNow.tm_min, tmNow.tm_sec ); ASSERT((nRetCode != -1) && (nRetCode < (sizeof(szLogFileName) - 1))); szLogFileName[sizeof(szLogFileName) - 1] = '\0'; mkdir("Profile"); fpOutput = fopen(szLogFileName, "w"); KGLOG_PROCESS_ERROR(fpOutput); ::QueryPerformanceCounter(&m_llFirstSampleTime); while (true) { nSleepTime = 1000 - dwSampleTime; while (nSleepTime > 0) { KG_PROCESS_SUCCESS(m_nExitFlag); ::Sleep(100); nSleepTime -= 100; } dwBegigTime = ::timeGetTime(); if (uColumnCount != m_RecorderMap.size()) { nRetCode = _OutputTitle(fpOutput); KGLOG_PROCESS_ERROR(nRetCode); uColumnCount = m_RecorderMap.size(); } if (uColumnCount) { nRetCode = _Sample(fpOutput); //KGLOG_PROCESS_ERROR(nRetCode); } dwSampleTime = ::timeGetTime() - dwBegigTime; } Exit1: nResult = true; Exit0: if (fpOutput) { fclose(fpOutput); fpOutput = NULL; } return nResult; }