⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adin_file.c

📁 julius version 4.12.about sound recognition.
💻 C
📖 第 1 页 / 共 2 页
字号:
    has_pre = TRUE;  }  gfp = fp;  return(TRUE);}/**  * Close the input file *  * @return TRUE on success, FALSE on failure. */static booleanadin_file_close(){  FILE *fp;  fp = gfp;  if (fclose(fp) != 0) {    jlog("Error: adin_file: failed to close file\n");    return FALSE;  } return TRUE; }static boolean from_file;	///< TRUE if list file is used to read input filenamestatic FILE *fp_list;		///< File pointer used for the listfile/**  * Initialization: if listfile is specified, open it here. *  * @param freq [in] required sampling frequency. * @param arg [in] file name of listfile, or NULL if not use *  * @return TRUE on success, FALSE on failure. */booleanadin_file_standby(int freq, void *arg){  char *fname = arg;  if (fname != NULL) {    /* read input filename from file */    if ((fp_list = fopen(fname, "r")) == NULL) {      jlog("Error: adin_file: failed to open %s\n", fname);      return(FALSE);    }    from_file = TRUE;  } else {    /* read filename from stdin */    from_file = FALSE;  }  /* store sampling frequency */  sfreq = freq;    return(TRUE);}/**  * @brief  Begin reading audio data from a file. * * If listfile was specified in adin_file_standby(), the next filename * will be read from the listfile.  Otherwise, the * filename will be obtained from stdin.  Then the file will be opened here. *  * @return TRUE on success, FALSE on failure. */booleanadin_file_begin(){  boolean readp;  /* ready to read next input */  readp = FALSE;  while(readp == FALSE) {    if (from_file) {      /* read file name from listfile */      do {	if (getl_fp(speechfilename, MAXPATHLEN, fp_list) == NULL) { /* end of input */	  fclose(fp_list);	  return(FALSE); /* end of input */	}      } while (speechfilename[0] == '#'); /* skip comment */    } else {      /* read file name from stdin */      if (get_line_from_stdin(speechfilename, MAXPATHLEN, "enter filename->") == NULL) {	return (FALSE);	/* end of input */      }    }    /* open input file */    if (adin_file_open(speechfilename) == FALSE) {      jlog("Error: adin_file: failed to read speech data: \"%s\"\n", speechfilename);    } else {      jlog("Stat: adin_file: input speechfile: %s\n", speechfilename);      readp = TRUE;    }  }  return TRUE;}/**  * Try to read @a sampnum samples and returns actual sample num recorded. *  * @param buf [out] samples obtained in this function * @param sampnum [in] wanted number of samples to be read *  * @return actural number of read samples, -1 if EOF, -2 if error. */intadin_file_read(SP16 *buf, int sampnum){  FILE *fp;  int cnt;  fp = gfp;    if (wav_p) {    cnt = fread(buf, sizeof(SP16), sampnum, fp);    if (cnt == 0) {      if (feof(fp)) return -1; /* EOF */      if (ferror(fp)) {	jlog("Error: adin_file: an error occured while reading file\n");	adin_file_close();	return -2; /* error */      }    }    if (nowlen + cnt > maxlen) {      cnt = maxlen - nowlen;    }    nowlen += cnt;  } else {    if (has_pre) {      buf[0] = pre_data[0]; buf[1] = pre_data[1];      has_pre = FALSE;      cnt = fread(&(buf[2]), sizeof(SP16), sampnum - 2, fp);      if (cnt == 0) {	if (feof(fp)) return -1; /* EOF */	if (ferror(fp)) {	  jlog("Error: adin_file: an error occured file reading file\n");	  adin_file_close();	  return -2; /* error */	}      }      cnt += 2;    } else {      cnt = fread(buf, sizeof(SP16), sampnum, fp);      if (cnt == 0) {	if (feof(fp)) return -1; /* EOF */	if (ferror(fp)) {	  jlog("Error: adin_file: an error occured file reading file\n");	  adin_file_close();	  return -2; /* error */	}      }    }  }  /* all .wav data are in little endian */  /* assume .raw data are in big endian */#ifdef WORDS_BIGENDIAN  if (wav_p) swap_sample_bytes(buf, cnt);#else  if (!wav_p) swap_sample_bytes(buf, cnt);#endif  return cnt;}/**  * End recording. *  * @return TRUE on success, FALSE on failure. */booleanadin_file_end(){  /* nothing needed */  adin_file_close();  return TRUE;}/**  * Initialization for speech input via stdin. *  * @param freq [in] required sampling frequency. * @param arg dummy, ignored *  * @return TRUE on success, FALSE on failure. */booleanadin_stdin_standby(int freq, void *arg){  /* store sampling frequency */  sfreq = freq;  return(TRUE);}/**  * @brief  Begin reading audio data from stdin * * @return TRUE on success, FALSE on failure. */booleanadin_stdin_begin(){  if (feof(stdin)) {		/* already reached the end of input stream */    jlog("Error: adin_stdin: stdin reached EOF\n");    return FALSE;		/* terminate search here */  } else {    /* open input stream */    if (adin_file_open(NULL) == FALSE) {      jlog("Error: adin_stdin: failed to read speech data from stdin\n");      return FALSE;    }    jlog("Stat: adin_stdin: reading wavedata from stdin...\n");  }  return TRUE;}/**  * Try to read @a sampnum samples and returns actual sample num recorded. *  * @param buf [out] samples obtained in this function * @param sampnum [in] wanted number of samples to be read *  * @return actural number of read samples, -1 if EOF, -2 if error. */intadin_stdin_read(SP16 *buf, int sampnum){  int cnt;  if (wav_p) {    cnt = myfread(buf, sizeof(SP16), sampnum, stdin);    if (cnt == 0) {      if (feof(stdin)) return -1; /* EOF */      if (ferror(stdin)) {	jlog("Error: adin_stdin: an error occured while reading stdin\n");	return -2; /* error */      }    }  } else {    if (has_pre) {      buf[0] = pre_data[0]; buf[1] = pre_data[1];      has_pre = FALSE;      cnt = fread(&(buf[2]), sizeof(SP16), sampnum - 2, stdin);      if (cnt == 0) {	if (feof(stdin)) return -1; /* EOF */	if (ferror(stdin)) {	  jlog("Error: adin_stdin: an error occured while reading stdin\n");	  return -2; /* error */	}      }      cnt += 2;    } else {      cnt = fread(buf, sizeof(SP16), sampnum, stdin);      if (cnt == 0) {	if (feof(stdin)) return -1; /* EOF */	if (ferror(stdin)) {	  jlog("Error: adin_stdin: an error occured while reading stdin\n");	  return -2; /* error */	}      }    }  }  /* all .wav data are in little endian */  /* assume .raw data are in big endian */#ifdef WORDS_BIGENDIAN  if (wav_p) swap_sample_bytes(buf, cnt);#else  if (!wav_p) swap_sample_bytes(buf, cnt);#endif  return cnt;}/**  *  * A tiny function to get current input raw speech file name. *  * @return string of current input speech file. *  */char *adin_file_get_current_filename(){  return(speechfilename);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -