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

📄 xencode.c

📁 Reference Implementation of G.711 standard and other voice codecs
💻 C
📖 第 1 页 / 共 3 页
字号:
	Description:	get file's mode.	~~~~~~~~~~~~	Variables:	~~~~~~~~~~	fp 	pointer to file of which the mode is wanted	Exit values:	~~~~~~~~~~~~	S_????	file's access mode	Author:	Simao Ferraz de Campos Neto -- CPqD/Telebras	~~~~~~~  <tdsimao@venus.cpqd.ansp.br>	Date:	19/Mar/91-16:30	~~~~~	Version: 1.00	~~~~~~~~	Revision/Date/Author: none (yet)	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/int             get_mode(fp)  FILE           *fp;{  struct stat     sbuf;  /* figure out file mode */  fstat(fileno(fp), &sbuf);  return (sbuf.st_mode & 0777);}/* ........................... end of get_mode() ........................... *//*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~	int encode (FILE *in, FILE *out, long charno);        ~~~~~~~~~~	Description:	~~~~~~~~~~~~	Copy from in to out, encoding as it goes along, using the basic	encoding scheme:                          ENC(c) = (((c) & 077) + ' ')	Variables:	~~~~~~~~~~	in 	pointer to file from which samples are taken	out	pointer to file to which encoded samples are put	charno	maximum number of chars to be written	Routines:	- outenc	~~~~~~~~~	- ENC	Author:	unknown	~~~~~~~	Revision/Date/Author: 	~~~~~~~~~~~~~~~~~~~~~         19.Mar.91 v1.0 Adapted from public domain implementation                       <tdsimao@venus.cpqd.ansp.br>        25.Sep.95 v1.1 Modified charno to reflect the number of bytes of the                        output file, instead of the number of bytes of the                        input file. <simao@ctd.comsat.com>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/int             encode(in, out, charno)  FILE           *in;  FILE           *out;  long            charno;{  char            buf[80];  int             i, n;  long            count = 0;  /* Adjust input bytes to output bytes */  charno = (long)(charno * 3 / 4);  do  {    /* Find out, encode and write the no.of chars/line (upto 45) */    n = fr(in, buf, 45);    putc(ENC(n), out);    /* Update CRCs for the block of data */    crc_a = get_arc_crc(crc_a,(unsigned char *) buf, n);    crc_c = get_ccitt_crc(crc_c, (unsigned char *) buf, n);    crc_x = get_xmodem_crc(crc_x, (unsigned char *) buf, n);    /* Encode the data from input and save to output, 3 at a time */    for (i = 0; i < n; i += 3)      outenc(&buf[i], out);    /* New line after "n" chars are out */    putc('\n', out);    /* Updates counter of output samples */    count += n;  } while (n > 0 && count < charno);	/* i.e., not EOF, ... */  if (count >= charno)    fprintf(out, "`\n");  return 0;}/* .......................... end of encode() .......................... *//*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~	int outenc (char *p, FILE *f);        ~~~~~~~~~~	Description:	~~~~~~~~~~~~	Output one group of 3 bytes, pointed at by p, on file f, using	the basic encoding scheme:                          ENC(c) = (((c) & 077) + ' ')	Variables:	~~~~~~~~~~	p	pointer to array of 3 bytes to be coded and saved as 4		[printable] bytes;	f	pointer to file to which encoded samples are put	Author:	unknown	~~~~~~~	Revision/Date/Author: Simao Ferraz de Campos Neto -- CPqD/Telebras	~~~~~~~~~~~~~~~~~~~~~ <tdsimao@venus.cpqd.ansp.br> -- 19/Mar/91-16:30~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/int outenc(p, f)  char           *p;  FILE           *f;{  int             c1, c2, c3, c4;  c1 = *p >> 2;  c2 = ((*p << 4) & 060) | ((p[1] >> 4) & 017);  c3 = ((p[1] << 2) & 074) | ((p[2] >> 6) & 03);  c4 = p[2] & 077;  putc(ENC(c1), f);  putc(ENC(c2), f);  putc(ENC(c3), f);  putc(ENC(c4), f);  return 0;}/* ........................... end of outenc() ........................... *//*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~	int fr (FILE *fd, char *buf, int cnt);	~~~~~~	Description:	~~~~~~~~~~~~	Read upto cnt bytes from stream (file/device) pointed by fd and	save in buffer buf. Similar to fread.	Variables:	~~~~~~~~~~	fd 	pointer to file from which chars are read	buf	pointer to char	cnt	maximum number of chars to be read	Author:	unknown	~~~~~~~	Revision/Date/Author: Simao Ferraz de Campos Neto -- CPqD/Telebras	~~~~~~~~~~~~~~~~~~~~~ <tdsimao@venus.cpqd.ansp.br> -- 19/Mar/91-16:30~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/int             fr(fd, buf, cnt)  FILE           *fd;  char           *buf;  int             cnt;{  int             c, i;  for (i = 0; i < cnt; i++)  {    c = getc(fd);    if (c == EOF)      return (i);    buf[i] = c;  }  return (cnt);}/* ........................... end of fr() ........................... *//*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~	char *xcode_index (register char *sp, register char c);	~~~~~~~~~~~	Description:	~~~~~~~~~~~~	Locates the first occurence of c in stream sp and returns it;	if c is not found, returns NULL.	Variables:	~~~~~~~~~~	sp 	pointer to first ocurrence of c in ptr	c	character to be located;	Author:	unknown	~~~~~~~	Revision/Date/Author: Simao Ferraz de Campos Neto -- CPqD/Telebras	~~~~~~~~~~~~~~~~~~~~~ <tdsimao@venus.cpqd.ansp.br> -- 19/Mar/91-16:30~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/#ifdef NULL# undef NULL#endif#define	NULL	0char           *xcode_index(sp, c)  register char  *sp;  register char   c;{  do  {    if (*sp == c)      return (sp);  } while (*sp++);  return (NULL);}/* ........................... end of xcode_index() ........................... *//*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~	char *get_root (char *root, char *full_name);	~~~~~~~~~~~~~~	Description:	~~~~~~~~~~~~        Deletes file extension from a file name by  locating the last        occurence of the extension mark (".") in the file  name pointed        by "full_name" and copying upto that position, "full_name" to        "root".	Variables:	~~~~~~~~~~	root		file name without extension;	full_name	file's full name;	Exit values:	~~~~~~~~~~~~	Filename without extension; if given file name has no extension,        the original name is returned.	Original Author:	~~~~~~~~~~~~~~~~	Simao Ferraz de Campos Neto -- CPqD/Telebras	Revision/Date/Author:	~~~~~~~~~~~~~~~~~~~~~        19.Mar.91 v1.0 1st release        21.Jul.93 v2.0 Added removal of the path from the file name.<simao>        25.Sep.95 v2.1 Added smarter handling of filenames with multiple '.'                        (allowed in Unix) <simao@ctd.comsat.com>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/#if defined(VMS)#define PATH_END ']'#elif defined(MSDOS)#define PATH_END '\\'#else				/* Unix */#define PATH_END '/'#endifchar           *get_root(root, full_name)  char           *root;  char           *full_name;{  register char  *tmp = full_name;#if (XENCODE==200)  int             n;#endif  /* copy full-name to root buffer */  strcpy(root, full_name);  /* finds last occurence of a pointend of the path */  tmp = (char *) strrchr(root, PATH_END);  if (tmp == NULL)    tmp = root; 		/* name starts with root, i.e., no path				 * present */  else    tmp++;			/* move onto start of root name */#if (XENCODE==200)  /* finds last occurence of a point */  n = (long) strcspn(tmp, ".");  /* copy root from tmp to `root' */  strncpy(root, tmp, n);  root[n] = '\0';#else  /* finds last occurence of a dot */  tmp = strrchr(tmp, '.');  if (tmp)     *tmp = 0;#endif  /* returns the file name without extension */  return (root);}#undef PATH_END/* ........................... end of get_root() ........................... *//*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~	char *get_extension (char *ext, char *full_name, int max_length);	~~~~~~~~~~~~~~~~~~~	Description:	~~~~~~~~~~~~        Locates the extension of a file name by  locating the last        occurence of the extension mark (".") in the file name pointed        by "full_name" and copying from that position (thus including        the '.')  upto the name's end (limmited to max_length chars) to        "ext".	Variables:	~~~~~~~~~~	ext		file name's extension (with point);	full_name	file's full name;	max_length	maximum length allowed for the extension	Exit values:	~~~~~~~~~~~~	Filename's extension; if given file name has no extension,        a null-string is returned.	Author:	Simao Ferraz de Campos Neto -- CPqD/Telebras	~~~~~~~  <tdsimao@venus.cpqd.ansp.br>	Date:	19/Mar/91-16:30	~~~~~	Version: 1.00	~~~~~~~~	Revision/Date/Author: none (yet)	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/char           *get_extension(ext, full_name, max_length)  char           *ext;  char           *full_name;  int             max_length;{  register char  *tmp, *end;  /* finds last occurence of a point */  if ((tmp = (char *) strrchr(full_name, '.')) == NULL)  {    /* if original file had no extension, returns a '.' */    strcpy(ext, ".");    return (NULL);  }  /* and string's end */  end = (char *) strrchr(full_name, 0);  /* copies the extension from the point, ... */  strncpy(ext, tmp, max_length);  /* ... and appends a '\0', if needed */  if (max_length <= end - tmp)    ext[max_length] = '\0';  /* returns the file name's extension ('.' included!) */  return (ext);}/* ......................... end of get_extension() ......................... */

⌨️ 快捷键说明

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