<commit_before>#include "PitchMarker.h"

#pragma comment(lib, "libfftw3-3.lib")

using namespace std;

PitchMarker::PitchMarker(){}

PitchMarker::~PitchMarker(){}

bool PitchMarker::mark(const vector<double>& fore_vowel_wav, const vector<double>& aft_vowel_wav)
{
  if (input_wav.size()==0) {
    cerr << "[PitchMarker::mark] input_wav is invalid" << endl;
    return false;
  }
  if (fore_vowel_wav.size()==0 || aft_vowel_wav.size()==0 || fore_vowel_wav.size()!=aft_vowel_wav.size()) {
    cerr << "[PitchMarker::mark] vowel_wav is invalid" << endl;
    return false;
  }

  short win_size = fore_vowel_wav.size();
  pitchmarks.clear();
  pitchmarks.reserve((it_input_wav_blnk-it_input_wav_offs)/win_size);

  long pos_fore_mark_end, pos_aft_mark_start;
  vector<double>::const_iterator it_cons_start, it_cons_end, it_base_start, it_base_end;
  {
    vector<double>::const_iterator it_mark_start;
    {
      // find start point
      vector<double> xcorr_win(win_size*2, 0.0);
      it_mark_start = max_element(it_input_wav_offs+(win_size/2), it_input_wav_offs+(win_size/2*3));
      xcorr(it_mark_start, xcorr_win.begin(), fore_vowel_wav.begin(), fore_vowel_wav.end());
      it_mark_start += max_element(xcorr_win.begin(), xcorr_win.end()) - xcorr_win.begin() - (win_size/2);
    }
    // fore vowel pitch mark
    vector<vector<double>::const_iterator> tmp_pitchmarks =
      markWithVowel(it_mark_start, it_input_wav_ovrl, fore_vowel_wav.begin(), fore_vowel_wav.end());
    for (size_t i=0; i<tmp_pitchmarks.size(); i++) {
      pitchmarks.push_back(tmp_pitchmarks[i] - input_wav.begin());
    }
    it_base_start = *(tmp_pitchmarks.end()-3);
    it_base_end = *(tmp_pitchmarks.end()-1);
    it_cons_start = it_base_end;
    pos_fore_mark_end =pitchmarks.back();
  }
  {
    vector<double>::const_reverse_iterator rit_mark_start, rit_input_wav_offs(it_input_wav_blnk), rit_input_wav_prec(it_input_wav_prec);
    {
      // find start point
      vector<double> xcorr_win(win_size*2, 0.0);
      rit_mark_start = max_element(rit_input_wav_offs+(win_size/2), rit_input_wav_offs+(win_size/2*3));
      xcorr(rit_mark_start, xcorr_win.begin(), aft_vowel_wav.rbegin(), aft_vowel_wav.rend());
      rit_mark_start += max_element(xcorr_win.begin(), xcorr_win.end()) - xcorr_win.begin() - (win_size/2);
    }
    // aft vowel pitch mark
    vector<vector<double>::const_reverse_iterator> tmp_pitchmarks =
      markWithVowel(rit_input_wav_offs, rit_input_wav_prec, aft_vowel_wav.rbegin(), aft_vowel_wav.rend());
    for (size_t i=0; i<tmp_pitchmarks.size(); i++) {
      pitchmarks.push_back(input_wav.rend() - tmp_pitchmarks[i]);
    }
    it_cons_end = (*(tmp_pitchmarks.end()-3)).base();
    pos_aft_mark_start = pitchmarks.back();
  }
  {<commit_msg>pitchmark bugfix<commit_after>#include "PitchMarker.h"

#pragma comment(lib, "libfftw3-3.lib")

using namespace std;

PitchMarker::PitchMarker(){}

PitchMarker::~PitchMarker(){}

bool PitchMarker::mark(const vector<double>& fore_vowel_wav, const vector<double>& aft_vowel_wav)
{
  if (input_wav.size()==0) {
    cerr << "[PitchMarker::mark] input_wav is invalid" << endl;
    return false;
  }
  if (fore_vowel_wav.size()==0 || aft_vowel_wav.size()==0 || fore_vowel_wav.size()!=aft_vowel_wav.size()) {
    cerr << "[PitchMarker::mark] vowel_wav is invalid" << endl;
    return false;
  }

  short win_size = fore_vowel_wav.size();
  pitchmarks.clear();
  pitchmarks.reserve((it_input_wav_blnk-it_input_wav_offs)/win_size);

  long pos_fore_mark_end, pos_aft_mark_start;
  vector<double>::const_iterator it_cons_start, it_cons_end, it_base_start, it_base_end;
  {
    vector<double>::const_iterator it_mark_start;
    {
      // find start point
      vector<double> xcorr_win(win_size*2, 0.0);
      it_mark_start = max_element(it_input_wav_offs+(win_size/2), it_input_wav_offs+(win_size/2*3));
      xcorr(it_mark_start, xcorr_win.begin(), fore_vowel_wav.begin(), fore_vowel_wav.end());
      it_mark_start += max_element(xcorr_win.begin(), xcorr_win.end()) - xcorr_win.begin() - (win_size/2);
    }
    // fore vowel pitch mark
    vector<vector<double>::const_iterator> tmp_pitchmarks =
      markWithVowel(it_mark_start, it_input_wav_ovrl, fore_vowel_wav.begin(), fore_vowel_wav.end());
    for (size_t i=0; i<tmp_pitchmarks.size(); i++) {
      pitchmarks.push_back(tmp_pitchmarks[i] - input_wav.begin());
    }
    it_base_start = *(tmp_pitchmarks.end()-3);
    it_base_end = *(tmp_pitchmarks.end()-1);
    it_cons_start = it_base_end;
    pos_fore_mark_end =pitchmarks.back();
  }
  {
    vector<double>::const_reverse_iterator rit_mark_start, rit_input_wav_offs(it_input_wav_blnk), rit_input_wav_prec(it_input_wav_prec);
    {
      // find start point
      vector<double> xcorr_win(win_size*2, 0.0);
      rit_mark_start = max_element(rit_input_wav_offs+(win_size/2), rit_input_wav_offs+(win_size/2*3));
      xcorr(rit_mark_start, xcorr_win.begin(), aft_vowel_wav.rbegin(), aft_vowel_wav.rend());
      rit_mark_start += max_element(xcorr_win.begin(), xcorr_win.end()) - xcorr_win.begin() - (win_size/2);
    }
    // aft vowel pitch mark
    vector<vector<double>::const_reverse_iterator> tmp_pitchmarks =
      markWithVowel(rit_mark_start, rit_input_wav_prec, aft_vowel_wav.rbegin(), aft_vowel_wav.rend());
    for (size_t i=0; i<tmp_pitchmarks.size(); i++) {
      pitchmarks.push_back(input_wav.rend() - tmp_pitchmarks[i]);
    }
    it_cons_end = (*(tmp_pitchmarks.end()-3)).base();
    pos_aft_mark_start = pitchmarks.back();
  }
  {
{'fraction_non_alphanumeric': 0.14610212611302925, 'fraction_numerical': 0.008722514991822642, 'mean_word_length': 4.892933618843683, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '729315', 'n_tokens_mistral': 2270, 'n_tokens_neox': 2208, 'n_words': 281}