Rev 298 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
298 | serge | 1 | // Emacs style mode select -*- C++ -*- |
2 | //----------------------------------------------------------------------------- |
||
3 | // |
||
4 | // $Id:$ |
||
5 | // |
||
6 | // Copyright (C) 1993-1996 by id Software, Inc. |
||
7 | // |
||
8 | // This source is available for distribution and/or modification |
||
9 | // only under the terms of the DOOM Source Code License as |
||
10 | // published by id Software. All rights reserved. |
||
11 | // |
||
12 | // The source is distributed in the hope that it will be useful, |
||
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License |
||
15 | // for more details. |
||
16 | // |
||
17 | // $Log:$ |
||
18 | // |
||
19 | // DESCRIPTION: |
||
20 | // System interface for sound. |
||
21 | // |
||
22 | //----------------------------------------------------------------------------- |
||
23 | |||
24 | static const char |
||
25 | rcsid[] = "$Id: i_unix.c,v 1.5 1997/02/03 22:45:10 b1 Exp $"; |
||
26 | |||
27 | #include "sounds.h" |
||
28 | |||
29 | char MsgText[256]; |
||
30 | void WriteDebug(char *); |
||
31 | |||
32 | #define NUM_SOUND_FX 128 |
||
33 | #define SB_SIZE 20480 |
||
34 | |||
35 | void CreateSoundBuffer(int Channel, int length, unsigned char *data); |
||
36 | void I_PlaySoundEffect(int sfxid, int Channel, int volume, int pan); |
||
37 | void DS_Error( HRESULT hresult, char *msg ); |
||
38 | |||
39 | LPDIRECTSOUND8 lpDS; |
||
40 | LPDIRECTSOUNDBUFFER lpMix[2]; |
||
41 | extern int gametic; |
||
42 | int swap_stereo; |
||
43 | |||
44 | static int mixbuff=0; |
||
45 | |||
46 | // Needed for calling the actual sound output. |
||
47 | #define SAMPLECOUNT 512 |
||
48 | #define NUM_CHANNELS 16 |
||
49 | // It is 2 for 16bit, and 2 for two channels. |
||
50 | #define BUFMUL 4 |
||
51 | #define MIXBUFFERSIZE (SAMPLECOUNT*BUFMUL) |
||
52 | |||
53 | #define SAMPLERATE 11025 // Hz |
||
54 | #define SAMPLESIZE 2 // 16bit |
||
55 | |||
56 | extern HWND win; |
||
57 | |||
58 | void I_CreateSound(void) |
||
59 | { |
||
60 | HRESULT hret; |
||
61 | int buff; |
||
62 | DSBUFFERDESC dsbd; |
||
63 | WAVEFORMATEX wfx; |
||
64 | |||
65 | hret = DirectSoundCreate8(NULL, &lpDS, NULL); |
||
66 | if (hret != DS_OK) |
||
67 | { |
||
333 | serge | 68 | //printf("failed DirectSoundCreate"); |
298 | serge | 69 | return; |
70 | } |
||
71 | |||
72 | hret = lpDS->lpVtbl->SetCooperativeLevel(lpDS, win, DSSCL_PRIORITY); |
||
73 | if (hret != DS_OK) |
||
333 | serge | 74 | //printf("failled DirectSound.SetCooperativeLevel"); |
298 | serge | 75 | |
76 | memset( &wfx,0, sizeof(WAVEFORMATEX) ); |
||
77 | wfx.wFormatTag = WAVE_FORMAT_PCM; |
||
78 | wfx.nChannels = 2; |
||
79 | wfx.nSamplesPerSec = 11025; |
||
80 | wfx.wBitsPerSample = 16; |
||
81 | wfx.nBlockAlign = 4; |
||
82 | wfx.nAvgBytesPerSec = 44100; |
||
83 | |||
84 | memset(&dsbd,0,sizeof(DSBUFFERDESC)); |
||
85 | dsbd.dwSize = sizeof(DSBUFFERDESC); |
||
86 | dsbd.dwFlags = 0; |
||
87 | dsbd.dwBufferBytes = MIXBUFFERSIZE; |
||
88 | dsbd.lpwfxFormat = &wfx; |
||
89 | |||
90 | hret=lpDS->lpVtbl->CreateSoundBuffer(lpDS,&dsbd, &lpMix[0], NULL); |
||
91 | hret=lpDS->lpVtbl->CreateSoundBuffer(lpDS,&dsbd, &lpMix[1], NULL); |
||
92 | |||
93 | |||
94 | return; |
||
95 | }; |
||
96 | |||
97 | void ShutdownDirectSound(void) |
||
98 | { |
||
99 | int buff; |
||
100 | DWORD BufferStatus; |
||
101 | |||
102 | if (lpMix[0] !=NULL) |
||
103 | lpMix[0]->lpVtbl->Release(lpMix[0]); |
||
104 | if(lpDS != NULL) |
||
105 | lpDS->lpVtbl->Release(lpDS); |
||
106 | } |
||
107 | |||
108 | void I_SubmitSound(signed short *mixbuffer) |
||
109 | { |
||
110 | DWORD hret; |
||
111 | void* pPtr1=NULL,*pPtr2=NULL; |
||
112 | DWORD dwSize1=0,dwSize2=0; |
||
113 | |||
114 | hret = lpMix[mixbuff]->lpVtbl->Stop(lpMix[mixbuff]); |
||
115 | hret = lpMix[mixbuff]->lpVtbl->SetCurrentPosition(lpMix[mixbuff],0); |
||
116 | |||
117 | hret=lpMix[mixbuff]->lpVtbl->Lock(lpMix[mixbuff],0,MIXBUFFERSIZE,&pPtr1, |
||
118 | &dwSize1,&pPtr2,&dwSize2,0); |
||
119 | if (hret!=DS_OK) |
||
333 | serge | 120 | { //printf("Error locking on play start"); |
298 | serge | 121 | return ; |
122 | } |
||
123 | memcpy(pPtr1, (void*)mixbuffer, MIXBUFFERSIZE); |
||
124 | hret-lpMix[mixbuff]->lpVtbl->Unlock(lpMix[mixbuff],pPtr1, dwSize1, pPtr2, dwSize2); |
||
125 | hret = lpMix[mixbuff]->lpVtbl->Play(lpMix[mixbuff],0,0,0); |
||
126 | mixbuff= (mixbuff+1)&1; |
||
127 | |||
128 | }; |