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

📄 ddsetrate.c

📁 speech signal process tools
💻 C
字号:
/* 	Copyright (c) 1989,1990 AT&T       *//*        All Rights Reserved   *//*      THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T     *//*      The copyright notice above does not evidence any        *//*      actual or intended publication of such source code.     *//* ddsetrate.c *//* Set sample rate of the Ariel A/D-D/A daughter card. */typedef	unsigned long	ulong;/*typedef	unsigned short	ushort;typedef	unsigned int	uint;*/typedef	unsigned char	uchar;#include	<stdio.h>#include	<ctype.h>#include	<errno.h>#include	<sys/ioctl.h>#include	<dsp32c.h>#include	<vme32c.h>extern DC_IO *dcmap();extern int use_dsp32;extern int debug_level;char *getenv();typedef struct freq_entry {  double frequency;  int code;} FREQ_ENT;/* The magic numbers sent to the Ariel interface cause it to   assume the following sample rates:   number 7     6     5     4     3    2    1    0   rate	 96000 48000 24000 12000 6000 3000 1500 750   The multiplier for these rates is determined by a (changeable) crystal on   the Ariel board.   */FREQ_ENT freq_table24[] = { { 96000.0, 7 }, { 48000.0, 6 }, { 24000.0, 5 }, { 12000.0, 4 }, {  6000.0, 3 }, {  3000.0, 2 }, {  1500.0, 1 }, {   750.0, 0 }, {    0.0, -1 }			/* list terminator */};FREQ_ENT freq_table16[] = {{ 64000.0, 7 },{ 32000.0, 6 },{ 16000.0, 5 },{  8000.0, 4 },{  4000.0, 3 },{  2000.0, 2 },{  1000.0, 1 },{   500.0, 0 },{     0.0, -1 }};FREQ_ENT *freq_table;#define	PCF8574A	0x70#define	PCF8574		0x40#define	CAITLIO_A	0#define	CAITLIO_B	2#define TRUE 1#define FALSE 0/*************************************************************************//*dsp32_is_available(){  int dc = dcopen("/dev/dc00");  if(dc >= 0) {    use_dsp32 = 1;    close(dc);  } else    use_dsp32 = 0;  return(use_dsp32);}*//*************************************************************************/closest_freq(rate)     double *rate;{  int i, mini;  double mindif, t, fabs(); if (getenv("ARIEL_16")) {    if (debug_level)      fprintf(stderr,"ddsetrate: using tables for Ariel with 16Mhz crystal\n");     freq_table = freq_table16; } else {    if (debug_level)      fprintf(stderr,"ddsetrate: using tables for Ariel with 24Mhz crystal\n");     freq_table = freq_table24; }  for(i=0, mini = -1, mindif=1.0e6; freq_table[i].code >= 0; i++)    if((t = fabs(freq_table[i].frequency - *rate)) < mindif) {      mindif = t;      mini = i;    }  if(mini < 0) {    mini = 5;    fprintf(stderr,"A frequency close to %f can't be found; using %f\n",	    *rate, freq_table[mini].frequency);  } else    if((float)*rate != (float)freq_table[mini].frequency)      fprintf(stderr, "Can't set rate to %fHz; using %fHz\n",*rate,	      freq_table[mini].frequency);  *rate = freq_table[mini].frequency;  return(freq_table[mini].code);}/*************************************************************************/set_sam_rate(rate,cluster)     double *rate;		/* desired sample rate in Hz */     char *cluster;             /* 'a' for dc00,dc01,dc02; 'b' for dc03... */{  int dsp, data, device;  register DC_IO *mem;  register unsigned short *iic0, *iic1;  data = closest_freq(rate);	/* get magic number corresponding to rate */  /* See Jim Snyder for explanation of the following: *//* *	we have two serial ports, one for each cluster, A and B. *	either cluster may or may not have a caitlio (i.e. serial *	I/O) daughter card. A caitlio card may or may not have an *	8582 configuration EEROM. It may or may not have an 8574 *	serial-to-parallel converter for controlling the sample *	rate. When we get our act together, we'll interrogate the *	EEROM to determine whether there's an 8574. For now, we're *	just assuming the user knows what he's doing. (What a laugh.) *	8574 addresses are 0x40 & 0x41 for cluster A, and 0x42 and 0x43 *	for cluster B. Also we're not taking a sample rate as input, *	we're taking the binary data to be written to the 8574. *	Eventually (like about the time we send this to betas) the *	data the user provides should be sample rate, and the program *	should interrogate the daughter card EEROMs to determine *	what card we're dealing with, and then use built-in tables *	(built-into the program, that is, not the EEROM) to pick up *	the binary value corresponding to that sample rate. Manana .. */  if (!strcmp(cluster, "a") && !getenv("P8574_type"))/* P8574 part (not rev A) */    device = PCF8574 | CAITLIO_A;  else if (!strcmp(cluster, "b") && !getenv("P8574_type")) /* P8574 */    device = PCF8574 | CAITLIO_B;  else if (!strcmp(cluster, "a") && getenv("P8574_type")) /* P8574A */    device = PCF8574A | CAITLIO_A;  else if (!strcmp(cluster, "b") && getenv("P8574_type")) /* P8574A */    device = PCF8574A | CAITLIO_B;  else {    fprintf (stderr,"Bad cluster specified to set_sam_rate(%s)\n",	     cluster);    return(FALSE);  }  if((dsp = dcopen("/dev/dc0io")) >= 0) {    if (!(mem = dcmap(dsp, 1, 0))) {      fprintf (stderr, "set_sam_rate(): dcmap failed\n");      close(dsp);      return(FALSE);    }    iic0 = &(mem->dc_iic1);    iic1 = &(mem->dc_iic2);    iicinit(iic0, iic1);    *iic0 = device | IIC_ADDR_WRITE; /* slave address, write */    *iic1 = 0xC4;		/* master, sio enabled, start, ack */    iicack(iic1, 0);    *iic0 = data;		/* write data to set rate */    iicack(iic1, 1);    *iic1 = 0xC2;		/* write stop *//*    while (!(*iic1 & IIC_STA_BUSFREE));	*/    close(dsp);    return(TRUE);  } else    printf("Can't open /dev/dc0io\n");  return(FALSE);}/*************************************************************************/iicack(i1,flag)     register ushort *i1;     int flag;{  while (*i1 & IIC_STA_PIN);  if (*i1 & (IIC_STA_BUSERR | IIC_STA_NAK)) {    fprintf (stderr, "iicack: bus error, sta=0x%x, flag=0x%x, goodbye!\n",	     *i1 & 0xff, flag);    fprintf (stderr,"\nTry setting the environment variable P8574_type to 0.\n");    fprintf (stderr,"Some Ariel boards have a different version of a chip\n");    fprintf (stderr,"which causes this problem.  See the man page.\n");    fflush(stderr);    exit(1);  }}/*************************************************************************/iicinit(i0, i1)     register ushort *i0, *i1;{  *i0 = 0x10;			/* write "own addr", put chip in 68K mode */  *i1 = 0x20;			/* point to clock select register */  *i0 = 0x18;	    /* load clock select register, 8MHz sysclk + 100Kbitclk */  *i1 = 0x40;			/* enable serial bus */  if (!(*i1 & IIC_STA_BUSFREE)) {    fprintf (stderr, "iicinit: bus busy, goodbye!\n");    fflush (stderr);    exit(1);  }}

⌨️ 快捷键说明

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