SoundDevice::DynamicCaps CWaveDevice::GetDeviceDynamicCaps(const std::vector<uint32> & /*baseSampleRates*/ ) //-------------------------------------------------------------------------------------------------------- { MPT_TRACE(); SoundDevice::DynamicCaps caps; WAVEOUTCAPSW woc; MemsetZero(woc); if(GetDeviceIndex() > 0) { if(waveOutGetDevCapsW(GetDeviceIndex() - 1, &woc, sizeof(woc)) == MMSYSERR_NOERROR) { if(woc.dwFormats & (WAVE_FORMAT_96M08 | WAVE_FORMAT_96M16 | WAVE_FORMAT_96S08 | WAVE_FORMAT_96S16)) { caps.supportedExclusiveSampleRates.push_back(96000); } if(woc.dwFormats & (WAVE_FORMAT_48M08 | WAVE_FORMAT_48M16 | WAVE_FORMAT_48S08 | WAVE_FORMAT_48S16)) { caps.supportedExclusiveSampleRates.push_back(48000); } if(woc.dwFormats & (WAVE_FORMAT_4M08 | WAVE_FORMAT_4M16 | WAVE_FORMAT_4S08 | WAVE_FORMAT_4S16)) { caps.supportedExclusiveSampleRates.push_back(44100); } if(woc.dwFormats & (WAVE_FORMAT_2M08 | WAVE_FORMAT_2M16 | WAVE_FORMAT_2S08 | WAVE_FORMAT_2S16)) { caps.supportedExclusiveSampleRates.push_back(22050); } if(woc.dwFormats & (WAVE_FORMAT_1M08 | WAVE_FORMAT_1M16 | WAVE_FORMAT_1S08 | WAVE_FORMAT_1S16)) { caps.supportedExclusiveSampleRates.push_back(11025); } } } return caps; }
//Draw loop always pulls the newest completed frame (optionally: and only performs CV operations when the frame is new). //Update thread converts and stores latest camera data into frame (slow). Only when this conversion is done should // the draw loop grab the data. void PS3EyeCapture::Update(){ //TODO: This gets called twice per frame, once per camera object. //We need to make sure this only gets called once across all Update calls this frame. if(!useThreadedUpdate) PS3EyeDriver::GetInstance().Update(); //Each frame assume the frame isn't ready //frameIsReady = false; //printf("Update status: %i\n", res); //If the camera has new data, grab the data and convert it if(PS3EyeDriver::GetInstance().HasNewFrame(GetDeviceIndex())){ //&& frameIsReady == false here //(Mutex lock kind of) //printf("New frame\n"); //Pull latest converted frame from PS3EyeDriver //Store raw data into buffer PS3EyeDriver::GetInstance().ConvertRawData(GetDeviceIndex(), rawData); //rawData = PS3EyeDriver::GetInstance().GetRawFrame(GetDeviceIndex()); //cv::Mat* frame(GetFrameWidth(), GetFrameHeight(), CV_8U, rawData); // does not copy //frame = cv::Mat(GetFrameWidth(), GetFrameHeight(), CV_8UC3, rawData); frame.data = rawData; //Swap the buffers frameIsReady = true; } }
SoundDevice::Caps CWaveDevice::InternalGetDeviceCaps() //-------------------------------------------------- { MPT_TRACE(); SoundDevice::Caps caps; caps.Available = true; caps.CanUpdateInterval = true; caps.CanSampleFormat = true; caps.CanExclusiveMode = (GetDeviceIndex() > 0); // no direct mode for WAVE_MAPPER, makes no sense there caps.CanBoostThreadPriority = true; caps.CanKeepDeviceRunning = false; caps.CanUseHardwareTiming = false; caps.CanChannelMapping = false; caps.CanInput = false; caps.HasNamedInputSources = false; caps.CanDriverPanel = false; caps.HasInternalDither = false; caps.ExclusiveModeDescription = MPT_USTRING("Use direct mode"); if(GetSysInfo().IsWine) { caps.DefaultSettings.sampleFormat = SampleFormatInt16; } else if(GetSysInfo().WindowsVersion.IsAtLeast(mpt::Windows::Version::WinVista)) { caps.DefaultSettings.sampleFormat = SampleFormatFloat32; } else { caps.DefaultSettings.sampleFormat = SampleFormatInt16; } return caps; }
unsigned char tNDP2kVirtualDeviceInfoParam::GetDeviceInstance() { tN2KDeviceInfo DeviceInfo; tProductInfo ProductInfo; m_GetVirtualDeviceInfoFn(GetDeviceIndex(), &DeviceInfo, &ProductInfo); return static_cast<unsigned char>((DeviceInfo.name.parts.upperInst << 3) | DeviceInfo.name.parts.lowerInst); }
unsigned short tNDP2kVirtualDeviceInfoParam::GetSerialNumber() { tN2KDeviceInfo DeviceInfo; tProductInfo ProductInfo; m_GetVirtualDeviceInfoFn(GetDeviceIndex(), &DeviceInfo, &ProductInfo); return static_cast<unsigned short>(DeviceInfo.name.parts.idNumber & 0x7FFF); }
unsigned short tNDP2kVirtualDeviceInfoParam::GetProductId() { tN2KDeviceInfo DeviceInfo; tProductInfo ProductInfo; m_GetVirtualDeviceInfoFn(GetDeviceIndex(), &DeviceInfo, &ProductInfo); return ProductInfo.nmeaProductCode; }
unsigned char tNDP2kVirtualDeviceInfoParam::GetSysInstance() { tN2KDeviceInfo DeviceInfo; tProductInfo ProductInfo; m_GetVirtualDeviceInfoFn(GetDeviceIndex(), &DeviceInfo, &ProductInfo); return DeviceInfo.name.parts.sysInst; }
void CCudaDeviceProperties::Init() { const int nDeviceIndex = GetDeviceIndex(); int nDevicesCount; cudaCheckError(cudaGetDeviceCount(&nDevicesCount)); if (nDeviceIndex < nDevicesCount) { cudaCheckError(cudaGetDeviceProperties(&m_dpProperties, nDeviceIndex)); } else { cout << "Incorrect device index " << nDeviceIndex << ". Proper index in range 0 .. " << nDevicesCount << endl; } }
int CCameraOpencv::Start() { int nRet = 0; if(m_videoCapture.isOpened()) Stop(); if(!m_videoCapture.open(this->GetDeviceIndex())) { LOG_MODEL_DEBUG("CCameraOpencv", "don't open video deivce:%d", GetDeviceIndex()); return -1; } m_nFrameWidth = m_videoCapture.get(CV_CAP_PROP_FRAME_WIDTH); m_nFrameHeight = m_videoCapture.get(CV_CAP_PROP_FRAME_WIDTH); //m_nFrameWidth = m_videoCapture.get(cv::CAP_PROP_FRAME_WIDTH); //m_nFrameHeight = m_videoCapture.get(cv::CAP_PROP_FRAME_WIDTH); m_Timer.start(m_tmCapture); return nRet; }
BOOL CDriverInterface::Initialize( EOPEN_BY a_eTypeOpenBy, PVOID a_pvOpenBy ) { BOOL bResult = FALSE; FT_STATUS ftStatus = FT_OK; int iDeviceNumber = 0; int iNumTries = 0; DWORD dwNumDevices = 0; DWORD dwDeviceIndex = 0; FT_DEVICE_LIST_INFO_NODE *ptDevicesInfo = NULL; std::string strOpenBy((CHAR*)a_pvOpenBy); std::wstring wstrOpenBy(strOpenBy.begin(), strOpenBy.end()); dwNumDevices = GetNumberOfDevicesConnected(); if (dwNumDevices == 0) { //GUI_LOG(_T("No device is connected!")); return FALSE; } if (GetDevicesInfoList(&ptDevicesInfo) == 0) { //GUI_LOG(_T("No device is connected!")); return FALSE; } //GUI_LOG(_T("\nList of Connected Devices!\n")); for (DWORD i = 0; i < dwNumDevices; i++) { std::string strSerialNumber(ptDevicesInfo[i].SerialNumber); std::wstring wstrSerialNumber(strSerialNumber.begin(), strSerialNumber.end()); std::string strDescription(ptDevicesInfo[i].Description); std::wstring wstrDescription(strDescription.begin(), strDescription.end()); /*GUI_LOG(_T("Device[%d]"), i); GUI_LOG(_T("\tFlags: 0x%x %s | Type: %d %s | ID: 0x%08X | ftHandle: 0x%x %s"), ptDevicesInfo[i].Flags, ptDevicesInfo[i].Flags & FT_FLAGS_SUPERSPEED ? _T("[USB 3]") : ptDevicesInfo[i].Flags & FT_FLAGS_HISPEED ? _T("[USB 2]") : ptDevicesInfo[i].Flags & FT_FLAGS_OPENED ? _T("[OPENED]") : _T(""), ptDevicesInfo[i].Type, ptDevicesInfo[i].Type == FT_DEVICE_600 || ptDevicesInfo[i].Type == FT_DEVICE_601 ? _T("[FT60X]") : _T(""), ptDevicesInfo[i].ID, ptDevicesInfo[i].ftHandle, ptDevicesInfo[i].ftHandle ? _T("[Already open]") : _T("") ); GUI_LOG(_T("\tDescription: %s"), wstrDescription.c_str()); GUI_LOG(_T("\tSerialNumber: %s"), wstrSerialNumber.c_str());*/ } //GUI_LOG(_T("")); dwDeviceIndex = GetDeviceIndex(ptDevicesInfo, dwNumDevices, a_eTypeOpenBy, a_pvOpenBy); if (dwDeviceIndex == 0xFFFFFFFF) { /*GUI_LOG(_T("Device with %s [%s] not found!"), a_eTypeOpenBy == EOPEN_BY_DESC ? _T("Description") : a_eTypeOpenBy == EOPEN_BY_SERIAL ? _T("Serial Number"): a_eTypeOpenBy == EOPEN_BY_INDEX ? _T("Index") : _T(""), wstrOpenBy.c_str());*/ ReleaseDevicesInfoList(ptDevicesInfo); return FALSE; } ReleaseDevicesInfoList(ptDevicesInfo); //CMD_LOG(_T("FT_Open")); m_FTHandle = NULL; do { switch (a_eTypeOpenBy) { case EOPEN_BY_GUID: { ftStatus = FT_Create(a_pvOpenBy, FT_OPEN_BY_GUID, &m_FTHandle); break; } case EOPEN_BY_DESC: { ftStatus = FT_Create(a_pvOpenBy, FT_OPEN_BY_DESCRIPTION, &m_FTHandle); break; } case EOPEN_BY_SERIAL: { ftStatus = FT_Create(a_pvOpenBy, FT_OPEN_BY_SERIAL_NUMBER, &m_FTHandle); break; } case EOPEN_BY_INDEX: { ULONG ulIndex = atoi((CHAR*)a_pvOpenBy); ftStatus = FT_Create((PVOID)ulIndex, FT_OPEN_BY_INDEX, &m_FTHandle); break; } } if (FT_FAILED(ftStatus)) { //CMD_LOG(_T("\t%s FAILED! FT_Open"), _T(__FUNCTION__)); Sleep(1000); continue; } // Get device VID and PID // to verify if this is FT60X USHORT uwVID = 0; USHORT uwPID = 0; ftStatus = FT_GetVIDPID(m_FTHandle, &uwVID, &uwPID); if (FT_FAILED(ftStatus)) { //CMD_LOG(_T("\t%s FAILED! FT_GetVIDPID"), _T(__FUNCTION__)); break; } if ((uwVID != FT600_VID) || (uwPID != FT600_PID && uwPID != FT601_PID) ) { //CMD_LOG(_T("\t%s FAILED! FT_GetVIDPID VID=0x%04x PID=0x%04x"), _T(__FUNCTION__), uwVID, uwPID); Cleanup(); break; } break; } while (iNumTries++ < 1); //while (iNumTries++ < 3); if (ftStatus != FT_OK || m_FTHandle == NULL) { if (ftStatus == FT_DEVICE_NOT_FOUND) { //GUI_LOG(_T("Device not connected or driver not installed!")); } else { //GUI_LOG(_T("Failed looking for device, FT_STATUS 0x%x!"), ftStatus); } Cleanup(); return FALSE; } /*GUI_LOG(_T("Device with %s [%s] opened! Device[%d]!"), a_eTypeOpenBy == EOPEN_BY_DESC ? _T("Description") : a_eTypeOpenBy == EOPEN_BY_SERIAL ? _T("Serial Number") : a_eTypeOpenBy == EOPEN_BY_INDEX ? _T("Index") : _T(""), wstrOpenBy.c_str(), dwDeviceIndex);*/ return TRUE; }
bool CWaveDevice::InternalOpen() //------------------------------ { MPT_TRACE(); if(m_Settings.InputChannels > 0) { return false; } WAVEFORMATEXTENSIBLE wfext; if(!FillWaveFormatExtensible(wfext, m_Settings)) { return false; } WAVEFORMATEX *pwfx = &wfext.Format; UINT nWaveDev = GetDeviceIndex(); nWaveDev = (nWaveDev > 0) ? nWaveDev - 1 : WAVE_MAPPER; m_ThreadWakeupEvent = CreateEvent(NULL, FALSE, FALSE, NULL); if(m_ThreadWakeupEvent == INVALID_HANDLE_VALUE) { InternalClose(); return false; } m_Failed = false; m_DriverBugs = 0; m_hWaveOut = NULL; if(waveOutOpen(&m_hWaveOut, nWaveDev, pwfx, (DWORD_PTR)WaveOutCallBack, (DWORD_PTR)this, CALLBACK_FUNCTION | (m_Settings.ExclusiveMode ? WAVE_FORMAT_DIRECT : 0)) != MMSYSERR_NOERROR) { InternalClose(); return false; } if(waveOutPause(m_hWaveOut) != MMSYSERR_NOERROR) { InternalClose(); return false; } m_nWaveBufferSize = Util::Round<int32>(m_Settings.UpdateInterval * pwfx->nAvgBytesPerSec); m_nWaveBufferSize = Util::AlignUp<uint32>(m_nWaveBufferSize, pwfx->nBlockAlign); m_nWaveBufferSize = mpt::clamp(m_nWaveBufferSize, static_cast<uint32>(WAVEOUT_MINBUFFERFRAMECOUNT * pwfx->nBlockAlign), static_cast<uint32>(Util::AlignDown<uint32>(WAVEOUT_MAXBUFFERSIZE, pwfx->nBlockAlign))); std::size_t numBuffers = Util::Round<int32>(m_Settings.Latency * pwfx->nAvgBytesPerSec / m_nWaveBufferSize); numBuffers = mpt::clamp(numBuffers, WAVEOUT_MINBUFFERS, WAVEOUT_MAXBUFFERS); m_nPreparedHeaders = 0; m_WaveBuffers.resize(numBuffers); m_WaveBuffersData.resize(numBuffers); for(std::size_t buf = 0; buf < numBuffers; ++buf) { MemsetZero(m_WaveBuffers[buf]); m_WaveBuffersData[buf].resize(m_nWaveBufferSize); m_WaveBuffers[buf].dwFlags = 0; m_WaveBuffers[buf].lpData = &m_WaveBuffersData[buf][0]; m_WaveBuffers[buf].dwBufferLength = m_nWaveBufferSize; if(waveOutPrepareHeader(m_hWaveOut, &m_WaveBuffers[buf], sizeof(WAVEHDR)) != MMSYSERR_NOERROR) { break; } m_WaveBuffers[buf].dwFlags |= WHDR_DONE; m_nPreparedHeaders++; } if(!m_nPreparedHeaders) { InternalClose(); return false; } m_nBuffersPending = 0; m_nWriteBuffer = 0; m_nDoneBuffer = 0; { MPT_LOCK_GUARD<mpt::mutex> guard(m_PositionWraparoundMutex); MemsetZero(m_PositionLast); m_PositionWrappedCount = 0; } SetWakeupEvent(m_ThreadWakeupEvent); SetWakeupInterval(m_nWaveBufferSize * 1.0 / m_Settings.GetBytesPerSecond()); m_Flags.NeedsClippedFloat = GetSysInfo().WindowsVersion.IsAtLeast(mpt::Windows::Version::WinVista); return true; }