/programs/games/doom/trunk/h/doomdef.h |
---|
118,7 → 118,7 |
#define MAXPLAYERS 4 |
// State updates, number of tics / second. |
#define TICRATE 35 |
#define TICRATE 30 |
// The current state of the game: whether we are |
// playing, gazing at the intermission screen, |
/programs/games/doom/trunk/i_sound.c |
---|
49,6 → 49,7 |
#include "doomdef.h" |
#include "kolibri.h" |
#include "sound.h" |
// The number of internal mixing channels, |
// the samples calculated for each mixing step, |
57,11 → 58,11 |
// Needed for calling the actual sound output. |
#define SAMPLECOUNT 8192 |
#define SAMPLECOUNT 1024 |
#define NUM_CHANNELS 16 |
// It is 2 for 16bit, and 2 for two channels. |
#define BUFMUL 4 |
#define MIXBUFFERSIZE (SAMPLECOUNT*BUFMUL) |
//#define BUFMUL 4 |
//#define MIXBUFFERSIZE (SAMPLECOUNT*BUFMUL) |
#define SAMPLERATE 11025 // Hz |
#define SAMPLESIZE 2 // 16bit |
76,9 → 77,8 |
// 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]; |
signed short *mixbuffer; |
// The channel step amount... |
unsigned int channelstep[NUM_CHANNELS]; |
// ... and a 0.16 bit remainder of last step. |
291,10 → 291,17 |
// Sanity check, clamp volume. |
if (rightvol < 0 || rightvol > 127) |
I_Error("rightvol out of bounds"); |
{ |
printf("rightvol out of bounds\n\r"); |
rightvol = 0; |
} |
if (leftvol < 0 || leftvol > 127) |
I_Error("leftvol out of bounds"); |
{ |
printf("leftvol out of bounds\n\r"); |
leftvol=0; |
} |
// Get the proper lookup table piece |
// for this volume level??? |
426,8 → 433,9 |
// This function currently supports only 16bit. |
// |
extern DWORD hMixBuff[4]; |
extern int mix_ptr; |
extern SNDBUF hMixBuff; |
extern unsigned int mix_offset; |
extern int mix_size; |
void I_UpdateSound( void ) |
{ |
441,7 → 449,7 |
// Pointers in global mixbuffer, left, right, end. |
signed short* leftout; |
signed short* rightout; |
signed short* leftend; |
// signed short* leftend; |
// Step in mixbuffer, left and right, thus two. |
int step; |
449,7 → 457,7 |
int chan; |
int i; |
int flags; |
flags = 0; |
int size = 0; |
// Left and right channel |
// are in global mixbuffer, alternating. |
459,12 → 467,12 |
// Determine end, for left channel only |
// (right channel is implicit). |
leftend = mixbuffer + SAMPLECOUNT*step; |
// leftend = mixbuffer + SAMPLECOUNT*step; |
// Mix sounds into the mixing buffer. |
// Loop over step*SAMPLECOUNT, |
// that is 512 values for two channels. |
for (i=0; i < 8192; i++) |
for (i=0; i < mix_size/4; i++) |
{ |
// Reset left/right value. |
dl = 0; |
473,12 → 481,14 |
// Love thy L2 chache - made this a loop. |
// Now more channels could be set at compile time |
// as well. Thus loop those channels. |
// flags=0; |
for ( chan = 0; chan < NUM_CHANNELS; chan++ ) |
{ |
// Check channel, if active. |
if (channels[ chan ]) |
{ |
flags=1; |
// flags=1; |
// Get the raw data from the channel. |
sample = *channels[ chan ]; |
525,11 → 535,22 |
// Increment current pointers in mixbuffer. |
leftout += step; |
rightout += step; |
// if (flags) |
// size+=4; |
} |
if(flags) |
{ WaveOut(hMixBuff[mix_ptr],(char*)&mixbuffer[0],32768); |
mix_ptr= (mix_ptr+1)&3; |
}; |
SetBuffer(hMixBuff,mixbuffer,mix_offset,mix_size); |
// WaveOut(hMixBuff,(char*)&mixbuffer[0],4096); |
// if(size) |
// { |
// WaveOut(hMixBuff,(char*)&mixbuffer[0],size); |
// SetBufferPos(hMixBuff, 0); |
// SetBuffer(hMixBuff,(char*)&mixbuffer[0],mix_offset,4096); |
// PlayBuffer(hMixBuff, PCM_SYNC); |
// }; |
} |
559,23 → 580,11 |
handle = vol = sep = pitch = 0; |
} |
extern volatile int sound_state; |
void I_ShutdownSound(void) |
{ |
// Wait till all pending sounds are finished. |
int done = 0; |
int i; |
// FIXME (below). |
printf( "I_ShutdownSound: NOT finishing pending sounds\n"); |
while ( !done ) |
{ |
for( i=0 ; i<8 && !channels[i] ; i++); |
// FIXME. No proper channel output. |
//if (i==8) |
done=1; |
} |
sound_state=0; |
return; |
} |
603,8 → 612,8 |
printf( " pre-cached all sound data\n"); |
// Now initialize mixbuffer with zero. |
for ( i = 0; i< MIXBUFFERSIZE; i++ ) |
mixbuffer[i] = 0; |
// for ( i = 0; i< MIXBUFFERSIZE; i++ ) |
// mixbuffer[i] = 0; |
// Finished initialization. |
printf("I_InitSound: sound module ready\n"); |
/programs/games/doom/trunk/i_system.c |
---|
91,8 → 91,6 |
return (tm*TICRATE)/100; |
} |
// |
// I_Init |
// |
109,10 → 107,10 |
{ |
// __libclog_printf("Calling I_Quit from %x\n",__builtin_return_address(0)); |
D_QuitNetGame (); |
// I_ShutdownSound(); |
I_ShutdownSound(); |
// I_ShutdownMusic(); |
M_SaveDefaults (); |
I_ShutdownGraphics(); |
// I_ShutdownGraphics(); |
exit(0); |
} |
144,6 → 142,7 |
// I_Error |
// |
extern boolean demorecording; |
extern volatile int sound_state; |
void I_Error (char *error, ...) |
{ |
162,6 → 161,7 |
D_QuitNetGame (); |
I_ShutdownGraphics(); |
sound_state=0; |
// getch(); |
exit(-1); |
} |
/programs/games/doom/trunk/kolibc/include/kolibri.h |
---|
66,20 → 66,11 |
void* _stdcall UserAlloc(int size); |
int _stdcall UserFree(void* p); |
void _stdcall GetNotify(DWORD *event); |
void _stdcall GetNotify(void *event); |
//void _stdcall CreateThread(void *fn, char *p_stack); |
void _stdcall CreateThread(void *fn, char *p_stack); |
DWORD _stdcall GetMousePos(DWORD rel_type); |
int _stdcall GetService(char *srv_name); |
void _stdcall GetDevInfo(DWORD hSrv,CTRL_INFO *pInfo); |
int _stdcall GetMasterVol(DWORD hSrv,int* vol); |
int _stdcall SetMasterVol(DWORD hSrv, int vol); |
DWORD _stdcall CreateBuffer(DWORD hSrv, DWORD format); |
int _stdcall DestroyBuffer(DWORD hSrv, DWORD hBuff); |
int _stdcall SetBuffer(DWORD hSrv, DWORD hBuff,char* buff, |
DWORD offs, int size); |
int _stdcall PlayBuffer(DWORD hSrv, DWORD hBuff); |
int _stdcall StopBuffer(DWORD hSrv, DWORD hBuff); |
void _stdcall debug_out_hex(DWORD val); |
void debug_out_str(char* str); |
99,6 → 90,8 |
int wait_for_event_infinite(); |
void BeginDraw(void); |
void EndDraw(void); |
void _stdcall GetScreenSize(int *x, int*y); |
void _stdcall DrawWindow(int x,int y, int sx, int sy,int workcolor,int style, |
int captioncolor,int windowtype,int bordercolor); |
void _stdcall debug_out(int ch); |
/programs/games/doom/trunk/kolibc/include/sound.h |
---|
0,0 → 1,134 |
#ifndef _SOUND_H_ |
#define _SOUND_H_ |
#ifdef __cplusplus |
extern "C" |
{ |
#endif |
#define SOUND_VERSION 5 |
#define PCM_ALL 0 |
#define PCM_OUT 0x08000000 |
#define PCM_RING 0x10000000 |
#define PCM_STATIC 0x20000000 |
#define PCM_FLOAT 0x40000000 |
#define PCM_FILTER 0x80000000 |
#define PCM_2_16_48 1 |
#define PCM_1_16_48 2 |
#define PCM_2_16_44 3 |
#define PCM_1_16_44 4 |
#define PCM_2_16_32 5 |
#define PCM_1_16_32 6 |
#define PCM_2_16_24 7 |
#define PCM_1_16_24 8 |
#define PCM_2_16_22 9 |
#define PCM_1_16_22 10 |
#define PCM_2_16_16 11 |
#define PCM_1_16_16 12 |
#define PCM_2_16_12 13 |
#define PCM_1_16_12 14 |
#define PCM_2_16_11 15 |
#define PCM_1_16_11 16 |
#define PCM_2_16_8 17 |
#define PCM_1_16_8 18 |
#define PCM_2_8_48 19 |
#define PCM_1_8_48 20 |
#define PCM_2_8_44 21 |
#define PCM_1_8_44 22 |
#define PCM_2_8_32 23 |
#define PCM_1_8_32 24 |
#define PCM_2_8_24 25 |
#define PCM_1_8_24 26 |
#define PCM_2_8_22 27 |
#define PCM_1_8_22 28 |
#define PCM_2_8_16 29 |
#define PCM_1_8_16 30 |
#define PCM_2_8_12 31 |
#define PCM_1_8_12 32 |
#define PCM_2_8_11 33 |
#define PCM_1_8_11 34 |
#define PCM_2_8_8 35 |
#define PCM_1_8_8 36 |
#define SRV_GETVERSION 0 |
#define SND_CREATE_BUFF 1 |
#define SND_DESTROY_BUFF 2 |
#define SND_SETFORMAT 3 |
#define SND_GETFORMAT 4 |
#define SND_RESET 5 |
#define SND_SETPOS 6 |
#define SND_GETPOS 7 |
#define SND_SETBUFF 8 |
#define SND_OUT 9 |
#define SND_PLAY 10 |
#define SND_STOP 11 |
#define SND_SETVOLUME 12 |
#define SND_GETVOLUME 13 |
#define SND_SETPAN 14 |
#define SND_GETPAN 15 |
#define SND_GETBUFFSIZE 16 |
#define PLAY_SYNC 0x80000000 |
typedef unsigned int SNDBUF; |
int _stdcall InitSound(); |
SNDBUF _stdcall CreateBuffer(unsigned int format,int size); |
int _stdcall DestroyBuffer(SNDBUF hBuff); |
int _stdcall SetFormat(SNDBUF hBuff, unsigned int format); |
int _stdcall GetFormat(SNDBUF hBuff); |
int _stdcall ResetBuffer(SNDBUF hBuff, unsigned int flags); |
int _stdcall SetBufferPos(SNDBUF hBuff, int offset); |
int _stdcall GetBufferPos(SNDBUF hBuff); |
int _stdcall GetBufferSize(SNDBUF hBuff); |
int _stdcall SetBuffer(SNDBUF hBuff,void* buff, |
int offs, int size); |
int _stdcall WaveOut(SNDBUF hBuff,void *buff, int size); |
int _stdcall PlayBuffer(SNDBUF hBuff,unsigned int flags); |
int _stdcall StopBuffer(SNDBUF hBuff); |
int _stdcall SetVolume(SNDBUF hBuff, int left, int right); |
int _stdcall GetVolume(SNDBUF hBuff, int *left, int *right); |
int _stdcall SetPan(SNDBUF hBuff, int pan); |
int _stdcall GetPan(SNDBUF hBuff, int pan); |
int _stdcall GetMasterVol(int* vol); |
int _stdcall SetMasterVol(int vol); |
typedef struct |
{ |
unsigned int riff_id; |
unsigned int riff_size; |
unsigned int riff_format; |
unsigned int fmt_id; |
unsigned int fmt_size; |
unsigned short int wFormatTag; |
unsigned short int nChannels; |
unsigned int nSamplesPerSec; |
unsigned int nAvgBytesPerSec; |
unsigned short int nBlockAlign; |
unsigned short int wBitsPerSample; |
unsigned int data_id; |
unsigned int data_size; |
} WAVEHEADER; |
unsigned int _stdcall test_wav(WAVEHEADER *hdr); |
#ifdef __cplusplus |
extern "C" |
} |
#endif |
#endif //_SOUND_H_ |
/programs/games/doom/trunk/s_sound.c |
---|
47,6 → 47,7 |
#include "kolibri.h" |
#include "sound.h" |
void WriteDebug(char *); |
165,24 → 166,20 |
// allocates channel buffer, sets S_sfx lookup. |
// |
DWORD hMixBuff[4]; |
int mix_ptr; |
SNDBUF hMixBuff; |
volatile int sound_state; |
void sound_proc(void); |
void I_UpdateSound( void ); |
void S_Init |
( int sfxVolume, |
int musicVolume ) |
{ |
int i; |
char *thread_stack; |
int ver; |
printf("S_Init: default sfx volume %d\n", sfxVolume); |
InitSound(); |
hMixBuff[0]= CreateBuffer(15); |
hMixBuff[1]= CreateBuffer(15); |
hMixBuff[2]= CreateBuffer(15); |
hMixBuff[3]= CreateBuffer(15); |
numChannels = NUM_CHANNELS; |
// Whatever these did with DMX, these are rather dummies now. |
208,8 → 205,120 |
// Note that sounds have not been cached (yet). |
for (i=1 ; i<NUMSFX ; i++) |
S_sfx[i].lumpnum = S_sfx[i].usefulness = -1; |
/******** |
if((ver = InitSound())< SOUND_VERSION ) |
{ |
printf("Sound service version mismatch\n\r"); |
printf("Installed version: %d, required version %d\n\r", |
ver, SOUND_VERSION); |
}; |
hMixBuff = CreateBuffer(PCM_2_16_11,0); |
*********/ |
thread_stack = UserAlloc(4096); |
thread_stack+=4092; |
sound_state=1; |
CreateThread(sound_proc, thread_stack); |
} |
typedef struct |
{ |
unsigned int code; |
unsigned int sender; |
unsigned int stream; |
unsigned int offset; |
unsigned int size; |
unsigned int unused; |
}SND_EVENT; |
unsigned int mix_offset; |
int mix_size; |
extern signed short *mixbuffer; |
void sound_proc(void) |
{ |
int ver; |
SND_EVENT evnt; |
int i; |
if((ver = InitSound())< SOUND_VERSION ) |
{ |
printf("Sound service version mismatch\n\r"); |
printf("Installed version: %d, required version %d\n\r", |
ver, SOUND_VERSION); |
}; |
hMixBuff=CreateBuffer(PCM_2_16_11|PCM_RING,0); |
if(!hMixBuff) |
{ |
printf("sound not available\n\r"); |
_asm |
{ |
mov eax, -1 |
int 0x40 |
}; |
}; |
mix_size=GetBufferSize(hMixBuff)/2; |
printf("mixer size %d\n\r", mix_size); |
mixbuffer = malloc(mix_size); |
PlayBuffer(hMixBuff, 0); |
while(sound_state) |
{ |
GetNotify(&evnt); |
if(evnt.code != 0xFF000001) |
{ |
printf("invalid code %d\n\r", evnt.code); |
continue; |
} |
if(evnt.stream != hMixBuff) |
{ |
printf("invalid stream %d hMixBuff= %d\n\r", evnt.stream, hMixBuff); |
continue; |
}; |
mix_offset= evnt.offset; |
I_UpdateSound(); |
}; |
//flush sound buffers |
for(i=0; i<32; i++) |
{ |
GetNotify(&evnt); |
if(evnt.code != 0xFF000001) |
{ |
printf("invalid code %d\n\r", evnt.code); |
continue; |
} |
if(evnt.stream != hMixBuff) |
{ |
printf("invalid stream %d hMixBuff= %d\n\r", evnt.stream, hMixBuff); |
continue; |
}; |
mix_offset= evnt.offset; |
I_UpdateSound(); |
}; |
_asm |
{ |
mov eax, -1 |
int 0x40 |
}; |
}; |
// |
// Per level startup code. |
// Kills playing sounds at start of level, |