Example #1
0
/** 
 * Device initialization: check device capability and open for recording.
 * 
 * @param sfreq [in] required sampling frequency.
 * @param dummy [in] a dummy data
 * 
 * @return TRUE on success, FALSE on failure.
 */
boolean
adin_mic_standby(int sfreq, void *dummy)
{
  PaError err;
  int frames_per_buffer, num_buffer;
  int latency;
  char *p;

  /* set cycle buffer length */
  cycle_buffer_len = INPUT_DELAY_SEC * sfreq;
  j_printerr("Audio cycle buffer length: %d bytes\n", cycle_buffer_len * sizeof(SP16));

  /* for safety... */
  if (sizeof(SP16) != paInt16) {
    j_error("SP16 != paInt16\n");
  }

  /* allocate and init */
  current = processed = 0;
  speech = (SP16 *)mymalloc(sizeof(SP16) * cycle_buffer_len);
  buffer_overflowed = FALSE;

  /* set buffer parameter*/
  if ((p = getenv("LATENCY_MSEC")) != NULL) {
    j_printerr("adin_mic_standby: get LATENCY_MSEC=%s\n", p);
    latency = atoi(p);
  } else {
    latency = MAX_FRAGMENT_MSEC;
  }
  frames_per_buffer = 256;
  num_buffer = sfreq * latency / (frames_per_buffer * 1000);
  j_printf("framesPerBuffer=%d, NumBuffers(guess)=%d (%d)\n",
	   frames_per_buffer, num_buffer, 
	   Pa_GetMinNumBuffers(frames_per_buffer, sfreq));
  j_printf("Audio I/O Latency = %d msec (data fragment = %d frames)\n",
	   (frames_per_buffer * num_buffer) * 1000 / sfreq, 
	   (frames_per_buffer * num_buffer));

  /* initialize device and open stream */
  err = Pa_Initialize();
  if (err != paNoError) {
    j_printerr("Error: %s\n", Pa_GetErrorText(err));
    return(FALSE);
  }

  err = Pa_OpenDefaultStream(&stream, 1, 0, paInt16, sfreq, 
			     frames_per_buffer, num_buffer, 
			     Callback, NULL);
  if (err != paNoError) {
    j_printerr("Error: %s\n", Pa_GetErrorText(err));
    return(FALSE);
  }

  return(TRUE);
}
Example #2
0
/*
 * Given a <linux_path>, change to its corresponding drive and directory
 * in DOS (redirecting a new drive if necessary).  The DOS command and any
 * DOS options (like "/a/b /c") are returned through <linux_path>.
 * The DOS options may be passed in dos_opts as well.
 *
 * Returns 0 on success, nonzero on failure.
 */
