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

📄 hw3sound.c

📁 The source code of Doom legacy for windows
💻 C
📖 第 1 页 / 共 2 页
字号:
// Emacs style mode select   -*- C++ -*- //-----------------------------------------------------------------------------//// $Id: hw3sound.c,v 1.1 2001/04/04 19:41:16 judgecutor Exp $//// Copyright (C) 2001 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: hw3sound.c,v $// Revision 1.1  2001/04/04 19:41:16  judgecutor// Initial release of 3D Sound Support//// //// DESCRIPTION://      Hardware 3D sound general code//      ////-----------------------------------------------------------------------------#include "hw3sound.h"#include "../i_sound.h"#include "../s_sound.h"#include "../w_wad.h"#include "../z_zone.h"#include "../g_game.h"#include "../tables.h"#include "../sounds.h"#include "../r_main.h" #include "../r_things.h"#define ANGLE2DEG(x) (((double)(x)) / ((double)ANG45/45))#define MIN_DISTANCE 160.0f#define MAX_DISTANCE 1200.0fstruct hardware3ds_s hw3ds_driver;typedef enum {    CT_NORMAL = 0,    CT_ATTACK,    CT_SCREAM,    CT_AMBIENT} channel_type_t;typedef struct source_s{    sfxinfo_t       *sfxinfo;    void            *origin;    int             handle;     // Internal source handle    channel_type_t  type;       // Sound type (attack, scream, etc)} source_t;typedef struct ambient_sdata_s{    source3D_data_t left;    source3D_data_t right;} ambient_sdata_t;typedef struct ambient_source_s{    source_t    left;    source_t    right;} ambient_source_t;// Static sources// This sources always createsstatic source_t p_attack_source;        // Player attack sourcestatic source_t p_scream_source;        // Player scream source// abuse?//#define STATIC_SOURCES_NUM      0       // Total number of static sourcesstatic ambient_source_t ambient_source; // Ambinet sound sources//  abuse???//static source3D_data_t  p_attack_sdata; // ?? Now just holds precalculated player attack source data//static source3D_data_t  p_default_sdata;// ?? ---- // ---- // ---- // ---- player scream source datastatic ambient_sdata_t  ambient_sdata;  // Precalculated datas of an ambient sound sources// Stack of dynamic sourcesstatic source_t      *sources       = NULL;     // Much like original channelsstatic int           num_sources    = 0;// Current mode of 3D sound system// Default is original (stereo) modeint                  hws_mode       = HWS_DEFAULT_MODE;//=============================================================================void HW3S_SetSourcesNum(){    int i;    // Allocating the internal channels for mixing    // (the maximum number of sounds rendered    // simultaneously) within zone memory.    if (sources)    {        HW3S_StopSounds();        Z_Free(sources);    }    num_sources = cv_numChannels.value;    if (num_sources <= 0)        I_Error("HW3S_SetSourcesNum: Number of sound sources cannot be less than 5\n");    sources =      (source_t*) Z_Malloc(num_sources * sizeof(source_t), PU_STATIC, 0);    // Free all channels for use    for (i=0 ; i < num_sources; i++)    {        sources[i].sfxinfo = NULL;        sources[i].type = CT_NORMAL;        sources[i].handle = -1;    }}//=============================================================================static void HW3S_KillSource(int snum){    source_t*   s = &sources[snum];    if (s->sfxinfo)    {        HW3DS.pfnStopSource(s->handle);        HW3DS.pfnKillSource(s->handle);        s->handle = -1;        s->sfxinfo->usefulness--;        s->origin = NULL;        s->sfxinfo = NULL;    }}//=============================================================================static void HW3S_StopSource(int snum){    source_t*  s = &sources[snum];    if (s->sfxinfo)    {        // stop the sound playing        HW3DS.pfnStopSource(s->handle);    }}//=============================================================================void HW3S_StopSound(void *origin){    int snum;    for (snum=0 ; snum < num_sources ; snum++)    {        if (sources[snum].sfxinfo && sources[snum].origin == origin)        {            HW3S_KillSource(snum);            break;        }    }}//=============================================================================void HW3S_StopSounds(){    int snum;    // kill all playing sounds at start of level    //  (trust me - a good idea)    for (snum = 0 ; snum < num_sources; snum++)        if (sources[snum].sfxinfo)            HW3S_KillSource(snum);}//=============================================================================static int HW3S_GetSource( void* origin, sfxinfo_t* sfxinfo ){    //    //   If none available, return -1.  Otherwise source #.    //   source number to use    int         snum;    source_t*   src;    // Find an open source    for (snum = 0, src = sources ; snum < num_sources; src++, snum++)    {        if (!src->sfxinfo)            break;        if (origin && src->origin ==  origin)        {            HW3S_KillSource(snum);            break;        }    }    // None available    if (snum == num_sources)    {        // Look for lower priority        for (snum = 0, src = sources ; snum < num_sources ; src++, snum++)            if (src->sfxinfo->priority >= sfxinfo->priority)                 break;        if (snum == num_sources)        {            // FUCK!  No lower priority.  Sorry, Charlie.            return -1;        }        else        {            // Otherwise, kick out lower priority                        HW3S_KillSource(snum);        }    }        return snum;}//=============================================================================static void HW3S_FillSourceParameters(mobj_t           *origin,                                source3D_data_t  *data,                                channel_type_t   c_type){    fixed_t an;    fixed_t x, y, z;        if (origin != players[displayplayer].mo)    {        ZeroMemory(data, sizeof(source3D_data_t));        data->max_distance = MAX_DISTANCE;        data->min_distance = MIN_DISTANCE;        data->volume = 255;        data->pos.momx = FIXED_TO_FLOAT(origin->momx);        data->pos.momy = FIXED_TO_FLOAT(origin->momy);        data->pos.momz = FIXED_TO_FLOAT(origin->momz);        x = origin->x;        y = origin->y;        z = origin->z;        if (c_type == CT_ATTACK)        {            an = origin->angle >> ANGLETOFINESHIFT;            x += FixedMul(16*FRACUNIT, finecosine[an]);            y += FixedMul(16*FRACUNIT, finesine[an]);            z += origin->height >> 1;        }        else if (c_type == CT_SCREAM)            z += origin->height - (5 * FRACUNIT);        data->pos.x = FIXED_TO_FLOAT(x);        data->pos.y = FIXED_TO_FLOAT(y);        data->pos.z = FIXED_TO_FLOAT(z);                        }            }#define HEADER_SIZE     8//==============================================================static void make_outphase_sfx(void *dest, void *src, int size){    signed char    *s = (signed char*)src + HEADER_SIZE, *d = (signed char*)dest + HEADER_SIZE;    CopyMemory(dest, src, HEADER_SIZE);    size -= HEADER_SIZE;    while (size--)        *d++ = -(*s++);}//=============================================================================static void HW3S_StartSoundTypeAtVolume(void *origin_p, int sfx_id, channel_type_t c_type, int volume){        sfxinfo_t       *sfx;    mobj_t          *origin = (mobj_t*)origin_p;    source3D_data_t source3d_data;    source2D_data_t source2d_data;    sfx_data_t      sfx_data;    //int             volume  = 255;    int             s_num;    source_t        *source;    if(nosound || (origin && origin->type == MT_SPIRIT))        return;    sfx = &S_sfx[sfx_id];    if (sfx->skinsound!=-1 && origin && origin->skin)    {        // it redirect player sound to the sound in the skin table        sfx_id = ((skin_t *)origin->skin)->soundsid[sfx->skinsound];        sfx    = &S_sfx[sfx_id];    }    // Initialize sound parameters    if (sfx->link)    {      //pitch = sfx->pitch;      //priority = sfx->priority;      volume += sfx->volume;      if (volume < 1)          return;      sfx->data = sfx->link->data;    }       if (!sfx->data)

⌨️ 快捷键说明

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