?? soundsrv.c
字號:
sdr = dr ^ 0xfff8000; *bothout++ = (((sdr + sdl) / 2) >> 8); } leftout += step; rightout += step; } return 1;}static struct timeval last={0,0};//static struct timeval now;static struct timezone whocares;void updatesounds(void){ mix(); I_SubmitOutputBuffer(mixbuffer, SAMPLECOUNT);}intaddsfx( int sfxid, int volume, int step, int seperation ){ static unsigned short handlenums = 0; int i; int rc = -1; int oldest = mytime; int oldestnum = 0; int slot; int rightvol; int leftvol; // play these sound effects // only one at a time if ( sfxid == sfx_sawup || sfxid == sfx_sawidl || sfxid == sfx_sawful || sfxid == sfx_sawhit || sfxid == sfx_stnmov || sfxid == sfx_pistol ) { for (i=0 ; i<8 ; i++) { if (channels[i] && channelids[i] == sfxid) { channels[i] = 0; break; } } } for (i=0 ; i<8 && channels[i] ; i++) { if (channelstart[i] < oldest) { oldestnum = i; oldest = channelstart[i]; } } if (i == 8) slot = oldestnum; else slot = i; channels[slot] = (unsigned char *) S_sfx[sfxid].data; channelsend[slot] = channels[slot] + lengths[sfxid]; if (!handlenums) handlenums = 100; channelhandles[slot] = rc = handlenums++; channelstep[slot] = step; channelstepremainder[slot] = 0; channelstart[slot] = mytime; // (range: 1 - 256) seperation += 1; // (x^2 seperation) leftvol = volume - (volume*seperation*seperation)/(256*256); seperation = seperation - 257; // (x^2 seperation) rightvol = volume - (volume*seperation*seperation)/(256*256); // sanity check if (rightvol < 0 || rightvol > 127) derror("rightvol out of bounds"); if (leftvol < 0 || leftvol > 127) derror("leftvol out of bounds"); // get the proper lookup table piece // for this volume level // channelleftvol_lookup[slot] = &vol_lookup[(leftvol*master_volume/31)*256]; // channelrightvol_lookup[slot] = &vol_lookup[(rightvol*master_volume/31)*256]; left_volume[slot] = leftvol; right_volume[slot] = rightvol; channelids[slot] = sfxid; return rc;}void outputushort(int num){ static unsigned char buff[5] = { 0, 0, 0, 0, '\n' }; static char* badbuff = "xxxx\n"; // outputs a 16-bit # in hex or "xxxx" if -1. if (num < 0) { write(1, badbuff, 5); } else { buff[0] = num>>12; buff[0] += buff[0] > 9 ? 'a'-10 : '0'; buff[1] = (num>>8) & 0xf; buff[1] += buff[1] > 9 ? 'a'-10 : '0'; buff[2] = (num>>4) & 0xf; buff[2] += buff[2] > 9 ? 'a'-10 : '0'; buff[3] = num & 0xf; buff[3] += buff[3] > 9 ? 'a'-10 : '0'; write(1, buff, 5); }}void initdata(void){ int i; int j; int* steptablemid = steptable + 128; for (i=0 ; i<sizeof(channels)/sizeof(unsigned char *) ; i++) { channels[i] = 0; } gettimeofday(&last, &whocares); for (i=-128 ; i<128 ; i++) steptablemid[i] = pow(2.0, (i/64.0))*65536.0; // generates volume lookup tables // which also turn the unsigned samples // into signed samples // for (i=0 ; i<128 ; i++) // for (j=0 ; j<256 ; j++) // vol_lookup[i*256+j] = (i*(j-128))/127; for (i=0 ; i<128 ; i++) for (j=0 ; j<256 ; j++) // vol_lookup[i*256+j] = (i*(j-128)*256)/127; volume_lookup[i][j] = (i*(j-128)*256)/127;}void quit(void){ I_ShutdownMusic(); I_ShutdownSound(); exit(0);}fd_set fdset;fd_set scratchset;intmain( int c, char** v ){ int done = 0; int rc; int nrc; int sndnum; int sndcnt = 0; int handle = 0; unsigned char commandbuf[10]; struct timeval zerowait = { 0, 0 }; int step; int vol; int sep; int i; int waitingtofinish=0; // init any data initdata(); I_InitSound(11025, 16); I_InitMusic(); if (snd_verbose) fprintf(stderr, "ready\n"); // parse commands and play sounds until done FD_ZERO(&fdset); FD_SET(0, &fdset); while (!done) { mytime++; if (!waitingtofinish) { do { scratchset = fdset; rc = select(FD_SETSIZE, &scratchset, 0, 0, &zerowait); if (rc > 0) { // fprintf(stderr, "select is true\n"); // got a command nrc = read(0, commandbuf, 1); if (!nrc) { done = 1; rc = 0; } else { //if (snd_verbose) // fprintf(stderr, "cmd: %c", commandbuf[0]); switch (commandbuf[0]) { case 'v': // get master volume read(0, commandbuf, 1); master_volume = (commandbuf[0] & 0x1f); break; case 'p': // play a new sound effect read(0, commandbuf, 4); //if (snd_verbose) //{ // commandbuf[9]=0; // fprintf(stderr, "%s\n", commandbuf); //} // p<snd#><step><vol><sep> sndnum = commandbuf[0]; step = commandbuf[1]; step = steptable[step]; vol = commandbuf[2]; sep = commandbuf[3]; handle = addsfx(sndnum, vol, step, sep); // returns the handle // outputushort(handle); break; case 'l': { int bln,tlen; read(0, &bln, sizeof(int)); //fprintf(stderr,"%d in...\n",bln); S_sfx[sndcnt].data = malloc(bln); // hey, read on a pipewill not always // fill the whole buffer 19990203 by Kin for(tlen = 0; tlen < bln;) { tlen+=read(0, S_sfx[sndcnt].data+tlen, bln-tlen); } lengths[sndcnt] = bln; sndcnt++; break; } case 'q': // no '\n' 19990201 by Kin //read(0, commandbuf, 1); waitingtofinish = 1; rc = 0; break; //case 's': //{ // int fd; // read(0, commandbuf, 3); // commandbuf[2] = 0; // fd = open((char*)commandbuf, O_CREAT|O_WRONLY, 0644); // commandbuf[0] -= commandbuf[0]>='a' ? 'a'-10 : '0'; // commandbuf[1] -= commandbuf[1]>='a' ? 'a'-10 : '0'; // sndnum = (commandbuf[0]<<4) + commandbuf[1]; // write(fd, S_sfx[sndnum].data, lengths[sndnum]); // close(fd); //} //break; default: fprintf(stderr, "Did not recognize command %d\n",commandbuf[0]); break; } } } else if (rc < 0) { quit(); } } while (rc > 0); } updatesounds(); if (waitingtofinish) { for(i=0 ; i<8 && !channels[i] ; i++); if (i==8) done=1; } } quit(); return 0;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -