author | rubidium |
Sat, 09 Dec 2006 14:14:51 +0000 | |
changeset 5298 | 6d4c150bdd94 |
parent 2977 | 0240dd4704a7 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
2189
d240b9097139
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
3 |
#include "../stdafx.h" |
d240b9097139
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
4 |
#include "../openttd.h" |
d240b9097139
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
5 |
#include "../driver.h" |
d240b9097139
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
6 |
#include "../functions.h" |
d240b9097139
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
7 |
#include "../mixer.h" |
d240b9097139
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
8 |
#include "win32_s.h" |
0 | 9 |
#include <windows.h> |
2189
d240b9097139
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
10 |
#include <mmsystem.h> |
0 | 11 |
|
12 |
static HWAVEOUT _waveout; |
|
13 |
static WAVEHDR _wave_hdr[2]; |
|
14 |
static int _bufsize; |
|
2171
008122046f7f
(svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
2163
diff
changeset
|
15 |
|
0 | 16 |
static void PrepareHeader(WAVEHDR *hdr) |
17 |
{ |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
18 |
hdr->dwBufferLength = _bufsize * 4; |
0 | 19 |
hdr->dwFlags = 0; |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
20 |
hdr->lpData = malloc(_bufsize * 4); |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
21 |
if (hdr->lpData == NULL || |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
22 |
waveOutPrepareHeader(_waveout, hdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR) |
0 | 23 |
error("waveOutPrepareHeader failed"); |
24 |
} |
|
25 |
||
1102
316643e34104
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
26 |
static void FillHeaders(void) |
0 | 27 |
{ |
28 |
WAVEHDR *hdr; |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
29 |
|
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
30 |
for (hdr = _wave_hdr; hdr != endof(_wave_hdr); hdr++) { |
0 | 31 |
if (!(hdr->dwFlags & WHDR_INQUEUE)) { |
2977 | 32 |
MxMixSamples(hdr->lpData, hdr->dwBufferLength / 4); |
0 | 33 |
if (waveOutWrite(_waveout, hdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR) |
34 |
error("waveOutWrite failed"); |
|
35 |
} |
|
36 |
} |
|
37 |
} |
|
38 |
||
2449
29c0920aee6d
(svn r2975) Use the correct types, not types which accidently have the same size on 32bit machines
tron
parents:
2189
diff
changeset
|
39 |
static void CALLBACK waveOutProc(HWAVEOUT hwo, UINT uMsg, DWORD_PTR dwInstance, |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
40 |
DWORD dwParam1, DWORD dwParam2) |
0 | 41 |
{ |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
42 |
switch (uMsg) { |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
43 |
case WOM_DONE: |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
44 |
if (_waveout) FillHeaders(); |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
45 |
break; |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
46 |
|
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
47 |
default: |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
48 |
break; |
0 | 49 |
} |
50 |
} |
|
51 |
||
2171
008122046f7f
(svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
2163
diff
changeset
|
52 |
static const char *Win32SoundStart(const char* const* parm) |
0 | 53 |
{ |
54 |
WAVEFORMATEX wfex; |
|
55 |
int hz; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
56 |
|
0 | 57 |
_bufsize = GetDriverParamInt(parm, "bufsize", 1024); |
58 |
hz = GetDriverParamInt(parm, "hz", 11025); |
|
59 |
wfex.wFormatTag = WAVE_FORMAT_PCM; |
|
60 |
wfex.nChannels = 2; |
|
61 |
wfex.nSamplesPerSec = hz; |
|
2171
008122046f7f
(svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
2163
diff
changeset
|
62 |
wfex.nAvgBytesPerSec = hz * 2 * 2; |
0 | 63 |
wfex.nBlockAlign = 4; |
64 |
wfex.wBitsPerSample = 16; |
|
2449
29c0920aee6d
(svn r2975) Use the correct types, not types which accidently have the same size on 32bit machines
tron
parents:
2189
diff
changeset
|
65 |
if (waveOutOpen(&_waveout, WAVE_MAPPER, &wfex, (DWORD_PTR)&waveOutProc, 0, CALLBACK_FUNCTION) != MMSYSERR_NOERROR) |
0 | 66 |
return "waveOutOpen failed"; |
67 |
PrepareHeader(&_wave_hdr[0]); |
|
68 |
PrepareHeader(&_wave_hdr[1]); |
|
69 |
FillHeaders(); |
|
70 |
return NULL; |
|
71 |
} |
|
72 |
||
1102
316643e34104
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
73 |
static void Win32SoundStop(void) |
0 | 74 |
{ |
75 |
HWAVEOUT waveout = _waveout; |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
76 |
|
0 | 77 |
_waveout = NULL; |
78 |
waveOutReset(waveout); |
|
79 |
waveOutUnprepareHeader(waveout, &_wave_hdr[0], sizeof(WAVEHDR)); |
|
80 |
waveOutUnprepareHeader(waveout, &_wave_hdr[1], sizeof(WAVEHDR)); |
|
81 |
waveOutClose(waveout); |
|
82 |
} |
|
83 |
||
84 |
const HalSoundDriver _win32_sound_driver = { |
|
85 |
Win32SoundStart, |
|
86 |
Win32SoundStop, |
|
87 |
}; |