예제 #1
0
int main(int argc, const char** argv) {
  const char* device_name = "";
  if (argc >= 2) {
    device_name = argv[1];
  }

  AudioDevicePtr device(OpenDevice(device_name));
  if (!device) {
    cerr << "OpenDevice() failed" << endl;
    return EXIT_FAILURE;
  }

  OutputStreamPtr tone = device->openStream(CreateTone(440));
  if (!tone) {
    cerr << "openStream() failed" << endl;
    return EXIT_FAILURE;
  }
  tone->play();

  clock_t start = clock();
  for (int i = 0; i < 100000; ++i) {
    assert(tone->isPlaying());
  }
  clock_t end = clock();

  double duration = double(end - start) / CLOCKS_PER_SEC;
  cout << "Total time for 100,000 isPlaying() calls = "
       << duration << " seconds" << endl;

  cout << "That is " << duration / 100000 << " seconds per call." << endl;

  return EXIT_SUCCESS;
}
예제 #2
0
int main(int argc, const char** argv) {

  if (argc != 2 && argc != 3) {
    cerr << "usage: simple <filename> [<device>]" << endl;
    return EXIT_FAILURE;
  }

  cerr << "initializing..." << endl;

  const char* device_name = "";
  if (argc == 3) {
    device_name = argv[2];
  }

  AudioDevicePtr device = OpenDevice(device_name);
  if (!device) {
    cerr << "OpenDevice() failed" << endl;
    return EXIT_FAILURE;
  }

  cerr << "opened device" << endl;

  OutputStreamPtr sound = OpenSound(device, argv[1]);
  if (!sound) {
    cerr << "OpenSound() failed" << endl;
    return EXIT_FAILURE;
  }

  cerr << "opened sound" << endl;

  sound->play();

  cerr << "started playback" << endl;
  while (sound->isPlaying()) {
    sleepSecond();
    if (sound->isSeekable()) {
      cerr << "position: " << sound->getPosition() << endl;
    }
  }

  return EXIT_SUCCESS;
}