亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? i_sound.c

?? 游戲類程序源代碼---WinDoom 3D源程序.zip
?? C
?? 第 1 頁 / 共 2 頁
字號:
// Emacs style mode select   -*- C++ -*- 
//-----------------------------------------------------------------------------
//
// $Id:$
//
// Copyright (C) 1993-1996 by id Software, Inc.
//
// This source is available for distribution and/or modification
// only under the terms of the DOOM Source Code License as
// published by id Software. All rights reserved.
//
// The source is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
// for more details.
//
// $Log:$
//
// DESCRIPTION:
//	System interface for sound.
//
//-----------------------------------------------------------------------------

static const char
rcsid[] = "$Id: i_unix.c,v 1.5 1997/02/03 22:45:10 b1 Exp $";

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

#include <math.h>

#include <time.h>
#include <sys/types.h>

//#ifndef LINUX
//#include <sys/filio.h>
//#endif

#include <fcntl.h>
#include <io.h>
//#include <unistd.h>
//#include <sys/ioctl.h>

// Linux voxware output.
//#include <linux/soundcard.h>

// Timer stuff. Experimental.
#include <time.h>
#include <signal.h>

#include "z_zone.h"

#include "i_system.h"
#include "i_sound.h"
#include "m_argv.h"
#include "m_misc.h"
#include "w_wad.h"

#include "doomdef.h"


////////////////////////////////////////////////////////////////////////////
// WinDoom - DirectSound
////////////////////////////////////////////////////////////////////////////
#include <dsound.h>

char MsgText[256];
void WriteDebug(char *);

#define NUM_SOUND_FX 128
#define SB_SIZE      20480

void CreateSoundBuffer(int Channel, int length, unsigned char *data);
void I_PlaySoundEffect(int sfxid, int Channel, int volume, int pan);
void DS_Error( HRESULT hresult, char *msg );

#define NUM_DSBUFFERS 256

typedef enum { dsb_perm, dsb_temp } dsb_type;

extern LPDIRECTSOUND        lpDS;
extern LPDIRECTSOUNDBUFFER  lpDSBuffer[NUM_DSBUFFERS];

typedef struct
   {
    void   *origin;
    int     dsb_type;
    int     sfxid;
   }DSBControl_t;

DSBControl_t DSBControl[NUM_DSBUFFERS];

extern int swap_stereo;

////////////////////////////////////////////////////////////////////////////

// UNIX hack, to be removed.
#ifdef SNDSERV
// Separate sound server process.
FILE*	sndserver=0;
char*	sndserver_filename = "./sndserver ";
#elif SNDINTR

// Update all 30 millisecs, approx. 30fps synchronized.
// Linux resolution is allegedly 10 millisecs,
//  scale is microseconds.
#define SOUND_INTERVAL     500

// Get the interrupt. Set duration in millisecs.
int I_SoundSetTimer( int duration_of_tick );
void I_SoundDelTimer( void );
#else
// None?
#endif


// A quick hack to establish a protocol between
// synchronous mix buffer updates and asynchronous
// audio writes. Probably redundant with gametic.
static int flag = 0;

// The number of internal mixing channels,
//  the samples calculated for each mixing step,
//  the size of the 16bit, 2 hardware channel (stereo)
//  mixing buffer, and the samplerate of the raw data.


// Needed for calling the actual sound output.
#define SAMPLECOUNT		512
#define NUM_CHANNELS		16
// It is 2 for 16bit, and 2 for two channels.
#define BUFMUL                  4
#define MIXBUFFERSIZE		(SAMPLECOUNT*BUFMUL)

#define SAMPLERATE		11025	// Hz
#define SAMPLESIZE		2   	// 16bit

// The actual lengths of all sound effects.
int 		lengths[NUMSFX];

// The actual output device.
int	audio_fd;

// The global mixing buffer.
// Basically, samples from all active internal channels
//  are modifed and added, and stored in the buffer
//  that is submitted to the audio device.
signed short	mixbuffer[MIXBUFFERSIZE];


