void Engine::audioNotify() { switch (m_mode) { case QAudio::AudioInput: { const qint64 recordPosition = qMin(m_bufferLength, audioLength(m_format, m_audioInput->processedUSecs())); setRecordPosition(recordPosition); const qint64 levelPosition = m_dataLength - m_levelBufferLength; if (levelPosition >= 0) calculateLevel(levelPosition, m_levelBufferLength); if (m_dataLength >= m_spectrumBufferLength) { const qint64 spectrumPosition = m_dataLength - m_spectrumBufferLength; calculateSpectrum(spectrumPosition); } emit bufferChanged(0, m_dataLength, m_buffer); } break; case QAudio::AudioOutput: { const qint64 playPosition = audioLength(m_format, m_audioOutput->processedUSecs()); setPlayPosition(qMin(bufferLength(), playPosition)); const qint64 levelPosition = playPosition - m_levelBufferLength; const qint64 spectrumPosition = playPosition - m_spectrumBufferLength; if (m_file) { if (levelPosition > m_bufferPosition || spectrumPosition > m_bufferPosition || qMax(m_levelBufferLength, m_spectrumBufferLength) > m_dataLength) { m_bufferPosition = 0; m_dataLength = 0; // Data needs to be read into m_buffer in order to be analysed const qint64 readPos = qMax(qint64(0), qMin(levelPosition, spectrumPosition)); const qint64 readEnd = qMin(m_analysisFile->size(), qMax(levelPosition + m_levelBufferLength, spectrumPosition + m_spectrumBufferLength)); const qint64 readLen = readEnd - readPos + audioLength(m_format, WaveformWindowDuration); qDebug() << "Engine::audioNotify [1]" << "analysisFileSize" << m_analysisFile->size() << "readPos" << readPos << "readLen" << readLen; if (m_analysisFile->seek(readPos + m_analysisFile->headerLength())) { m_buffer.resize(readLen); m_bufferPosition = readPos; m_dataLength = m_analysisFile->read(m_buffer.data(), readLen); qDebug() << "Engine::audioNotify [2]" << "bufferPosition" << m_bufferPosition << "dataLength" << m_dataLength; } else { qDebug() << "Engine::audioNotify [2]" << "file seek error"; } emit bufferChanged(m_bufferPosition, m_dataLength, m_buffer); } } else { if (playPosition >= m_dataLength) stopPlayback(); } if (levelPosition >= 0 && levelPosition + m_levelBufferLength < m_bufferPosition + m_dataLength) calculateLevel(levelPosition, m_levelBufferLength); if (spectrumPosition >= 0 && spectrumPosition + m_spectrumBufferLength < m_bufferPosition + m_dataLength) calculateSpectrum(spectrumPosition); } break; } }
int calculateFullEntry(int mat[SIZE1][SIZE2],struct fullentry * bob) { int n1,n2; int autocor[(2*SIZE1-1)*(2*SIZE2-1)]; //int disps[SIZE1*(2*SIZE2-1)]; calculateEntry(mat,&(bob[0].intrep)); //calculate entry part of full entry calculateAutocor((autocor),mat,&(bob[0].ones)); calculateSpectrum(autocor,&(bob[0].spectrum[0]),bob[0].ones,&(bob[0].peaksidelobe),2*SIZE1-1,2*SIZE2-1); //display info for debugging if(bob[0].ones>=25) { printf("ones %d \n",bob[0].ones); printf("calculating full entry \n"); displaymatrix(mat,NULL); printf("calculating autocor \n"); displaygeneral(autocor,NULL,2*SIZE1-1,2*SIZE2-1); printf("peak sidelobe %d \n",bob[0].peaksidelobe); } /*printf("calculating displacements \n"); calculateDisplacements(mat,disps); displaygeneral(disps,NULL,SIZE1,2*SIZE2-1); printf("calculating displacement spectrum \n"); calculateSpectrum((disps),&(bob[0].dispspectrum[0]),&(bob[0].peakdisp),SIZE1,2*SIZE2-1); */ return 0; }
/// Executes the algorithm void PoldiFitPeaks2D::exec() { std::vector<PoldiPeakCollection_sptr> peakCollections = getPeakCollectionsFromInput(); // Try to setup the 2D data and poldi instrument MatrixWorkspace_sptr ws = getProperty("InputWorkspace"); setDeltaTFromWorkspace(ws); setPoldiInstrument(boost::make_shared<PoldiInstrumentAdapter>(ws)); setTimeTransformerFromInstrument(m_poldiInstrument); // If a profile function is selected, set it on the peak collections. Property *profileFunctionProperty = getPointerToProperty("PeakProfileFunction"); if (!profileFunctionProperty->isDefault()) { for (auto &peakCollection : peakCollections) { peakCollection->setProfileFunctionName(profileFunctionProperty->value()); } } // Perform 2D-fit and return Fit algorithm to extract various information IAlgorithm_sptr fitAlgorithm = calculateSpectrum(peakCollections, ws); // The FitFunction is used to generate... IFunction_sptr fitFunction = getFunction(fitAlgorithm); // ...a calculated 1D-spectrum... MatrixWorkspace_sptr outWs1D = get1DSpectrum(fitFunction, ws); // ...a vector of peak collections. std::vector<PoldiPeakCollection_sptr> integralPeaks = getCountPeakCollections(fitFunction); for (size_t i = 0; i < peakCollections.size(); ++i) { assignMillerIndices(peakCollections[i], integralPeaks[i]); } // Get the calculated 2D workspace setProperty("OutputWorkspace", getWorkspace(fitAlgorithm)); // Set the output peaks depending on whether it's one or more workspaces if (integralPeaks.size() == 1) { setProperty("RefinedPoldiPeakWorkspace", integralPeaks.front()->asTableWorkspace()); } else { WorkspaceGroup_sptr peaksGroup = boost::make_shared<WorkspaceGroup>(); for (auto &integralPeak : integralPeaks) { peaksGroup->addWorkspace(integralPeak->asTableWorkspace()); } setProperty("RefinedPoldiPeakWorkspace", peaksGroup); } // Set the 1D-spectrum output setProperty("Calculated1DSpectrum", outWs1D); // If it was a PawleyFit, also produce one or more cell parameter tables. bool isPawleyFit = getProperty("PawleyFit"); if (isPawleyFit) { Poldi2DFunction_sptr poldi2DFunction = boost::dynamic_pointer_cast<Poldi2DFunction>(fitFunction); std::vector<ITableWorkspace_sptr> cells; if (poldi2DFunction) { for (size_t i = 0; i < poldi2DFunction->nFunctions(); ++i) { try { ITableWorkspace_sptr cell = getRefinedCellParameters(poldi2DFunction->getFunction(i)); cells.push_back(cell); } catch (const std::invalid_argument &) { // do nothing } } if (cells.size() == 1) { setProperty("RefinedCellParameters", cells.front()); } else { WorkspaceGroup_sptr cellsGroup = boost::make_shared<WorkspaceGroup>(); for (auto &cell : cells) { cellsGroup->addWorkspace(cell); } setProperty("RefinedCellParameters", cellsGroup); } } else { g_log.warning() << "Warning: Cell parameter table is empty."; } } // Optionally output the raw fitting parameters. Property *rawFitParameters = getPointerToProperty("RawFitParameters"); if (!rawFitParameters->isDefault()) { ITableWorkspace_sptr parameters = fitAlgorithm->getProperty("OutputParameters"); setProperty("RawFitParameters", parameters); } }