static int setupDOSCommand(const char *linux_path, int n_up, char *r_drv)
{
#define MAX_RESOURCE_PATH_LENGTH   128
  char dos_path [MAX_PATH_LENGTH];
  char resourceStr[MAX_RESOURCE_PATH_LENGTH];
  int drive;
  int err;
  int i;
  char *dos_dir;
  char *path1, *p;

  drive = find_free_drive();
  if (drive < 0) {
    com_fprintf (com_stderr,
                     "ERROR: Cannot find a free DOS drive to use for LREDIR\n");
    return (1);
  }

  path1 = strdup(linux_path);
  i = n_up;
  while (i--) {
    p = strrchr(path1, '/');
    if (!p) {
      free(path1);
      error("Path \"%s\" does not contain %i components\n", linux_path, n_up);
      return 1;
    }
    *p = 0;
  }
  if (!path1[0])
    strcpy(path1, "/");
  j_printf("Redirecting %c: to %s\n", drive + 'A', path1);
  snprintf(resourceStr, sizeof(resourceStr), "%s%s", LINUX_RESOURCE, path1);
  err = RedirectDisk(drive, resourceStr, 0/*rw*/);
  free(path1);
  if (err) {
    com_fprintf (com_stderr,
                   "ERROR: Could not redirect %c: to /\n", drive + 'A');
    return (1);
  }

  /* switch to the drive */
  j_printf ("Switching to drive %i (%c:)\n", drive, drive + 'A');
  com_dossetdrive (drive);
  if (com_dosgetdrive () != drive) {
    com_fprintf (com_stderr, "ERROR: Could not change to %c:\n", drive + 'A');
    if (com_dossetdrive (com_dosgetdrive ()) < 26)
      com_fprintf (com_stderr, "Try 'LASTDRIVE=Z' in CONFIG.SYS.\n");
    return (1);
  }

  err = make_unmake_dos_mangled_path(dos_path, linux_path, drive, 1/*mangle*/);
  if (err) {
    com_fprintf(com_stderr, "INTERNAL ERROR: path %s not resolved\n",
        linux_path);
    return 1;
  }
  j_printf ("DOS path: '%s' (from linux '%s')\n", dos_path, linux_path);

  /* switch to the directory */
  if (strlen(dos_path) < 3) {
    com_fprintf(com_stderr, "INTERNAL ERROR: DOS path %s invalid\n", dos_path);
    return 1;
  }
  dos_dir = dos_path + 2;
  j_printf ("Changing to directory '%s'\n", dos_dir);
  err = com_dossetcurrentdir (dos_dir);
  if (err) {
    com_fprintf (com_stderr,
                   "ERROR: Could not change to directory: %s\n",
                   dos_dir);
    return (1);
  }

  if (r_drv)
    *r_drv = drive + 'A';
  return (0);
}
Example #3
0
/** 
 * Device initialization: check device capability and open for recording.
 * 
 * @param sfreq [in] required sampling frequency.
 * @param arg [in] a dummy data
 * 
 * @return TRUE on success, FALSE on failure.
 */
boolean
adin_mic_standby(int sfreq, void *arg)
{
  char *defaultdev = DEFAULT_DEVICE;
  char *devname;

  /* get device name if specified in $AUDIODEV */
  if ((devname = getenv("AUDIODEV")) == NULL) {
    devname = defaultdev;
  }

  /* open the device */
  if ((afd = open(devname, O_RDONLY)) == -1) {
    perror("adin_mic_standby: open audio device");
    return(FALSE);
  }

#if 0
  {
    /* output hardware info (debug) */
    struct audio_device adev;
    if (ioctl(afd, AUDIO_GETDEV, &adev)== -1) {
      perror("adin_mic_standby: AUDIO_GETDEV");
      return(FALSE);
    }
    j_printf("Hardware name: %s\n",adev.name);
    j_printf("Hardware version: %s\n", adev.version);
    j_printf("Properties: %s\n", adev.config);
  }
#endif

  /* get current setting */
  if (ioctl(afd, AUDIO_GETINFO, &ainfo) == -1) {
    perror("adin_mic_standby: AUDIO_GETINFO");
    return(FALSE);
  }
  /* pause for changing setting */
  ainfo.record.pause = 1;
  if (ioctl(afd, AUDIO_SETINFO, &ainfo) == -1) {
    perror("adin_mic_standby: AUDIO_SETINFO");
    return(FALSE);
  }
  /* flush current input buffer (in old format) */
  if((ioctl(afd , I_FLUSH , FLUSHR)) == -1) {
    perror("adin_mic_standby: I_FLUSH");
    return(FALSE);
  }
  /* set record setting */
  ainfo.record.sample_rate = sfreq;
  ainfo.record.channels = 1;
  ainfo.record.precision = 16;
  ainfo.record.encoding = AUDIO_ENCODING_LINEAR;
  /* ainfo.record.gain = J_DEF_VOLUME * (AUDIO_MAX_GAIN - AUDIO_MIN_GAIN) / 100 + AUDIO_MIN_GAIN; */
  ainfo.record.port = AUDIO_MICROPHONE;
  /* recording should be paused when initialized */
  ainfo.record.pause = 1;

  /* set audio setting, remain pause */
  if (ioctl(afd, AUDIO_SETINFO, &ainfo) == -1) {
    perror("adin_mic_standby: AUDIO_SETINFO");
    return(FALSE);
  }

  return(TRUE);

}