// The channel step amount...
unsigned int	channelstep[NUM_CHANNELS];
// ... and a 0.16 bit remainder of last step.
unsigned int	channelstepremainder[NUM_CHANNELS];


// The channel data pointers, start and end.
unsigned char*	channels[NUM_CHANNELS];
unsigned char*	channelsend[NUM_CHANNELS];


// Time/gametic that the channel started playing,
//  used to determine oldest, which automatically
//  has lowest priority.
// In case number of active sounds exceeds
//  available channels.
int		channelstart[NUM_CHANNELS];

// The sound in channel handles,
//  determined on registration,
//  might be used to unregister/stop/modify,
//  currently unused.
int 		channelhandles[NUM_CHANNELS];

// SFX id of the playing sound effect.
// Used to catch duplicates (like chainsaw).
int		channelids[NUM_DSBUFFERS];

// Pitch to stepping lookup, unused.
int		steptable[256];

// Volume lookups.
int		vol_lookup[128*256];

// Hardware left and right channel volume lookup.
int*		channelleftvol_lookup[NUM_CHANNELS];
int*		channelrightvol_lookup[NUM_CHANNELS];


//
// Safe ioctl, convenience.
//
void
myioctl
( int	fd,
  int	command,
  int*	arg )
{   
// FIXME
/*
    int		rc;
    extern int	errno;
    
    rc = ioctl(fd, command, arg);  
    if (rc < 0)
    {
	fprintf(stderr, "ioctl(dsp,%d,arg) failed\n", command);
	fprintf(stderr, "errno=%d\n", errno);
	exit(-1);
    }
*/
}





//
// This function loads the sound data from the WAD lump,
//  for single sound.
//
void *getsfx( char *sfxname, int *len )
   {
    unsigned char*      sfx;
    unsigned char*      paddedsfx;
    int                 i;
    int                 size;
    int                 paddedsize;
    char                name[20];
    int                 sfxlump;

   
    sprintf(name, "ds%s", sfxname);

    // Get the sound data from the WAD, allocate lump
    //  in zone memory.
    // Now, there is a severe problem with the
    //  sound handling, in it is not (yet/anymore)
    //  gamemode aware. That means, sounds from
    //  DOOM II will be requested even with DOOM
    //  shareware.
    // The sound list is wired into sounds.c,
    //  which sets the external variable.
    // I do not do runtime patches to that
    //  variable. Instead, we will use a
    //  default sound for replacement.

    if ( W_CheckNumForName(name) == -1 )
      sfxlump = W_GetNumForName("dspistol");
    else
      sfxlump = W_GetNumForName(name);
    
    size = W_LumpLength( sfxlump );

//    sprintf(MsgText, "Getting sound effect : %s - %d\n", name, size);
//    WriteDebug(MsgText);

    // Debug.
    // fprintf( stderr, "." );
    //fprintf( stderr, " -loading  %s (lump %d, %d bytes)\n",
    //	     sfxname, sfxlump, size );
    //fflush( stderr );
    
    sfx = (unsigned char*)W_CacheLumpNum( sfxlump, PU_STATIC );

    // Pads the sound effect out to the mixing buffer size.
    // The original realloc would interfere with zone memory.
    paddedsize = ((size-8 + (SAMPLECOUNT-1)) / SAMPLECOUNT) * SAMPLECOUNT;

    // Allocate from zone memory.
    paddedsfx = (unsigned char*)Z_Malloc( paddedsize+8, PU_STATIC, 0 );
    // ddt: (unsigned char *) realloc(sfx, paddedsize+8);
    // This should interfere with zone memory handling,
    //  which does not kick in in the soundserver.

    // Now copy and pad.
    memcpy(  paddedsfx, sfx, size );
    for (i = size; i < paddedsize+8; i++)
        paddedsfx[i] = 128;

    // Remove the cached lump.
    Z_Free( sfx );
    
    // Preserve padded length.
    *len = paddedsize;

    // Return allocated padded data.
    return (void *) (paddedsfx + 8);
   }



