Example #1
0
KeyFinderResultWrapper keyDetectionProcess(const AsyncFileObject& object) {

  KeyFinderResultWrapper result;
  result.batchRow = object.batchRow;

  AudioFileDecoder* decoder = NULL;
  try {

    decoder = new AudioFileDecoder(object.filePath, object.prefs.getMaxDuration());

  } catch (std::exception& e) {

    delete decoder;
    result.errorMessage = QString(e.what());
    return result;

  } catch (...) {

    delete decoder;
    result.errorMessage = "Unknown exception initialising decoder";
    return result;
  }

  KeyFinder::Workspace workspace;

  static KeyFinder::KeyFinder kf;

  try {

    while (true) {

      KeyFinder::AudioData* tempAudio = decoder->decodeNextAudioPacket();
      if (tempAudio == NULL) break;

      kf.progressiveChromagram(*tempAudio, workspace);
      delete tempAudio;
    }

    delete decoder;
    decoder = NULL;

    kf.finalChromagram(workspace);
    result.fullChromagram = KeyFinder::Chromagram(*workspace.chromagram);
    result.core = kf.keyOfChromagram(workspace);

  } catch (std::exception& e) {

    if (decoder != NULL) delete decoder;
    result.errorMessage = QString(e.what());
    return result;

  } catch (...) {

    if (decoder != NULL) {
      delete decoder;
      result.errorMessage = "Unknown exception while decoding";
    } else {
      result.errorMessage = "Unknown exception while analysing";
    }

    return result;
  }

  return result;
}
KeyFinderResultWrapper keyDetectionProcess(const AsyncFileObject& object) {

  KeyFinderResultWrapper result;
  result.batchRow = object.batchRow;

  AudioFileDecoder* decoder = NULL;
  try {
    decoder = new AudioFileDecoder(object.filePath, object.prefs.getMaxDuration());
  } catch (std::exception& e) {
    delete decoder;
    result.errorMessage = QString(e.what());
    return result;
  } catch (...) {
    delete decoder;
    result.errorMessage = "Unknown exception initialising decoder";
    return result;
  }

  KeyFinder::Workspace workspace;
  static KeyFinder::KeyFinder kf;
  try {
    while (true) {
      KeyFinder::AudioData* tempAudio = decoder->decodeNextAudioPacket();
      if (tempAudio == NULL) break;
      kf.progressiveChromagram(*tempAudio, workspace, object.prefs.core);
      delete tempAudio;
    }
    delete decoder;
    decoder = NULL;
    kf.finalChromagram(workspace, object.prefs.core);
    result.fullChromagram = KeyFinder::Chromagram(*workspace.chromagram);
    result.core = kf.keyOfChromagram(workspace, object.prefs.core);
    result.oneOctaveChromagram = result.fullChromagram;
    result.oneOctaveChromagram.reduceToOneOctave();
  } catch (std::exception& e) {
    if (decoder != NULL) delete decoder;
    result.errorMessage = QString(e.what());
    return result;
  } catch (...) {
    if (decoder != NULL) {
      delete decoder;
      result.errorMessage = "Unknown exception while decoding";
    } else {
      result.errorMessage = "Unknown exception while analysing";
    }
    return result;
  }

  for (unsigned int i = 0; i < result.core.segments.size(); i++) {
    qDebug(
      "Chroma vector for segment %d of file %s: [%.0f, %.0f, %.0f, %.0f, %.0f, %.0f, %.0f, %.0f, %.0f, %.0f, %.0f, %.0f]",
      i, object.filePath.toUtf8().constData(),
      result.core.segments[i].chromaVector[0],  result.core.segments[i].chromaVector[1],
      result.core.segments[i].chromaVector[2],  result.core.segments[i].chromaVector[3],
      result.core.segments[i].chromaVector[4],  result.core.segments[i].chromaVector[5],
      result.core.segments[i].chromaVector[6],  result.core.segments[i].chromaVector[7],
      result.core.segments[i].chromaVector[8],  result.core.segments[i].chromaVector[9],
      result.core.segments[i].chromaVector[10], result.core.segments[i].chromaVector[11]
    );
  }

  return result;
}