Subversion Repositories Kolibri OS

Rev

Details | 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 
28
#include 
29
#include "sounds.h"
30
 
31
char MsgText[256];
32
void WriteDebug(char *);
33
 
34
#define NUM_SOUND_FX 128
35
#define SB_SIZE      20480
36
 
37
void CreateSoundBuffer(int Channel, int length, unsigned char *data);
38
void I_PlaySoundEffect(int sfxid, int Channel, int volume, int pan);
39
void DS_Error( HRESULT hresult, char *msg );
40
 
41
LPDIRECTSOUND8       lpDS;
42
LPDIRECTSOUNDBUFFER  lpMix[2];
43
extern int gametic;
44
int swap_stereo;
45
 
46
static int mixbuff=0;
47
 
48
// Needed for calling the actual sound output.
49
#define SAMPLECOUNT   512
50
#define NUM_CHANNELS  16
51
// It is 2 for 16bit, and 2 for two channels.
52
#define BUFMUL        4
53
#define MIXBUFFERSIZE (SAMPLECOUNT*BUFMUL)
54
 
55
#define SAMPLERATE	  11025	// Hz
56
#define SAMPLESIZE	  2   	// 16bit
57
 
58
extern HWND win;
59
 
60
void I_CreateSound(void)
61
{
62
  HRESULT        hret;
63
  int            buff;
64
  DSBUFFERDESC   dsbd;
65
  WAVEFORMATEX   wfx;
66
 
67
  hret = DirectSoundCreate8(NULL, &lpDS, NULL);
68
  if (hret != DS_OK)
69
  {
70
     printf("failed DirectSoundCreate");
71
     return;
72
  }
73
 
74
  hret = lpDS->lpVtbl->SetCooperativeLevel(lpDS, win, DSSCL_PRIORITY);
75
  if (hret != DS_OK)
76
       printf("failled DirectSound.SetCooperativeLevel");
77
 
78
  memset( &wfx,0, sizeof(WAVEFORMATEX) );
79
  wfx.wFormatTag      = WAVE_FORMAT_PCM;
80
  wfx.nChannels       = 2;
81
  wfx.nSamplesPerSec  = 11025;
82
  wfx.wBitsPerSample  = 16;
83
  wfx.nBlockAlign     = 4;
84
  wfx.nAvgBytesPerSec = 44100;
85
 
86
  memset(&dsbd,0,sizeof(DSBUFFERDESC));
87
  dsbd.dwSize        = sizeof(DSBUFFERDESC);
88
  dsbd.dwFlags       = 0;
89
  dsbd.dwBufferBytes = MIXBUFFERSIZE;
90
  dsbd.lpwfxFormat   = &wfx;
91
 
92
  hret=lpDS->lpVtbl->CreateSoundBuffer(lpDS,&dsbd, &lpMix[0], NULL);
93
  hret=lpDS->lpVtbl->CreateSoundBuffer(lpDS,&dsbd, &lpMix[1], NULL);
94
 
95
 
96
  return;
97
};
98
 
99
void ShutdownDirectSound(void)
100
{
101
  int buff;
102
  DWORD BufferStatus;
103
 
104
  if (lpMix[0] !=NULL)
105
     lpMix[0]->lpVtbl->Release(lpMix[0]);
106
  if(lpDS != NULL)
107
     lpDS->lpVtbl->Release(lpDS);
108
}
109
 
110
void I_SubmitSound(signed short *mixbuffer)
111
{
112
  DWORD hret;
113
  void* pPtr1=NULL,*pPtr2=NULL;
114
  DWORD dwSize1=0,dwSize2=0;
115
 
116
  hret = lpMix[mixbuff]->lpVtbl->Stop(lpMix[mixbuff]);
117
  hret = lpMix[mixbuff]->lpVtbl->SetCurrentPosition(lpMix[mixbuff],0);
118
 
119
  hret=lpMix[mixbuff]->lpVtbl->Lock(lpMix[mixbuff],0,MIXBUFFERSIZE,&pPtr1,
120
                           &dwSize1,&pPtr2,&dwSize2,0);
121
  if (hret!=DS_OK)
122
  {	printf("Error locking on play start");
123
 	return ;
124
  }
125
  memcpy(pPtr1, (void*)mixbuffer, MIXBUFFERSIZE);
126
  hret-lpMix[mixbuff]->lpVtbl->Unlock(lpMix[mixbuff],pPtr1, dwSize1, pPtr2, dwSize2);
127
  hret = lpMix[mixbuff]->lpVtbl->Play(lpMix[mixbuff],0,0,0);
128
  mixbuff= (mixbuff+1)&1;
129
 
130
};