📄 setrate.c
字号:
/* setrate.c *//* * This material contains unpublished, proprietary software of * Entropic Research Laboratory, Inc. Any reproduction, distribution, * or publication of this work must be authorized in writing by Entropic * Research Laboratory, Inc., and must bear the notice: * * "Copyright (c) 1987-1990 AT&T, Inc. * "Copyright (c) 1986-1990 Entropic Speech, Inc. * "Copyright (c) 1990-1991 Entropic Research Laboratory, Inc. * All rights reserved" * * The copyright notice above does not evidence any actual or intended * publication of this source code. * * Written by: * Checked by: * Revised by: * * Brief description: * */static char *sccs_id = "@(#)setrate.c 1.6 10/8/91 ATT/ESI/ERL";/* get the right up/down sampler, for the new DSPboard set clock freq * we also download the sample rate converter programs * freq is in Hz. (not optionally kHz as in earlier versions). * mode = 0/1/2: play only/ record/ play and record * * HISTORY * Originally part of the WAVES system, this module was copied * into the general dsp32 directories on 5/6/88 by mcb. Setrate * now takes a dsp32 program name string as an argument. If this * string is not empty, it will load this program into dsp0. If * no program string is given, it will load `db[mode]' as before. */#include "dsp32.h"#include <stdio.h>#include <esps/epaths.h>/* A flag to indicate whether to use the dsp32/VME buss board: */int use_dsp32 = 1;static char *db[3] = { "dbplay", "dbplrc", "dbrecord"};struct sf { int freq, down, up, sfreq;};static struct sf pcm56[] = { /* Burr Brown PCM56 */ { 6666, 3, 1, 20 }, { 6667, 3, 1, 20 }, { 8000, 3, 1, 24 }, { 10000, 2, 1, 20 }, { 12000, 2, 1, 24 }, { 16000, 3, 2, 24 }, { 20000, 1, 1, 20 }, { 24000, 1, 1, 24 }, { 0, 1, 1, 0 }};static struct sf codec_12[] = { /* AT&T 752x codec */ { 6000, 2, 1, 12 }, { 6666, 9, 5, 12 }, { 6667, 9, 5, 12 }, { 8000, 3, 2, 12 }, {10000, 6, 5, 12 }, {12000, 1, 1, 12 }, {16000, 3, 4, 12 }, {20000, 3, 5, 12 }, {24000, 1, 2, 12 }, { 0, 1, 1, 12 }};static struct sf codec_16[] = { /* AT&T 752x codec */ { 8000, 2, 1, 16 }, { 8888, 9, 5, 16 }, { 8889, 9, 5, 16 }, { 10666, 3, 2, 16 }, {13333, 6, 5, 16 }, {16000, 1, 1, 16 }, {21333, 3, 4, 16 }, {26667, 3, 5, 16 }, {32000, 1, 2, 16 }, { 0, 1, 1, 16 }};dsp32_is_available(){ int didopen; if(dspopn((char*) 0,0) < 0) { return(0); } else return(1);}setrate(path, freq, prog0, mode) char *path, *prog0; unsigned mode; double *freq;{ static int clock = 0; struct sf *p, *q; struct sf *codec; char adprog[80], daprog[80], *dbprog; int err=0, ifreq, cfreq; char *getenv(); char *da_prog, *ad_prog; extern debug_level; if(! use_dsp32) { printf("DSP-32 is not available or not enabled.\n"); return(-2); } if ( *freq < 1.0 ) *freq = 8000.0; ifreq = 0.5 + *freq; if (getenv("CODEC16")) { codec = codec_16; fprintf(stderr,"setrate: using tables for 16Khz\n"); } else codec = codec_12; q = p = ( dsp_codec() ) ? codec : pcm56; for( cfreq = 0 ; p->freq; p++ ) if ( ifreq == p->freq ) { if ( p->sfreq ) cfreq = p->sfreq; break; } if ( !cfreq ) { /* couldn't find exact match, try closest */ int diff, ad; cfreq = ( dsp_freq()*500 ) / ifreq; for( cfreq = 0, diff = 1000000 ; q->freq; q++ ) { if((ad = ifreq - q->freq) < 0) ad = -ad; if ( ad < diff ) { diff = ad; cfreq = q->sfreq; p = q; } } printf("Convertor can not be run at exactly %f Hz.; using %d Hz,\n", *freq,p->freq); *freq = p->freq; } cfreq = dsp_freq()/(2*cfreq); if(mode&8) sprintf(daprog, "1to0"); else sprintf(daprog, "%dto%d\0", p->up, p->down); sprintf(adprog, "%dto%d\0", p->down, p->up); if(!(da_prog = FIND_FAB2_BIN(NULL,daprog))) { fprintf(stderr,"setrate: cannot find dsp code: %s\n",daprog); return -1; } if(!(ad_prog = FIND_FAB2_BIN(NULL,adprog))) { fprintf(stderr,"setrate: cannot find dsp code: %s\n",adprog); return -1; } if(debug_level) fprintf(stderr,"setrate: da_prog: %s, ad_prog: %s\n",da_prog,ad_prog); if ( !dsp_codec() ) { da_prog = (char*)realloc(da_prog,strlen(da_prog)+3); strcat(da_prog,"p"); } if ( !dsp_old() && (clock-cfreq) ) dsptmr(0, TMR_MODE, cfreq, cfreq, 7, 7); clock = cfreq; if ( prog0 && *prog0) { /* load this prog, if given */ if ( dspld(0,prog0) < 0 ) err = 1; } else { /* load mode default program */ if ( (mode&3) < 3 ) { dbprog = FIND_FAB2_BIN(NULL,db[mode&3]); if (dbprog && (dspld(0,dbprog) < 0) ) err = 1; if (dbprog) free(dbprog); } } if ( dspld(1,da_prog) < 0 ) err = -1; if ( dspld(2,ad_prog) < 0 ) err = -1; if (da_prog) free(da_prog); if (ad_prog) free(ad_prog); return err;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -