<commit_before>#include "VisHost.h"

VisHost::VisHost(string pluginPath_in)
{
  pluginPath = pluginPath_in;
  verbose=false;
}

int VisHost::init()
{
  // load the visualization library
  if (verbose) cout << " * Loading visualization plugin..." << flush;
  handle = dlopen(pluginPath.c_str(), RTLD_LAZY);
  if (!handle) {
    cerr << "ERROR: Cannot load library: " << dlerror() << endl;
    return 1;
  }

  // reset errors
  dlerror();

  // load the symbols
  create_t* create_plugin = (create_t*) dlsym(handle, "create");
  const char* dlsym_error = dlerror();
  if (dlsym_error) {
    cerr << "ERROR: Cannot load symbol create: " << dlsym_error << endl;
    dlclose(handle);
    return 1;
  }
  destroy_plugin = (destroy_t*) dlsym(handle, "destroy");
  dlsym_error = dlerror();
  if (dlsym_error) {
    cerr << "ERROR: Cannot load symbol destroy: " << dlsym_error << endl;
    dlclose(handle);
    return 1;
  }

  // create an instance of the class
  visPlugin = create_plugin();
  if (verbose) cout << " [done]" << endl;

  return 0;
}

int VisHost::process(string wavfile)
{
  // open the .wav file
  memset(&sfinfo, 0, sizeof(SF_INFO));
  sndfile = sf_open(wavfile.c_str(), SFM_READ, &sfinfo);
  if (!sndfile) {
    cerr << ": ERROR: Failed to open input file \""
      << wavfile << "\": " << sf_strerror(sndfile) << endl;
    return 1;
  }
  sampleRate = sfinfo.samplerate;

  // create set of unique plugins
  VisPlugin::VampOutputList vampOuts = visPlugin->getVampPlugins();
  for (VisPlugin::VampOutputList::iterator o=vampOuts.begin();
       o!=vampOuts.end(); o++)
  {
    VisPlugin::VampOutput out = *o;
    vampPlugins.insert(out.plugin);
  }

  // for each unique plugin
  for (set<VisPlugin::VampPlugin>::iterator p=vampPlugins.begin();
       p!=vampPlugins.end(); p++)
  {
    VisPlugin::VampPlugin plugin = *p;
    if (verbose) cout << " * Processing Vamp plugin " << plugin.name << "..."
      << flush;

    // move to beginning of .wav file
    sf_seek(sndfile, 0, SEEK_SET);
<commit_msg>Added check for number of channels on input file.<commit_after>#include "VisHost.h"

VisHost::VisHost(string pluginPath_in)
{
  pluginPath = pluginPath_in;
  verbose=false;
}

int VisHost::init()
{
  // load the visualization library
  if (verbose) cout << " * Loading visualization plugin..." << flush;
  handle = dlopen(pluginPath.c_str(), RTLD_LAZY);
  if (!handle) {
    cerr << "ERROR: Cannot load library: " << dlerror() << endl;
    return 1;
  }

  // reset errors
  dlerror();

  // load the symbols
  create_t* create_plugin = (create_t*) dlsym(handle, "create");
  const char* dlsym_error = dlerror();
  if (dlsym_error) {
    cerr << "ERROR: Cannot load symbol create: " << dlsym_error << endl;
    dlclose(handle);
    return 1;
  }
  destroy_plugin = (destroy_t*) dlsym(handle, "destroy");
  dlsym_error = dlerror();
  if (dlsym_error) {
    cerr << "ERROR: Cannot load symbol destroy: " << dlsym_error << endl;
    dlclose(handle);
    return 1;
  }

  // create an instance of the class
  visPlugin = create_plugin();
  if (verbose) cout << " [done]" << endl;

  return 0;
}

int VisHost::process(string wavfile)
{
  // open the .wav file
  memset(&sfinfo, 0, sizeof(SF_INFO));
  sndfile = sf_open(wavfile.c_str(), SFM_READ, &sfinfo);
  if (!sndfile) {
    cerr << "ERROR: Failed to open input file \""
      << wavfile << "\": " << sf_strerror(sndfile) << endl;
    return 1;
  }
  sampleRate = sfinfo.samplerate;

  // check channels
  if (sfinfo.channels != 1) {
    cerr << "ERROR: Only mono files currently supported." << endl;
    return 1;
  }

  // create set of unique plugins
  VisPlugin::VampOutputList vampOuts = visPlugin->getVampPlugins();
  for (VisPlugin::VampOutputList::iterator o=vampOuts.begin();
       o!=vampOuts.end(); o++)
  {
    VisPlugin::VampOutput out = *o;
    vampPlugins.insert(out.plugin);
  }

  // for each unique plugin
  for (set<VisPlugin::VampPlugin>::iterator p=vampPlugins.begin();
       p!=vampPlugins.end(); p++)
  {
    VisPlugin::VampPlugin plugin = *p;
    if (verbose) cout << " * Processing Vamp plugin " << plugin.name << "..."
      << flush;

    // move to beginning of .wav file
    sf_seek(sndfile, 0, SEEK_SET);

{'fraction_non_alphanumeric': 0.15452380952380954, 'fraction_numerical': 0.0038095238095238095, 'mean_word_length': 3.389759665621735, 'pattern_counts': {'":': 3, '<': 97, '<?xml version=': 0, '>': 7, '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': '1911106', 'n_tokens_mistral': 1515, 'n_tokens_neox': 1458, 'n_words': 373}