/*

//
// This function adds a sound to the
//  list of currently active sounds,
//  which is maintained as a given number
//  (eight, usually) of internal channels.
// Returns a handle.
//
int addsfx( int sfxid, int volume, int step, int seperation )
   {
    static unsigned short	handlenums = 0;
 
    int		i;
    int		rc = -1;
    
    int		oldest = gametic;
    int		oldestnum = 0;
    int		slot;

    int		rightvol;
    int		leftvol;

    int     iVolume, iPan;

    // Chainsaw troubles.
    // 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 )
       {
        // Loop all channels, check.
        for (i = 0; i < NUM_CHANNELS; i++)
           {
            // Active, and using the same SFX?
            if ( (channels[i]) && (channelids[i] == sfxid) )
               {
                // Reset.
                channels[i] = 0;
                // We are sure that iff, there will only be one.
                break;
               }
           }
       }

    // Loop all channels to find oldest SFX.
    for (i = 0; (i<NUM_CHANNELS) && (channels[i]); i++)
        {
         if (channelstart[i] < oldest)
            {
             oldestnum = i;
             oldest = channelstart[i];
            }
        }

    // Tales from the cryptic.
    // If we found a channel, fine.
    // If not, we simply overwrite the first one, 0.
    // Probably only happens at startup.
    if (i == NUM_CHANNELS)
        slot = oldestnum;
    else
        slot = i;

    // Okay, in the less recent channel,
    //  we will handle the new SFX.
    // Set pointer to raw data.
    channels[slot] = (unsigned char *) S_sfx[sfxid].data;
    // Set pointer to end of raw data.
    channelsend[slot] = channels[slot] + lengths[sfxid];

    // Reset current handle number, limited to 0..100.
    if (!handlenums)
        handlenums = 100;

    // Assign current handle number.
    // Preserved so sounds could be stopped (unused).
    channelhandles[slot] = rc = handlenums++;

    // Set stepping???
    // Kinda getting the impression this is never used.
    channelstep[slot] = step;
    // ???
    channelstepremainder[slot] = 0;
    // Should be gametic, I presume.
    channelstart[slot] = gametic;

    iVolume = 0-(128*(15-volume));
    if (iVolume < -10000)
       iVolume == -10000;
    iPan = (seperation-128)*20;
    if (iPan < -10000)
       iPan = -10000;
    if (iPan > 10000)
       iPan = 10000;

    if (swap_stereo == TRUE)
       iPan *= -1;

    // Separation, that is, orientation/stereo.
    //  range is: 1 - 256

    seperation += 1;

    // Per left/right channel.
    //  x^2 seperation,
    //  adjust volume properly.
    leftvol = volume - ((volume*seperation*seperation) >> 16); //(256*256);
    seperation = seperation - 257;
    rightvol = volume - ((volume*seperation*seperation) >> 16);

    // Sanity check, clamp volume.
    if (rightvol < 0 || rightvol > 127)
        I_Error("rightvol out of bounds");
    
    if (leftvol < 0 || leftvol > 127)
        I_Error("leftvol out of bounds");
    
    // Get the proper lookup table piece
    //  for this volume level???
    channelleftvol_lookup[slot] = &vol_lookup[leftvol*256];
    channelrightvol_lookup[slot] = &vol_lookup[rightvol*256];

    // Preserve sound SFX id,
    //  e.g. for avoiding duplicates of chainsaw.
    channelids[slot] = sfxid;

    I_PlaySoundEffect(sfxid, iVolume, iPan);

    // You tell me.
    //return rc;
    return sfxid;
   }

*/
//
// This function adds a sound to the
//  list of currently active sounds,
//  which is maintained as a given number
//  (eight, usually) of internal channels.
// Returns a handle.
//
int addsfx( int sfxid, int volume, int step, int seperation, void *origin )
   {
    static unsigned short	handlenums = 0;
 
    int		i;
    int		rc = -1;
    
    int		oldest = gametic;
    int		oldestnum = 0;
    int		slot;

    int		rightvol;
    int		leftvol;

    int     iVolume, iPan;
    DWORD   dwDSBStatus;
    int     dsbchannel;

    // Chainsaw troubles.
    // 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 )
        dsbchannel = sfxid;
    else
       {
        dsbchannel = sfxid;
        if (lpDSBuffer[0] != 0)
            lpDSBuffer[sfxid]->lpVtbl->GetStatus(lpDSBuffer[sfxid], &dwDSBStatus);
        else
            dwDSBStatus = DS_OK;
        if (dwDSBStatus == DSBSTATUS_PLAYING)
           {
            for (i = NUMSFX; i < NUM_DSBUFFERS; i++)
               {
                if ((DSBControl[i].origin == origin) && (DSBControl[i].sfxid == sfxid))
                   {
                    dsbchannel = i;
                    break;
                   }
                if (DSBControl[i].sfxid == -1)
                   {
                    dsbchannel = i;
                    DSBControl[i].origin = origin;
                    break;
                   }
                if (DSBControl[i].sfxid >= 0)
                   {
                    lpDSBuffer[i]->lpVtbl->GetStatus(lpDSBuffer[i], &dwDSBStatus);
                    if (dwDSBStatus != DSBSTATUS_PLAYING)
                       {
                        dsbchannel = i;
                        DSBControl[i].origin = origin;
                        break;
                       }
                   }
                if (DSBControl[i].origin == origin)
                   {
                    dsbchannel = i;
                    break;
                   }
               }
           }
       }

    iVolume = 0-(128*(15-volume));
    if (iVolume < -10000)
       iVolume == -10000;
    iPan = (seperation-128)*20;
    if (iPan < -10000)
       iPan = -10000;
    if (iPan > 10000)
       iPan = 10000;

    if (swap_stereo == TRUE)
       iPan *= -1;

    // Preserve sound SFX id,
    //  e.g. for avoiding duplicates of chainsaw.
    channelids[dsbchannel] = sfxid;

    I_PlaySoundEffect(sfxid, dsbchannel, iVolume, iPan);

    // You tell me.
    //return rc;
    return dsbchannel;
   }

