void audioInit() { g_AudioData.hWaveOut = NULL; g_AudioData.bFlush = false; g_AudioData.nFirstToCheck = -1; g_AudioData.SyncDump = XN_DUMP_CLOSED; // check if device audio is enabled const AudioMetaData* pAudioMD = getAudioMetaData(); if (pAudioMD == NULL) return; // start audio out device WAVEFORMATEX wf; wf.wFormatTag = 0x0001; // PCM wf.nChannels = pAudioMD->NumberOfChannels(); wf.nSamplesPerSec = pAudioMD->SampleRate(); wf.wBitsPerSample = pAudioMD->BitsPerSample(); wf.nBlockAlign = wf.wBitsPerSample * wf.nChannels / 8; wf.nAvgBytesPerSec = wf.nBlockAlign * wf.nSamplesPerSec; MMRESULT mmRes = waveOutOpen(&g_AudioData.hWaveOut, WAVE_MAPPER, &wf, (DWORD_PTR)audioCallback, NULL, CALLBACK_FUNCTION); if (mmRes != MMSYSERR_NOERROR) { printf("Warning: Failed opening wave out device. Audio will not be played!\n"); g_AudioData.hWaveOut = NULL; return; } // create some wave headers for playing g_AudioData.pAudioBuffers = new WAVEHDR[NUMBER_OF_AUDIO_BUFFERS]; g_AudioData.pAudioTimestamps = new XnUInt64[NUMBER_OF_AUDIO_BUFFERS]; xnOSMemSet(g_AudioData.pAudioBuffers, 0, sizeof(WAVEHDR)*NUMBER_OF_AUDIO_BUFFERS); // allocate max buffer for one second g_AudioData.nBufferSize = wf.nAvgBytesPerSec; for (int i = 0; i < NUMBER_OF_AUDIO_BUFFERS; ++i) { g_AudioData.pAudioBuffers[i].lpData = new XnChar[g_AudioData.nBufferSize]; g_AudioData.pAudioBuffers[i].dwUser = i; g_AudioData.pAudioBuffers[i].dwFlags = WHDR_DONE; // mark this buffer as empty (already played) } g_AudioData.nAudioNextBuffer = 0; xnDumpInit(&g_AudioData.SyncDump, AUDIO_SYNC_DUMP_MASK, "", "%s.txt", AUDIO_SYNC_DUMP_MASK); }
void drawPointerMode(IntPair* pPointer) { char buf[512] = ""; int nCharWidth = glutBitmapWidth(GLUT_BITMAP_HELVETICA_18, '0'); int nPointerValue = 0; XnDouble dTimestampDivider = 1E6; const DepthMetaData* pDepthMD = getDepthMetaData(); if (pDepthMD != NULL) { // Print the scale black background glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBegin(GL_QUADS); glColor4f(0, 0, 0, 0.7); glVertex2i(0, WIN_SIZE_Y); // lower left glVertex2i(WIN_SIZE_X, WIN_SIZE_Y); glVertex2i(WIN_SIZE_X, WIN_SIZE_Y - 135); glVertex2i(0, WIN_SIZE_Y - 135); glEnd(); glDisable(GL_BLEND); // set a large point size (for the scale) glPointSize(15); // Print the scale data glBegin(GL_POINTS); for (int i = 0; i < pDepthMD->ZRes(); i+=1) { float fNewColor = g_pDepthHist[i]; if ((fNewColor > 0.004) && (fNewColor < 0.996)) { glColor3f(fNewColor, fNewColor, 0); glVertex3f(((i/10)*2), WIN_SIZE_Y - 23, 1); } } glEnd(); // Print the pointer scale data if (pPointer != NULL) { // make sure pointer in on a depth pixel (take in mind cropping might be in place) IntPair pointerInDepth = *pPointer; pointerInDepth.X -= pDepthMD->XOffset(); pointerInDepth.Y -= pDepthMD->YOffset(); if (pointerInDepth.X < (int)pDepthMD->XRes() && pointerInDepth.Y < (int)pDepthMD->YRes()) { nPointerValue = (*pDepthMD)(pointerInDepth.X, pointerInDepth.Y); glBegin(GL_POINTS); glColor3f(1,0,0); glVertex3f(10 + ((nPointerValue/10)*2), WIN_SIZE_Y - 70, 1); glEnd(); } } // Print the scale texts for (int i = 0; i < pDepthMD->ZRes()/10; i+=25) { int xPos = i*2 + 10; // draw a small line in this position glBegin(GL_LINES); glColor3f(0, 1, 0); glVertex2i(xPos, WIN_SIZE_Y - 54); glVertex2i(xPos, WIN_SIZE_Y - 62); glEnd(); // place a label under, and in the middle of, that line. int chars = sprintf(buf, "%d", i); glColor3f(1,0,0); glRasterPos2i(xPos - chars*nCharWidth/2, WIN_SIZE_Y - 40); glPrintString(GLUT_BITMAP_HELVETICA_18,buf); } sprintf(buf, "%s - Frame %4u, Timestamp %.3f", getDepthGenerator()->GetInfo().GetInstanceName(), pDepthMD->FrameID(), (double)pDepthMD->Timestamp()/dTimestampDivider); } const ImageMetaData* pImageMD = getImageMetaData(); if (pImageMD != NULL) { if (buf[0] != '\0') sprintf(buf + strlen(buf), " | "); sprintf(buf + strlen(buf), "%s - Frame %4u, Timestamp %.3f", getImageGenerator()->GetInfo().GetInstanceName(), pImageMD->FrameID(), (double)pImageMD->Timestamp()/dTimestampDivider); } const IRMetaData* pIRMD = getIRMetaData(); if (pIRMD != NULL) { if (buf[0] != '\0') sprintf(buf + strlen(buf), " | "); sprintf(buf + strlen(buf), "%s - Frame %4u, Timestamp %.3f", getIRGenerator()->GetInfo().GetInstanceName(), pIRMD->FrameID(), (double)pIRMD->Timestamp()/dTimestampDivider); } const AudioMetaData* pAudioMD = getAudioMetaData(); if (pAudioMD != NULL) { if (buf[0] != '\0') sprintf(buf + strlen(buf), " | "); sprintf(buf + strlen(buf), "%s - Timestamp %.3f", getAudioGenerator()->GetInfo().GetInstanceName(), (double)pAudioMD->Timestamp()/dTimestampDivider); } int nYLocation = WIN_SIZE_Y - 88; glColor3f(1,0,0); glRasterPos2i(10,nYLocation); glPrintString(GLUT_BITMAP_HELVETICA_18, buf); nYLocation -= 26; if (pPointer != NULL && isStatisticsActive()) { XnPixelStatistics* pStatistics = &g_PixelStatistics[pPointer->Y * pDepthMD->XRes() + pPointer->X]; sprintf(buf, "Collected: %3u, Min: %4u Max: %4u Avg: %6.2f StdDev: %6.2f", pStatistics->nCount, pStatistics->nMin, pStatistics->nMax, pStatistics->dAverage, pStatistics->dStdDev); glRasterPos2i(10,nYLocation); glPrintString(GLUT_BITMAP_HELVETICA_18, buf); nYLocation -= 26; } if (pPointer != NULL) { // Print the pointer text XnUInt64 nCutOffMin = 0; XnUInt64 nCutOffMax = (pDepthMD != NULL) ? g_nMaxDepth : 0; XnChar sPointerValue[100]; if (nPointerValue != g_nMaxDepth) { sprintf(sPointerValue, "%.1f", (float)nPointerValue/10); } else { sprintf(sPointerValue, "-"); } sprintf(buf, "Pointer Value: %s (X:%d Y:%d) Cutoff: %llu-%llu.", sPointerValue, pPointer->X, pPointer->Y, nCutOffMin, nCutOffMax); glRasterPos2i(10,nYLocation); glPrintString(GLUT_BITMAP_HELVETICA_18, buf); nYLocation -= 26; } }
QVariant DirModel::data(const QModelIndex &index, int role) const { //its not for QML #if defined(REGRESSION_TEST_FOLDERLISTMODEL) if (!index.isValid() || (role != Qt::DisplayRole && role != Qt::DecorationRole && role != Qt::BackgroundRole) ) { return QVariant(); } if (role == Qt::DecorationRole && index.column() == 0) { QIcon icon; QMimeType mime = mDirectoryContents.at(index.row()).mimeType(); if (mime.isValid()) { if (QIcon::hasThemeIcon(mime.iconName()) ) { icon = QIcon::fromTheme(mime.iconName()); } else if (QIcon::hasThemeIcon(mime.genericIconName())) { icon = QIcon::fromTheme(mime.genericIconName()); } } if (icon.isNull()) { if (mDirectoryContents.at(index.row()).isLocal()) { icon = QFileIconProvider().icon(mDirectoryContents.at(index.row()).diskFileInfo()); } else if (mDirectoryContents.at(index.row()).isDir()) { icon = QFileIconProvider().icon(QFileIconProvider::Folder); } else { icon = QFileIconProvider().icon(QFileIconProvider::File); } } return icon; } if (role == Qt::BackgroundRole && index.column() == 0) { if (mDirectoryContents.at(index.row()).isSelected()) { //TODO it'd better to get some style or other default // background color return QBrush(Qt::lightGray); } return QVariant(); } role = FileNameRole + index.column(); #else if (role < FileNameRole || role > TrackCoverRole) { qWarning() << Q_FUNC_INFO << this << "Got an out of range role: " << role; return QVariant(); } if (index.row() < 0 || index.row() >= mDirectoryContents.count()) { qWarning() << "Attempted to access out of range row: " << index.row(); return QVariant(); } if (index.column() != 0) return QVariant(); #endif const DirItemInfo &fi = mDirectoryContents.at(index.row()); switch (role) { case FileNameRole: return fi.fileName(); case AccessedDateRole: return fi.lastRead(); case CreationDateRole: return fi.created(); case ModifiedDateRole: return fi.lastModified(); case FileSizeRole: { if (fi.isDir() && fi.isLocal()) { return dirItems(fi.diskFileInfo()); } return fileSize(fi.size()); } case IconSourceRole: { const QString &fileName = fi.fileName(); if (fi.isDir()) return QLatin1String("image://theme/icon-m-common-directory"); if (fileName.endsWith(QLatin1String(".jpg"), Qt::CaseInsensitive) || fileName.endsWith(QLatin1String(".png"), Qt::CaseInsensitive)) { return QLatin1String("image://nemoThumbnail/") + fi.filePath(); } return "image://theme/icon-m-content-document"; } case FilePathRole: return fi.filePath(); case MimeTypeRole: return fi.mimeType().name(); case MimeTypeDescriptionRole: return fi.mimeType().comment(); case IsDirRole: return fi.isDir(); case IsFileRole: return !fi.isDir(); case IsReadableRole: return fi.isReadable(); case IsWritableRole: return fi.isWritable(); case IsExecutableRole: return fi.isExecutable(); case IsSelectedRole: return fi.isSelected(); #ifndef DO_NOT_USE_TAG_LIB case TrackTitleRole: case TrackArtistRole: case TrackAlbumRole: case TrackYearRole: case TrackNumberRole: case TrackGenreRole: case TrackLengthRole: case TrackCoverRole: if (mReadsMediaMetadata && fi.isLocal()) { return getAudioMetaData(fi.diskFileInfo(), role); } break; #endif default: #if !defined(REGRESSION_TEST_FOLDERLISTMODEL) // this should not happen, ever Q_ASSERT(false); qWarning() << Q_FUNC_INFO << this << "Got an unknown role: " << role; #endif break; } return QVariant(); }
// -------------------------------- // Code // -------------------------------- void audioPlay() { if (g_AudioData.hWaveOut == NULL) // not initialized return; const AudioMetaData* pAudioMD = getAudioMetaData(); if (pAudioMD == NULL || pAudioMD->DataSize() == 0 || !pAudioMD->IsDataNew()) return; if (g_AudioData.bFlush) { printf("Audio is falling behind. Flushing all queue.\n"); xnDumpFileWriteString(g_AudioData.SyncDump, "Flushing queue...\n"); // mark not to check all dropped headers g_AudioData.nFirstToCheck = g_AudioData.nAudioNextBuffer; // flush all queued headers waveOutReset(g_AudioData.hWaveOut); g_AudioData.bFlush = false; return; } int nBufferSize = pAudioMD->DataSize(); WAVEHDR* pHeader = &g_AudioData.pAudioBuffers[g_AudioData.nAudioNextBuffer]; if ((pHeader->dwFlags & WHDR_DONE) == 0) { printf("No audio buffer is available!. Audio buffer will be lost!\n"); return; } // first unprepare this header MMRESULT mmRes = waveOutUnprepareHeader(g_AudioData.hWaveOut, pHeader, sizeof(WAVEHDR)); if (mmRes != MMSYSERR_NOERROR) { CHAR msg[250]; waveOutGetErrorText(mmRes, msg, 250); printf("Failed unpreparing header: %s\n", msg); } int nMaxPlayedAudio = (int)(pAudioMD->SampleRate() / 1000.0 * pAudioMD->NumberOfChannels() * 2 * AUDIO_LATENCY_THRESHOLD); if (nBufferSize > nMaxPlayedAudio) { printf("Dropping %d bytes of audio to keep synch.\n", nBufferSize - nMaxPlayedAudio); nBufferSize = nMaxPlayedAudio; } const XnUInt8* pData = pAudioMD->Data(); if (nBufferSize > g_AudioData.nBufferSize) { printf("Dropping %d bytes of audio to match buffer size.\n", nBufferSize - g_AudioData.nBufferSize); pData += (nBufferSize - g_AudioData.nBufferSize); nBufferSize = g_AudioData.nBufferSize; } pHeader->dwFlags = 0; xnOSMemCopy(pHeader->lpData, pData, nBufferSize); pHeader->dwBufferLength = nBufferSize; // prepare header mmRes = waveOutPrepareHeader(g_AudioData.hWaveOut, pHeader, sizeof(WAVEHDR)); if (mmRes != MMSYSERR_NOERROR) { CHAR msg[250]; waveOutGetErrorText(mmRes, msg, 250); printf("Unable to prepare header: %s\n", msg); return; } // queue header mmRes = waveOutWrite(g_AudioData.hWaveOut, pHeader, sizeof(WAVEHDR)); if (mmRes != MMSYSERR_NOERROR) { CHAR msg[250]; waveOutGetErrorText(mmRes, msg, 250); printf("Unable to queue header: %s\n", msg); return; } // place end-time as a timestamp g_AudioData.pAudioTimestamps[g_AudioData.nAudioNextBuffer] = (XnUInt64)(pAudioMD->Timestamp() + nBufferSize / (pAudioMD->BitsPerSample() / 8.0) / pAudioMD->NumberOfChannels() / (pAudioMD->SampleRate() / 1e6)); xnDumpFileWriteString(g_AudioData.SyncDump, "Queued index %d with timestamp %llu (%u bytes, %f ms, end timestamp: %llu)\n", g_AudioData.nAudioNextBuffer, pAudioMD->Timestamp(), nBufferSize, nBufferSize / 2.0 / pAudioMD->NumberOfChannels() / (pAudioMD->SampleRate() / 1e3), g_AudioData.pAudioTimestamps[g_AudioData.nAudioNextBuffer]); g_AudioData.nAudioNextBuffer = (g_AudioData.nAudioNextBuffer + 1) % NUMBER_OF_AUDIO_BUFFERS; }