Exemplo n.º 1
0
/**
 * Plays a sound definition file (*.sdf) through PC speaker. SDF files
 * should reside in the gfiles dir. The only params passed to function are
 * filename and false if playback is unabortable, true if it is abortable. If no
 * extension then .SDF is appended. A full path to file may be specified to
 * override gfiles dir. Format of file is:
 *
 * <freq> <duration in ms> [pause_delay in ms]
 * 1000 1000 50
 *
 * Returns 1 if sucessful, else returns 0. The pause_delay is optional and
 * is used to insert silences between tones.
 */
bool play_sdf(const std::string soundFileName, bool abortable) {
  WWIV_ASSERT(!soundFileName.empty());

  std::string fullPathName;
  // append gfilesdir if no path specified
  if (soundFileName.find(WWIV_FILE_SEPERATOR_CHAR) == std::string::npos) {
    std::ostringstream ss;
    ss << syscfg.gfilesdir << soundFileName;
    fullPathName = ss.str();
  } else {
    fullPathName = soundFileName;
  }

  // append .SDF if no extension specified
  if (fullPathName.find('.') == std::string::npos) {
    fullPathName += ".sdf";
  }

  // Must Exist
  if (!WFile::Exists(fullPathName)) {
    return false;
  }

  // must be able to open read-only
  WTextFile soundFile(fullPathName, "rt");
  if (!soundFile.IsOpen()) {
    return false;
  }

  // scan each line, ignore lines with words<2
  std::string soundLine;
  while (soundFile.ReadLine(&soundLine)) {
    if (abortable && bkbhit()) {
      break;
    }
    int nw = wordcount(soundLine.c_str(), DELIMS_WHITE);
    if (nw >= 2) {
      int freq = atoi(extractword(1, soundLine, DELIMS_WHITE));
      int dur = atoi(extractword(2, soundLine, DELIMS_WHITE));

      // only play if freq and duration > 0
      if (freq > 0 && dur > 0) {
        int nPauseDelay = 0;
        if (nw > 2) {
          nPauseDelay = atoi(extractword(3, soundLine, DELIMS_WHITE));
        }
        WWIV_Sound(freq, dur);
        if (nPauseDelay > 0) {
          WWIV_Delay(nPauseDelay);
        }
      }
    }
  }

  soundFile.Close();
  return true;
}
Exemplo n.º 2
0
boolean KB_KeyWaiting( void )
{
	return bkbhit();
//	return (keyfifoplc != keyfifoend);
}