// This function call starts a sound playing in a DirectSound buffer...
void I_PlaySoundEffect(int sfxid, int Channel, int iVolume, int iPan)
   {
    HRESULT hresult;
    DWORD   dwDSBStatus;

    if (Channel > NUM_SOUND_FX)
       {
        //WriteDebug("Invalid sound channel...\n");
        return;
       }
    if (lpDSBuffer[Channel] == 0)
       {
        //WriteDebug("Trying to play sound without DirectSound working...\n");
        return;
       }

    if ((DSBControl[Channel].dsb_type == dsb_temp) && (DSBControl[Channel].sfxid != sfxid))
       {
        if (DSBControl[Channel].sfxid > 0)
           {
/*
            lpDSBuffer[Channel]->lpVtbl->GetStatus(lpDSBuffer[Channel], &dwDSBStatus);
            if (dwDSBStatus == DSBSTATUS_PLAYING)
               {
                hresult = lpDSBuffer[Channel]->lpVtbl->Stop(lpDSBuffer[Channel]);
                if (hresult != DS_OK)
                    DS_Error(hresult, "lpDSBuffer.Stop");
               }
*/
            lpDSBuffer[Channel]->lpVtbl->Release(lpDSBuffer[Channel]);
            DSBControl[Channel].sfxid = -1;
           }

        if (DSBControl[Channel].sfxid < 0)
           {
            // clone temp buffer here...
            lpDS->lpVtbl->DuplicateSoundBuffer(lpDS, lpDSBuffer[sfxid], &lpDSBuffer[Channel]);
            DSBControl[Channel].sfxid = sfxid;
           }
       }
/*
    else
       {
        lpDSBuffer[Channel]->lpVtbl->GetStatus(lpDSBuffer[Channel], &dwDSBStatus);
        if (dwDSBStatus == DSBSTATUS_PLAYING)
           {
            hresult = lpDSBuffer[Channel]->lpVtbl->Stop(lpDSBuffer[Channel]);
            if (hresult != DS_OK)
                DS_Error(hresult, "lpDSBuffer.Stop");
           }
       }
*/
    hresult = lpDSBuffer[Channel]->lpVtbl->SetCurrentPosition(lpDSBuffer[Channel], 0);
    if (hresult != DS_OK)
        DS_Error(hresult, "lpDSBuffer.SetCurrentPosition");
    hresult = lpDSBuffer[Channel]->lpVtbl->SetVolume(lpDSBuffer[Channel], iVolume );
    if (hresult != DS_OK)
        DS_Error(hresult, "lpDSBuffer.SetVolume");
    hresult = lpDSBuffer[Channel]->lpVtbl->SetPan(lpDSBuffer[Channel], iPan);
    if (hresult != DS_OK)
        DS_Error(hresult, "lpDSBuffer.SetPan");
    hresult = lpDSBuffer[Channel]->lpVtbl->Play(lpDSBuffer[Channel], 0, 0, 0);
    if (hresult != DS_OK)
        DS_Error(hresult, "lpDSBuffer.Play");
   }

