Exemple #1
0
size_t
AudioPlayer::Soundfile::_get_jack_sample_rate()
{
  ECA_CONTROL_INTERFACE eca;
  eca.command("cs-add dummy_chainsetup");
  eca.command("c-add dummy_chain");

  eca.command("ai-add jack");
  eca.command("ao-add null");
  eca.command("cs-connect");
  if (eca.error())
  {
    throw soundfile_error("_get_jack_sample_rate(): " + eca.last_error());
  }
  eca.command("ai-get-format");
  std::string str = eca.last_string();
  eca.command("cs-disconnect");
  eca.command("c-remove");
  eca.command("cs-remove");

  std::replace(str.begin(), str.end(), ',', ' ');
  std::istringstream iss(str);
  std::string format;
  size_t channels, sample_rate;
  iss >> format >> channels >> sample_rate;
  if (iss.fail())
  {
    throw soundfile_error("Couldn't convert string for getting sample rate!");
  }
  assert(sample_rate >= 1);

  return sample_rate;
}
Exemple #2
0
std::string
AudioPlayer::Soundfile::get_format(const std::string& filename
    , size_t& channels, size_t& sample_rate)
{
  ECA_CONTROL_INTERFACE eca;
  eca.command("cs-add dummy_chainsetup");
  eca.command("c-add dummy_chain");

  eca.command("ai-add sndfile,"
      + posixpathtools::get_escaped_filename(filename));
  eca.command("ao-add null");
  eca.command("cs-connect");
  if (eca.error())
  {
    throw soundfile_error("get_format(): " + eca.last_error());
  }
  eca.command("ai-index-select 1");
  eca.command("ai-get-format");
  std::string str = eca.last_string();
  eca.command("cs-disconnect");
  eca.command("c-remove");
  eca.command("cs-remove");

  std::replace(str.begin(), str.end(), ',', ' ');
  std::istringstream iss(str);
  std::string format;
  iss >> format >> channels >> sample_rate;
  if (iss.fail())
  {
    throw soundfile_error("Couldn't convert format string!");
  }
  assert(sample_rate >= 1);

  return format;
}