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

📄 libds.c

📁 speech signal process tools
💻 C
字号:
/*	Copyright (c) 1987, 1988, 1989, 1990, 1991 AT&T	*//*	  and Entropic Research Lab, Inc.		*//*	  All Rights Reserved.		*//*	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T	*//*	AND ENTROPIC RESEARCH LAB, INC.				*//*	The copyright notice above does not evidence any	*//*	actual or intended publication of such source code.	*/static char *sccs_id = "@(#)libds.c	1.17 11/6/95 ERL ATT";#if !defined(SUN4) || defined(OS5)/* then no dsp possible, just defined stubs for these routines */int dspopn(name, mode)char *name; int mode;{return 0;}int dsp_old() {return 0;}int dsp_codec() {return 0;}int dsp_freq() {return 0;}char *dsp_ldpath() {return 0;}int dspcls(){return 0;}int dsprg(dsp,reg,data,cash)unsigned int dsp;int reg,data;short *cash;{return 0;}dsptmr(cntr,mode,low,high,stop,run){return 0;}char *dspid(){return 0;}dsprd(dsp,addr,buf,cnt)unsigned dsp, addr;char *buf;int cnt;{return 0;}dspwr(dsp,addr,buf,cnt)unsigned dsp, addr;char *buf;int cnt;{return 0;}char* dspmap(){return 0;}#else#include <stdio.h>#include <fcntl.h>#include <sys/ioctl.h>#include "dsp32.h"#include <sys/mman.h>static	short	dsp_cnt = 0;static	short	c_cntr = 0;#define NAME_LENGTH	80int dbug = 0;static void	env_parse();static int	copyfield();static char    *getdspinfo();static	struct	dflt {		char dsp_name[NAME_LENGTH];		char dsp_ldpath[NAME_LENGTH];		int  dsp_mode;		int  dsp_old;		/* old board (1) */		int  dsp_codec;		/* codec (1) or pcm56 (0) */		int  dsp_freq;		/* serial clock (kHz) */}#ifndef C1122dflt = { "/dev/dsp3", "", 0, 0, 1, 2048 }; /* NEWBOARD, CODEC, 2048kHz */#elsedflt = { "/dev/dsp3", "", 0, 1, 1, 3072 }; /* OLDBOARD, CODEC, 3072kHz */#endifint		dsp_fp	= 0;dspopn(name,mode)char *name;int  mode;{	char *cp, *getenv(), *dspid();	if ( dsp_fp > 0 ) return 0;	if ( name )		strcpy(dflt.dsp_name, name);	if ( (cp=getenv("DSPDEV")) || (cp=getdspinfo("DSPDEV")) )		env_parse(cp, &dflt);	dflt.dsp_mode = mode;	dsp_fp = open(dflt.dsp_name,O_RDWR);	if ( dsp_fp < 0 ) {		return -1;	}	return 0;}dsp_old() { return dflt.dsp_old; }dsp_codec() { return dflt.dsp_codec; }dsp_freq() { return dflt.dsp_freq; }char *dsp_ldpath() { return dflt.dsp_ldpath; }dspcls(){	if ( dsp_fp > 0 )		close(dsp_fp);	dsp_fp=0;}dsprg(dsp,reg,data,cash)unsigned int dsp;int reg,data;short *cash;{	register int i;	struct	{ struct d_cmd cmd; } pkt;	if (dsp_fp==0) dspopn( (char*)0, 1);	if ( (dsp_fp<=0) || (dsp>=64) ) return -1;	pkt.cmd.cmd = (reg & ~C_BLOCK)|DSPST(dsp);	if ( reg & C_WRITE )		pkt.cmd.data[0]= data;	if ( reg == C_RUN ) {		pkt.cmd.data[0] = data;		pkt.cmd.data[1] = data>>16;	}	pkt.cmd.c_cnt = c_cntr++;	if ( (i=ioctl(dsp_fp, DIOCTL, &pkt)) < 0 ) {		perror(" dsprg ");		return(-1);	} else {		if ( pkt.cmd.status & S_ERROR ) {			fprintf(stderr," dsprg error: 0x%4x\n", pkt.cmd.status);			return -1;		} else {			if ( pkt.cmd.status&S_PDR_CASH ) {				register int i;				for( i=1; i<NDATA; i++ )					cash[i] = pkt.cmd.data[i];				cash[0] = NDATA;			}		}		return ( pkt.cmd.data[0]& 0xffff );	}}dsptmr(cntr,mode,low,high,stop,run){	struct	{ struct d_cmd cmd; } pkt;	if (dsp_fp==0) dspopn( (char*)0, 1);	if (dsp_fp<=0) return -1;	if ( dsp_old() ) return -1;	pkt.cmd.cmd = C_TIMER;	pkt.cmd.t_cntr = cntr;	pkt.cmd.t_mode = mode;	pkt.cmd.t_low = low;	pkt.cmd.t_high = high;	pkt.cmd.t_stop = stop;	pkt.cmd.t_run = run;	pkt.cmd.c_cnt = c_cntr++;	if ( ioctl(dsp_fp, DIOCTL, &pkt) < 0 ) {		perror("dsptmr: ");		return -1;	}	if ( pkt.cmd.status & S_ERROR ) {		fprintf(stderr,"S_ERROR = 0x%4x\n",pkt.cmd.status);		return -1;	}	return 0;}char *dspid(){	static struct	{ struct d_cmd cmd; } pkt;	if (dsp_fp==0) dspopn( (char*)0, 1);	if (dsp_fp<=0) return 0;	pkt.cmd.cmd = C_SYSID;	pkt.cmd.data[0] = 0;	pkt.cmd.c_cnt = c_cntr++;	if ( ioctl(dsp_fp, DIOCTL, &pkt) < 0 ) {		perror("dspid: ");		return 0;	}	if ( pkt.cmd.status & S_ERROR ) 		return 0;	else		return (char*) pkt.cmd.data;}dsprd(dsp,addr,buf,cnt)unsigned dsp, addr;char *buf;int cnt;{	int i;	struct	{ struct d_cmd cmd; } pkt;	if (dsp_fp==0) dspopn( (char*)0, 1);	if (dsp_fp<=0) return -1;	addr=addr+(dsp<<16);	if ((i=lseek(dsp_fp,(long)addr,0)) != addr )		fprintf(stderr," lseek: 0x%x\n",i);	if ( (i=read(dsp_fp,buf,cnt)) < 0 )		perror(" dsprd ");	return i;}dspwr(dsp,addr,buf,cnt)unsigned dsp, addr;char *buf;int cnt;{	int i;	struct	{ struct d_cmd cmd; } pkt;	if (dsp_fp==0) dspopn( (char*)0, 1);	if (dsp_fp<=0) return -1;	addr=addr+(dsp<<16);	if ((i=lseek(dsp_fp,(long)addr,0)) != addr )		fprintf(stderr," lseek: 0x%x\n",i);	if ( (i=write(dsp_fp,buf,cnt)) < 0 )		perror(" dspwr ");	return i;}char* dspmap(){  static char *page = (char*)0;  char  *valloc();  int size = getpagesize();    if (dsp_fp <= 0) return (char*) 0;  /* this way we can only get to one board, but     therefore the stupid guys can call is as often     as they want     */  if ( !page ) {    page = valloc( size );    if (mmap(page,size,PROT_READ|PROT_WRITE,	     MAP_SHARED|MAP_FIXED,dsp_fp,0)==(caddr_t)-1) {      perror(" dspmap ");      free(page);      page = (char*) 0;    }  }    return (char*) page;}static char *getdspinfo(key)     char *key;{    /* if info file exists, get the value string for 'key'. */    FILE *info = NULL;    char *val = NULL, *strtok();    int len = 0;    static char line[256];	/* pointer returned to caller */    char *find_esps_file();    char *dspinfo = find_esps_file(NULL,"dspinfo",			      "/etc:$ESPS_BASE/lib/waves/files",			      "ESPS_DSPINFO_PATH");    if (key && *key && (info=fopen(dspinfo,"r"))) { /* key & file? */        while ((fgets(line,256,info))) {	    if (line[0] != '#' && !strncmp(key,line,(len=strlen(key)))) {	        if (strtok(line," \t"))		/* have right line... */		  val=strtok(NULL," \t\n");	/* want second field */		break;	    }	}    }    if (info)      fclose(info);    free(dspinfo);    if (dbug)        fprintf(stderr,"Info: %s = %s\n",key,val);    return val;}static int copyfield(src,dest,delim,maxsize)     char *src, *dest, delim;     int maxsize;{  /* copy string 'till delimiter or null or (maxsize-1) */  int len = 0;  if (src && dest) {    while (*src && *src != delim && ++len < maxsize)      *dest++ = *src++;    *dest = '\0';    if (len < maxsize)      return len;  }  return 0;}static void env_parse(env, state)     char *env;			/* ptr to environment string */     struct dflt *state;		/* dsp board state structure */{  /* MUST NOT CHANGE ENVIRONMENT STRING */  register int len;  register char *key;  char numbuf[10];    while (*env) {    if (*env == ',') {      env++;      continue;    }    else if (*env == '/' &&	/* dsp device name */             (len = copyfield(env,state->dsp_name,',',NAME_LENGTH)) > 0) {      env += len;      continue;    }    else if ((len=strlen(key="PATH=")) && !strncmp(env,key,len)) {      env += len;      if ((len = copyfield(env,state->dsp_ldpath,',',NAME_LENGTH)) > 0)	env += len;      continue;    }    else if ((len=strlen(key="FREQ=")) && !strncmp(env,key,len)) {      env += len;      if ((len = copyfield(env,numbuf,',',10)) > 0 &&	  (state->dsp_freq = atoi(numbuf)) > 0)	env += len;      continue;    }    else if ((len=strlen(key="OLD")) && !strncmp(env,key,len)) {      state->dsp_old = 1;      env += len;      continue;    }    else if ((len=strlen(key="NEW")) && !strncmp(env,key,len)) {      state->dsp_old = 0;      env += len;      continue;    }    else if ((len=strlen(key="CODEC")) && !strncmp(env,key,len)) {      state->dsp_codec = 1;      env += len;      continue;    }    else if ((len=strlen(key="PCM56")) && !strncmp(env,key,len)) {      state->dsp_codec = 0;      env += len;      continue;    }    env++;  }    if (dbug)    fprintf(stderr,"dsp board: DEV=%s PATH=%s\nFREQ=%d CODEC?=%d OLD?=%d\n",	    state->dsp_name,state->dsp_ldpath,state->dsp_freq,	    state->dsp_codec,state->dsp_old);}#endif

⌨️ 快捷键说明

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