//
// SFX API
// Note: this was called by S_Init.
// However, whatever they did in the
// old DPMS based DOS version, this

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲天堂网中文字| 99国产精品久久久久久久久久久| 国产乱码字幕精品高清av| 91在线国产福利| 日韩欧美一级二级三级| 亚洲精品免费一二三区| 国产精品中文字幕欧美| 91精品欧美一区二区三区综合在| 欧美国产日韩精品免费观看| 青青草国产精品亚洲专区无| 99久久久久久| 欧美国产欧美亚州国产日韩mv天天看完整 | 日韩欧美你懂的| 亚洲午夜羞羞片| 91免费精品国自产拍在线不卡| 久久久一区二区| 日本美女一区二区| 日本精品一区二区三区高清 | 91精品蜜臀在线一区尤物| 国产精品高清亚洲| 粉嫩av一区二区三区| 亚洲资源在线观看| 成人白浆超碰人人人人| 久久夜色精品一区| 国产九九视频一区二区三区| 日韩亚洲欧美在线观看| 日韩av在线播放中文字幕| 欧美日韩中字一区| 亚洲综合色自拍一区| 色哟哟在线观看一区二区三区| 国产精品久久久久久久久免费樱桃| 极品尤物av久久免费看| 欧美精品一区二区高清在线观看| 日本vs亚洲vs韩国一区三区二区| 欧美精三区欧美精三区| 日韩在线卡一卡二| 日韩一区二区不卡| 狠狠色丁香久久婷婷综合丁香| 欧美电影免费观看高清完整版在线观看 | 日韩视频永久免费| 精品一区二区三区免费视频| 337p日本欧洲亚洲大胆精品| 国产老女人精品毛片久久| 国产天堂亚洲国产碰碰| 成人v精品蜜桃久久一区| 国产精品国产馆在线真实露脸| 91色婷婷久久久久合中文| 亚洲欧美偷拍三级| 在线免费观看日本一区| 丝袜美腿亚洲一区| 欧美哺乳videos| 国产成人精品免费看| 亚洲视频1区2区| 欧美日韩亚洲综合在线| 国内外成人在线视频| 国产精品入口麻豆九色| 91久久精品日日躁夜夜躁欧美| 亚洲777理论| 久久只精品国产| 成人黄色国产精品网站大全在线免费观看 | 精品国产乱子伦一区| 成人高清在线视频| 性久久久久久久久久久久| 欧美精品一区视频| www.日韩在线| 麻豆精品在线观看| 亚洲精品免费一二三区| 欧美成人vr18sexvr| 色婷婷综合久色| 男女男精品视频网| 亚洲欧美aⅴ...| 91麻豆精品国产91久久久久| 国产a久久麻豆| 亚洲成av人综合在线观看| 2017欧美狠狠色| 欧美亚洲丝袜传媒另类| 国产成人精品www牛牛影视| 亚洲一区视频在线观看视频| 久久久91精品国产一区二区三区| 色呦呦国产精品| 国产精品影视天天线| 亚洲mv大片欧洲mv大片精品| 欧美国产一区在线| 欧美一区二区三区免费| 99re8在线精品视频免费播放| 日韩精品三区四区| 尤物视频一区二区| 亚洲国产精品av| 欧美一卡二卡三卡四卡| 日本精品免费观看高清观看| 国产麻豆一精品一av一免费| 亚洲一区电影777| 国产精品国产三级国产aⅴ入口 | 日韩一区二区三区三四区视频在线观看 | 一本到一区二区三区| 国产一区二区三区最好精华液| 亚洲一区二区精品3399| 日韩毛片精品高清免费| 欧美激情一区二区三区蜜桃视频| 欧美一区二区三区视频免费播放 | 精品视频在线免费看| 暴力调教一区二区三区| 国产在线精品视频| 蜜桃av噜噜一区| 午夜视频一区在线观看| 亚洲人成精品久久久久久 | 成人动漫在线一区| 黄色精品一二区| 久久成人精品无人区| 蜜桃视频一区二区| 奇米影视在线99精品| 日日摸夜夜添夜夜添亚洲女人| 亚洲成人777| 日韩国产一区二| 麻豆成人久久精品二区三区红| 日韩国产在线观看| 麻豆91在线看| 国产伦精品一区二区三区免费迷 | 国产精品一二三区| 国产·精品毛片| 97成人超碰视| 欧美日韩一区在线观看| 欧美三级电影网| 欧美日韩免费一区二区三区视频 | 蜜桃精品视频在线观看| 国精产品一区一区三区mba视频| 狠狠色丁香婷综合久久| 丁香婷婷综合五月| voyeur盗摄精品| 一本久久精品一区二区| 91国偷自产一区二区开放时间 | 国产色综合久久| 日韩欧美中文字幕制服| 欧美xxxxx裸体时装秀| 精品成人在线观看| 日韩欧美高清一区| 26uuu精品一区二区在线观看| 欧美mv和日韩mv国产网站| 2020日本不卡一区二区视频| 久久久久久9999| 国产精品美女久久久久久久久| 久久免费看少妇高潮| 亚洲另类在线一区| 亚洲午夜电影网| 丝袜亚洲精品中文字幕一区| 日本中文字幕一区二区视频| 亚洲电影视频在线| 日韩在线一二三区| 国产在线观看一区二区| 夫妻av一区二区| 欧美一区二区网站| 精品国产99国产精品| 国产午夜精品一区二区三区视频 | 成人免费视频app| 97精品电影院| 精品久久久久久久久久久院品网| www久久久久| 亚洲欧美在线观看| 一片黄亚洲嫩模| 国产成人8x视频一区二区| 91色porny在线视频| 欧美精品123区| 日本一区二区三区视频视频| 国产精品国产三级国产普通话三级 | 中文字幕精品三区| 亚洲午夜久久久久久久久电影院 | 色噜噜狠狠成人中文综合 | 欧美日本国产视频| 久久影音资源网| 亚洲视频在线一区二区| 香蕉乱码成人久久天堂爱免费| 国产在线麻豆精品观看| 国产成人啪免费观看软件| 成人妖精视频yjsp地址| 欧美日韩免费高清一区色橹橹| 26uuu色噜噜精品一区| 一区二区视频在线| 国产一区91精品张津瑜| 色婷婷av一区二区| 最新成人av在线| 蜜臀国产一区二区三区在线播放| 麻豆视频观看网址久久| 免费成人在线网站| 欧美艳星brazzers| 欧美国产日产图区| 久久疯狂做爰流白浆xx| 欧美日韩一区中文字幕| 国产精品你懂的在线| 国产福利91精品一区| 91精品国产综合久久久久久久 | 91精品欧美一区二区三区综合在| 精品蜜桃在线看| 久久精品久久综合| 欧美中文字幕久久| 国产精品不卡在线| 久久精品国产99久久6| 日韩欧美久久久| 五月天丁香久久| 91久久精品网| 亚洲国产精品影院|