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

📄 soundsrv.c

📁 The source code of Doom legacy for windows
💻 C
📖 第 1 页 / 共 2 页
字号:
// Emacs style mode select   -*- C++ -*- //-----------------------------------------------------------------------------//// $Id: soundsrv.c,v 1.7 2000/09/01 19:34:37 bpereira Exp $//// Copyright (C) 1993-1996 by id Software, Inc.// Portions Copyright (C) 1998-2000 by DooM Legacy Team.//// This program is free software; you can redistribute it and/or// modify it under the terms of the GNU General Public License// as published by the Free Software Foundation; either version 2// of the License, or (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU General Public License for more details.////// $Log: soundsrv.c,v $// Revision 1.7  2000/09/01 19:34:37  bpereira// no message//// Revision 1.6  2000/04/30 19:50:37  metzgermeister// no message//// Revision 1.5  2000/04/28 19:26:10  metzgermeister// musserver fixed, sndserver amplified accordingly//// Revision 1.4  2000/04/22 20:30:00  metzgermeister// fix amplification by 4//// Revision 1.3  2000/03/28 16:18:42  linuxcub// Added a command to the Linux sound-server which sets a master volume.//// Revision 1.2  2000/02/27 00:42:12  hurdler// fix CR+LF problem//// Revision 1.1.1.1  2000/02/22 20:32:33  hurdler// Initial import into CVS (v1.29 pr3)////// DESCRIPTION://      UNIX soundserver, run as a separate process,//       started by DOOM program.//      Originally conceived fopr SGI Irix,//       mostly used with Linux voxware.////-----------------------------------------------------------------------------#include <math.h>#include <sys/types.h>#include <stdio.h>#include <fcntl.h>#include <sys/ioctl.h>#include <unistd.h>#include <stdlib.h>#include <malloc.h>#include <sys/stat.h>#include <sys/time.h>#include "sounds.h"#include "soundsrv.h"extern int audio_8bit_flag;//// Department of Redundancy Department.//typedef struct wadinfo_struct{    // should be IWAD    char        identification[4];          int         numlumps;    int         infotableofs;    } wadinfo_t;typedef struct filelump_struct{    int         filepos;    int         size;    char        name[8];    } filelump_t;// an internal time keeperstatic int      mytime = 0;// number of sound effectsint             numsounds;// longest sound effectint             longsound;// lengths of all sound effectsint             lengths[NUMSFX];// mixing buffersigned short    mixbuffer[MIXBUFFERSIZE];// file descriptor of sfx deviceint             sfxdevice;                      // file descriptor of music deviceint             musdevice;                      // the channel data pointersunsigned char*  channels[8];// the channel step amountunsigned int    channelstep[8];// 0.16 bit remainder of last stepunsigned int    channelstepremainder[8];// the channel data end pointersunsigned char*  channelsend[8];// time that the channel started playingint             channelstart[8];// the channel handlesint             channelhandles[8];// the channel left volume lookup// int*            channelleftvol_lookup[8];// the channel right volume lookup// int*            channelrightvol_lookup[8];// sfx id of the playing sound effectint             channelids[8];                  int             snd_verbose=1;int             steptable[256];// int             vol_lookup[128*256];int             volume_lookup[128][256];int             master_volume=31; /* 0..31 */int             left_volume[8],right_volume[8];static void derror(char* msg){    fprintf(stderr, "error: %s\n", msg);    exit(-1);}int mix(void){    register unsigned int       sample;    register int                dl;    register int                dr;    unsigned short              sdl;    unsigned short              sdr;        signed short*               leftout;    signed short*               rightout;    signed short*               leftend;    unsigned char*              bothout;        int                         step;    int                         i;    int                         leftv[8],rightv[8];        for( i=0; i<8; ++i ) {        leftv[i] = left_volume[i]*master_volume/31;        rightv[i] = right_volume[i]*master_volume/31;    }    leftout = mixbuffer;    rightout = mixbuffer+1;    bothout = (unsigned char *)mixbuffer;    step = 2;    leftend = mixbuffer + SAMPLECOUNT*step;    // mix into the mixing buffer    while (leftout != leftend)    {        dl = 0;        dr = 0;        if (channels[0])        {            sample = *channels[0];            // dl += channelleftvol_lookup[0][sample];            dl += volume_lookup[leftv[0]][sample];            // dr += channelrightvol_lookup[0][sample];            dr += volume_lookup[rightv[0]][sample];            channelstepremainder[0] += channelstep[0];            channels[0] += channelstepremainder[0] >> 16;            channelstepremainder[0] &= 65536-1;            if (channels[0] >= channelsend[0])                channels[0] = 0;        }        if (channels[1])        {            sample = *channels[1];            // dl += channelleftvol_lookup[1][sample];            dl += volume_lookup[leftv[1]][sample];            // dr += channelrightvol_lookup[1][sample];            dr += volume_lookup[rightv[1]][sample];            channelstepremainder[1] += channelstep[1];            channels[1] += channelstepremainder[1] >> 16;            channelstepremainder[1] &= 65536-1;            if (channels[1] >= channelsend[1])                channels[1] = 0;        }        if (channels[2])        {            sample = *channels[2];            // dl += channelleftvol_lookup[2][sample];            dl += volume_lookup[leftv[2]][sample];            // dr += channelrightvol_lookup[2][sample];            dr += volume_lookup[rightv[2]][sample];            channelstepremainder[2] += channelstep[2];            channels[2] += channelstepremainder[2] >> 16;            channelstepremainder[2] &= 65536-1;            if (channels[2] >= channelsend[2])                channels[2] = 0;        }                if (channels[3])        {            sample = *channels[3];            // dl += channelleftvol_lookup[3][sample];            dl += volume_lookup[leftv[3]][sample];            // dr += channelrightvol_lookup[3][sample];            dr += volume_lookup[rightv[3]][sample];            channelstepremainder[3] += channelstep[3];            channels[3] += channelstepremainder[3] >> 16;            channelstepremainder[3] &= 65536-1;            if (channels[3] >= channelsend[3])                channels[3] = 0;        }                if (channels[4])        {            sample = *channels[4];            // dl += channelleftvol_lookup[4][sample];            dl += volume_lookup[leftv[4]][sample];            // dr += channelrightvol_lookup[4][sample];            dr += volume_lookup[rightv[4]][sample];            channelstepremainder[4] += channelstep[4];            channels[4] += channelstepremainder[4] >> 16;            channelstepremainder[4] &= 65536-1;            if (channels[4] >= channelsend[4])                channels[4] = 0;        }                if (channels[5])        {            sample = *channels[5];            // dl += channelleftvol_lookup[5][sample];            dl += volume_lookup[leftv[5]][sample];            // dr += channelrightvol_lookup[5][sample];            dr += volume_lookup[rightv[5]][sample];            channelstepremainder[5] += channelstep[5];            channels[5] += channelstepremainder[5] >> 16;            channelstepremainder[5] &= 65536-1;            if (channels[5] >= channelsend[5])                channels[5] = 0;        }                if (channels[6])        {            sample = *channels[6];            // dl += channelleftvol_lookup[6][sample];            dl += volume_lookup[leftv[6]][sample];            // dr += channelrightvol_lookup[6][sample];            dr += volume_lookup[rightv[6]][sample];            channelstepremainder[6] += channelstep[6];            channels[6] += channelstepremainder[6] >> 16;            channelstepremainder[6] &= 65536-1;            if (channels[6] >= channelsend[6])                channels[6] = 0;        }        if (channels[7])        {            sample = *channels[7];            // dl += channelleftvol_lookup[7][sample];            dl += volume_lookup[leftv[7]][sample];            // dr += channelrightvol_lookup[7][sample];            dr += volume_lookup[rightv[7]][sample];            channelstepremainder[7] += channelstep[7];            channels[7] += channelstepremainder[7] >> 16;            channelstepremainder[7] &= 65536-1;            if (channels[7] >= channelsend[7])                channels[7] = 0;        }        // Has been char instead of short.        // if (dl > 127) *leftout = 127;        // else if (dl < -128) *leftout = -128;        // else *leftout = dl;        // if (dr > 127) *rightout = 127;        // else if (dr < -128) *rightout = -128;        // else *rightout = dr;                dl <<= 3;        dr <<= 3;        if (!audio_8bit_flag)        {            if (dl > 0x7fff)                *leftout = 0x7fff;            else if (dl < -0x8000)                *leftout = -0x8000;            else                *leftout = dl;            if (dr > 0x7fff)                *rightout = 0x7fff;            else if (dr < -0x8000)                *rightout = -0x8000;            else                *rightout = dr;        }        else        {            if (dl > 0x7fff)                dl = 0x7fff;            else if (dl < -0x8000)                dl = -0x8000;            sdl = dl ^ 0xfff8000;            if (dr > 0x7fff)                dr = 0x7fff;            else if (dr < -0x8000)                dr = -0x8000;

⌨️ 快捷键说明

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