void init_sound_system() { char lod_buf[30000]; WORD ltatten, rtatten, ltgain, rtgain; /* Lock Sound System */ locksnd(); /* Save old settings */ ltatten = soundcmd(LTATTEN, -1); rtatten = soundcmd(RTATTEN, -1); ltgain = soundcmd(LTGAIN, -1); rtgain = soundcmd(RTGAIN, -1); /* Reset sound system */ sndstatus(1); /* Restore old settings */ soundcmd(LTATTEN, ltatten); soundcmd(RTATTEN, rtatten); soundcmd(LTGAIN, ltgain); soundcmd(RTGAIN, rtgain); /* Set some necessary parameters */ settracks(0,0); setmontracks(0); setmode(STEREO16); setbuffer(0,sound,sound+sizeof(sound)); soundcmd(ADDERIN, 0x2); soundcmd(ADCINPUT, 0x0); /* DSP side */ dsptristate(ENABLE, ENABLE); dsp_abil = Dsp_RequestUniqueAbility(); /* Dsp_LoadProg(DSP_LOD, dsp_abil, lod_buf); */ Dsp_ExecProg(dsp_bin, sizeof(dsp_bin)/3, dsp_abil); /* Connect DMA playback with DSP and then to DAC */ switch (options.function) { case replay: devconnect(DMAPLAY, DSPRECV, CLK25M, options.prescale, NO_SHAKE); devconnect(DSPXMIT, DAC, CLK25M, options.prescale, NO_SHAKE); break; case record: break; case thru: devconnect(ADC, DSPRECV, CLK25M, options.prescale, NO_SHAKE); devconnect(DSPXMIT, DAC, CLK25M, options.prescale, NO_SHAKE); break; } Dsp_BlkUnpacked(&options.dsp.mono, 1L, 0L, 0L); Dsp_BlkUnpacked(&options.dsp.karaoke, 1L, 0L, 0L); Dsp_BlkUnpacked(&options.dsp.flange, 1L, 0L, 0L); }
/* * float dsp_sin(float x) * x est exprim‚ en degr‚s (pas forc‚ment entiers) * ATTENTION: Ici les angles devraient etre POSITIFS, * En effet, lors de l'interpolation il faut prendre le * point connu PRECEDENT et non suivant, dans le cas de nombres * negatifs... R‚fl‚chissez y! * La fonction retourne le sinus de x * */ float dsp_sin(float deg) { long ret; long *ptr; float d; /* * Conversion des degres en offset dans la table de sinus * du DSP, contenue dans les ROM de celui-ci. * Cette table contient un sinus complet sur 256 points. */ d=(deg*(256.0/360.0)); /* * Donn‚es pour le DSP */ ptr=DspParBlk; *ptr++=SIN; /* On veut un sinus */ *ptr++=trunc(d); /* partie entiŠre de l'angle */ *ptr++=(d-trunc(d))*0x1000000L; /* partie decimale */ Dsp_BlkUnpacked(DspParBlk,3,&ret,1); /* on envoie 3 donn‚es et on recois 1 resultat */ ret=Ext24(ret); /* le resultat est sur 24 bits, il faut l'‚tandre … 32 */ return ((float)ret/0x800000L); /* division par 2^23 pour obtenir la valeur cod‚e */ } /* (codage en virgule fixe) */
int main(void) { DSP_WORD *dsp_prog; FILE * fp; long prog_size; int abil; MATRIX c; long c1[N][N*2]; int i,j; if (Dsp_Lock()) { printf("DSP already in use\n"); return 10; } if (Dsp_Reserve(0x40+N*N,0x1000+N*N*3)) { printf("Can't reserve enough DSP RAM\n"); Dsp_Unlock(); return 10; } /* Now open the DSP file */ fp=fopen(DSP_CODE_FILE,"rb"); if (fp==NULL) { printf("Can't open file " DSP_CODE_FILE "\n"); Dsp_Unlock(); return 10; } /* Now read the DSP file into dsp_prog with the size in dsp words in prog_size */ fseek(fp,0,SEEK_END); prog_size=ftell(fp)/sizeof(DSP_WORD); fseek(fp,0,SEEK_SET); dsp_prog=malloc(prog_size*sizeof(DSP_WORD)); fread(dsp_prog,sizeof(DSP_WORD),prog_size,fp); fclose(fp); abil=Dsp_RequestUniqueAbility(); Dsp_ExecProg(dsp_prog,prog_size,abil); Dsp_BlkUnpacked(0,0,&(c1[0][0]),N*N*2); for (i=0;i<N;i++) for (j=0;j<N;j++) c[i][j]=c1[i][j*2]+(float)(c1[i][j*2+1])/0x800000; showmat(c); Dsp_Unlock(); return 0; }
float dsp_sqr(float x) { long ret; long *ptr; float d; d=x*256.0; ptr=DspParBlk; *ptr++=SQR; *ptr++=trunc(d); *ptr++=(d-trunc(d))*0x1000000L; Dsp_BlkUnpacked(DspParBlk,3,&ret,1); ret=Ext24(ret); return ((float)ret/0x800000L); }
/* * float dsp_cos(float x) * La procedure est identique … dsp_sinus(x) * Retourne le cosinus de x */ float dsp_cos(float deg) { long ret; long *ptr; float d; d=(deg*(256.0/360.0)); ptr=DspParBlk; *ptr++=COS; *ptr++=trunc(d); *ptr++=(d-trunc(d))*0x1000000L; Dsp_BlkUnpacked(DspParBlk,3,&ret,1); ret=Ext24(ret); return ((float)ret/0x800000L); }
void bootdsp() { char *dsp_binptr; long dsp_binsize,dsp_datsize; if((mp2info.sample_frequency==44100L) && !ext) { dsp_binptr=dsp_binint; /* use internal clock */ dsp_binsize = get_bin_len(0)/3; /* dsp_binsize=((long)sizeof(dsp_binint))/3; */ } else { dsp_binptr=dsp_binext; /* use external clock */ dsp_binsize = get_bin_len(1)/3; /* dsp_binsize=((long)sizeof(dsp_binext))/3; */ } /* dsp_codebin=(long)dsp_binptr; dsp_codelen=(int)dsp_binsize; dsp_bootbin=(long)dsp_bootstrap; dsp_bootlen=((int)sizeof(dsp_bootstrap))/3; Supexec(dsp_load); */ Dsp_ExecProg(dsp_binptr, dsp_binsize, 0x42); #ifdef DEBUG printf("DSP bootstrapped\n"); #endif dsp_datsize=get_dat_len()/4; Dsp_BlkUnpacked((long *)dsp_dat, dsp_datsize, 0, 0); #ifdef DEBUG printf("DSP data uploaded\n"); #endif }
/* multiply a by b giving c - returns non-zero if error */ int mult(MATRIX a,MATRIX b,MATRIX c) { DSP_WORD *dsp_prog; FILE * fp; long prog_size; int abil; long a1[N][N],b1[N][N],c1[N][N*2]; int i,j; /* First we need to convert the values to fixed point */ for (i=0;i<N;i++) for (j=0;j<N;j++) { a1[i][j]= 0x800000*a[i][j]; b1[i][j]= 0x800000*b[i][j]; } if (Dsp_Lock()) { printf("DSP already in use\n"); return 10; } if (Dsp_Reserve(0x40+N*N,0x1000+N*N*3)) { printf("Can't reserve enough DSP RAM\n"); Dsp_Unlock(); return 10; } /* Now open the DSP file */ fp=fopen(DSP_CODE_FILE,"rb"); if (fp==NULL) { printf("Can't open file " DSP_CODE_FILE "\n"); Dsp_Unlock(); return 10; } /* Now read the DSP file into dsp_prog with the size in dsp words in prog_size */ fseek(fp,0,SEEK_END); prog_size=ftell(fp)/sizeof(DSP_WORD); fseek(fp,0,SEEK_SET); dsp_prog=malloc(prog_size*sizeof(DSP_WORD)); fread(dsp_prog,sizeof(DSP_WORD),prog_size,fp); fclose(fp); abil=Dsp_RequestUniqueAbility(); Dsp_ExecProg(dsp_prog,prog_size,abil); /* send the data */ Dsp_BlkUnpacked(&a1[0][0],N*N,0,0); Dsp_BlkUnpacked(&b1[0][0],N*N,0,0); Dsp_BlkUnpacked(0,0,&c1[0][0],N*N*2); for (i=0;i<N;i++) for (j=0;j<N;j++) { c[i][j]=c1[i][j*2]*2 +(float)(c1[i][j*2+1])/0x800000; } Dsp_Unlock(); return 0; }