bool Engine::loadFile(const QString &fileName) { reset(); bool result = false; Q_ASSERT(!m_generateTone); Q_ASSERT(!m_file); Q_ASSERT(!fileName.isEmpty()); m_file = new WavFile(this); if (m_file->open(fileName)) { if (isPCMS16LE(m_file->fileFormat())) { result = initialize(); } else { emit errorMessage(tr("Audio format not supported"), formatToString(m_file->fileFormat())); } } else { // transform to wav for other audio format QString wavFile = this->m_ffmpegHelper->transform2WAV(fileName); if(wavFile == NULL) { // can not transform correctly emit errorMessage(tr("Could not open file"), fileName); } else { loadFile(wavFile); } } if (result) { m_analysisFile = new WavFile(this); m_analysisFile->open(fileName); } return result; }
void SpectrumAnalyser::calculate(const QByteArray &buffer, const QAudioFormat &format, bool isSample,char phoneme) { // QThread::currentThread is marked 'for internal use only', but // we're only using it for debug output here, so it's probably OK :) SPECTRUMANALYSER_DEBUG << "SpectrumAnalyser::calculate" << QThread::currentThread() << "state" << m_state; if (isReady()) { Q_ASSERT(isPCMS16LE(format)); const int bytesPerSample = format.sampleSize() * format.channels() / 8; #ifdef DUMP_SPECTRUMANALYSER m_count++; const QString pcmFileName = m_outputDir.filePath(QString("spectrum_%1.pcm").arg(m_count, 4, 10, QChar('0'))); QFile pcmFile(pcmFileName); pcmFile.open(QIODevice::WriteOnly); const int bufferLength = m_numSamples * bytesPerSample; pcmFile.write(buffer, bufferLength); m_textStream << "TimeDomain " << m_count << "\n"; const qint16* input = reinterpret_cast<const qint16*>(buffer); for (int i=0; i<m_numSamples; ++i) { m_textStream << i << "\t" << *input << "\n"; input += format.channels(); } #endif m_state = Busy; // Invoke SpectrumAnalyserThread::calculateSpectrum using QMetaObject. If // m_thread is in a different thread from the current thread, the // calculation will be done in the child thread. // Once the calculation is finished, a calculationChanged signal will be // emitted by m_thread. const bool b = QMetaObject::invokeMethod(m_thread, "calculateSpectrum", Qt::AutoConnection, Q_ARG(QByteArray, buffer), Q_ARG(int, format.frequency()), Q_ARG(int, bytesPerSample), Q_ARG(bool,isSample), Q_ARG(char,phoneme)); Q_ASSERT(b); Q_UNUSED(b) // suppress warnings in release builds #ifdef DUMP_SPECTRUMANALYSER m_textStream << "FrequencySpectrum " << m_count << "\n"; FrequencySpectrum::const_iterator x = m_spectrum.begin(); for (int i=0; i<m_numSamples; ++i, ++x) m_textStream << i << "\t" << x->frequency << "\t" << x->amplitude<< "\t" << x->phase << "\n"; #endif } }
void SpectrumAnalyser::calculate(const QByteArray &buffer, const QAudioFormat &format) { // QThread::currentThread is marked 'for internal use only', but // we're only using it for debug output here, so it's probably OK :) SPECTRUMANALYSER_DEBUG << "SpectrumAnalyser::calculate" << QThread::currentThread() << "state" << m_state; SPECTRUMANALYSER_DEBUG << "buffer size =" << buffer.size(); if (isReady()) { Q_ASSERT(isPCMS16LE(format)); const int bytesPerSample = format.sampleSize() * format.channelCount() / 8; m_state = Busy; // Invoke SpectrumAnalyserThread::calculateSpectrum using QMetaObject. If // m_thread is in a different thread from the current thread, the // calculation will be done in the child thread. // Once the calculation is finished, a calculationChanged signal will be // emitted by m_thread. const bool b = QMetaObject::invokeMethod(m_thread, "calculateSpectrum", Qt::AutoConnection, Q_ARG(QByteArray, buffer), Q_ARG(int, format.sampleRate()), Q_ARG(int, bytesPerSample)); Q_ASSERT(b); Q_UNUSED(b) // suppress warnings in release builds #ifdef DUMP_SPECTRUMANALYSER m_textStream << "FrequencySpectrum " << m_count << "\n"; FrequencySpectrum::const_iterator x = m_spectrum.begin(); for (int i=0; i<m_numSamples; ++i, ++x) m_textStream << i << "\t" << x->frequency << "\t" << x->amplitude<< "\t" << x->phase << "\n"; #endif } }
bool Engine::loadFile(const QString &fileName) { reset(); bool result = false; Q_ASSERT(!m_generateTone); Q_ASSERT(!m_file); Q_ASSERT(!fileName.isEmpty()); m_file = new WavFile(this); if (m_file->open(fileName)) { if (isPCMS16LE(m_file->fileFormat())) { result = initialize(); } else { emit errorMessage(tr("Audio format not supported"), formatToString(m_file->fileFormat())); } } else { emit errorMessage(tr("Could not open file"), fileName); } if (result) { m_analysisFile = new WavFile(this); m_analysisFile->open(fileName); } return result; }
void SpectrumAnalyser::calculateTotal( qint64 position, qint64 length, const QAudioFormat &format, const QByteArray &buffer ) { Q_UNUSED(position) Q_UNUSED(length) SPECTRUMANALYSER_DEBUG << "SpectrumAnalyser::calculateTotal" << QThread::currentThread() << "state" << m_state; SPECTRUMANALYSER_DEBUG << "buffer size =" << buffer.size(); if (isReady()) { Q_ASSERT(isPCMS16LE(format)); const int bytesPerSample = format.sampleSize() * format.channelCount() / 8; m_state = Busy; // Invoke SpectrumAnalyserThread::calculateTotalSpectrum using QMetaObject. // If m_thread is in a different thread from the current thread, the // calculation will be done in the child thread. // Once the calculation is finished, a calculationChanged signal will be // emitted by m_thread. const bool b = QMetaObject::invokeMethod(m_thread, "calculateTotalSpectrum", Qt::AutoConnection, Q_ARG(QByteArray, buffer), Q_ARG(int, format.sampleRate()), Q_ARG(int, bytesPerSample)); Q_ASSERT(b); Q_UNUSED(b) // suppress warnings in release builds } }