author | bjarni |
Sun, 11 Mar 2007 16:31:18 +0000 | |
branch | cpp_gui |
changeset 6298 | c30fe89622df |
parent 6253 | 23983700e3d7 |
child 6720 | 35756db7e577 |
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" |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
8 |
#include "../helpers.hpp" |
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
|
9 |
#include "win32_s.h" |
0 | 10 |
#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
|
11 |
#include <mmsystem.h> |
0 | 12 |
|
13 |
static HWAVEOUT _waveout; |
|
14 |
static WAVEHDR _wave_hdr[2]; |
|
15 |
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
|
16 |
|
0 | 17 |
static void PrepareHeader(WAVEHDR *hdr) |
18 |
{ |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
19 |
hdr->dwBufferLength = _bufsize * 4; |
0 | 20 |
hdr->dwFlags = 0; |
5860
7fdc9b423ba1
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5838
diff
changeset
|
21 |
hdr->lpData = MallocT<char>(_bufsize * 4); |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
22 |
if (hdr->lpData == NULL || |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
23 |
waveOutPrepareHeader(_waveout, hdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR) |
0 | 24 |
error("waveOutPrepareHeader failed"); |
25 |
} |
|
26 |
||
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6253
diff
changeset
|
27 |
static void FillHeaders() |
0 | 28 |
{ |
29 |
WAVEHDR *hdr; |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
30 |
|
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
31 |
for (hdr = _wave_hdr; hdr != endof(_wave_hdr); hdr++) { |
0 | 32 |
if (!(hdr->dwFlags & WHDR_INQUEUE)) { |
2977 | 33 |
MxMixSamples(hdr->lpData, hdr->dwBufferLength / 4); |
0 | 34 |
if (waveOutWrite(_waveout, hdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR) |
35 |
error("waveOutWrite failed"); |
|
36 |
} |
|
37 |
} |
|
38 |
} |
|
39 |
||
2449
29c0920aee6d
(svn r2975) Use the correct types, not types which accidently have the same size on 32bit machines
tron
parents:
2189
diff
changeset
|
40 |
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
|
41 |
DWORD dwParam1, DWORD dwParam2) |
0 | 42 |
{ |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
43 |
switch (uMsg) { |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
44 |
case WOM_DONE: |
6253 | 45 |
if (_waveout != NULL) FillHeaders(); |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
46 |
break; |
6253 | 47 |
default: break; |
0 | 48 |
} |
49 |
} |
|
50 |
||
2171
008122046f7f
(svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
2163
diff
changeset
|
51 |
static const char *Win32SoundStart(const char* const* parm) |
0 | 52 |
{ |
53 |
WAVEFORMATEX wfex; |
|
54 |
wfex.wFormatTag = WAVE_FORMAT_PCM; |
|
55 |
wfex.nChannels = 2; |
|
56 |
wfex.wBitsPerSample = 16; |
|
6253 | 57 |
wfex.nSamplesPerSec = GetDriverParamInt(parm, "hz", 11025); |
58 |
wfex.nBlockAlign = (wfex.nChannels * wfex.wBitsPerSample) / 8; |
|
59 |
wfex.nAvgBytesPerSec = wfex.nSamplesPerSec * wfex.nBlockAlign; |
|
60 |
||
61 |
_bufsize = GetDriverParamInt(parm, "bufsize", 1024); |
|
62 |
||
2449
29c0920aee6d
(svn r2975) Use the correct types, not types which accidently have the same size on 32bit machines
tron
parents:
2189
diff
changeset
|
63 |
if (waveOutOpen(&_waveout, WAVE_MAPPER, &wfex, (DWORD_PTR)&waveOutProc, 0, CALLBACK_FUNCTION) != MMSYSERR_NOERROR) |
0 | 64 |
return "waveOutOpen failed"; |
6253 | 65 |
|
0 | 66 |
PrepareHeader(&_wave_hdr[0]); |
67 |
PrepareHeader(&_wave_hdr[1]); |
|
68 |
FillHeaders(); |
|
69 |
return NULL; |
|
70 |
} |
|
71 |
||
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6253
diff
changeset
|
72 |
static void Win32SoundStop() |
0 | 73 |
{ |
74 |
HWAVEOUT waveout = _waveout; |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
75 |
|
0 | 76 |
_waveout = NULL; |
77 |
waveOutReset(waveout); |
|
78 |
waveOutUnprepareHeader(waveout, &_wave_hdr[0], sizeof(WAVEHDR)); |
|
79 |
waveOutUnprepareHeader(waveout, &_wave_hdr[1], sizeof(WAVEHDR)); |
|
80 |
waveOutClose(waveout); |
|
81 |
} |
|
82 |
||
83 |
const HalSoundDriver _win32_sound_driver = { |
|
84 |
Win32SoundStart, |
|
85 |
Win32SoundStop, |
|
86 |
}; |