author | rubidium |
Mon, 31 Mar 2008 22:09:27 +0000 | |
branch | 0.6 |
changeset 9357 | bafe57f3402a |
parent 8627 | 448ebf3a8291 |
child 9280 | 9c03416d26b1 |
child 10328 | 721fe18a2176 |
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 "../mixer.h" |
8626
440dfcd14c4a
(svn r11691) -Codechange: move+rename helpers.hpp and only include it when it is really needed.
rubidium
parents:
7666
diff
changeset
|
7 |
#include "../core/alloc_func.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
|
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 |
|
7666
a5fccd76176a
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents:
6573
diff
changeset
|
12 |
static FSoundDriver_Win32 iFSoundDriver_Win32; |
a5fccd76176a
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents:
6573
diff
changeset
|
13 |
|
0 | 14 |
static HWAVEOUT _waveout; |
15 |
static WAVEHDR _wave_hdr[2]; |
|
16 |
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
|
17 |
|
0 | 18 |
static void PrepareHeader(WAVEHDR *hdr) |
19 |
{ |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
20 |
hdr->dwBufferLength = _bufsize * 4; |
0 | 21 |
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
|
22 |
hdr->lpData = MallocT<char>(_bufsize * 4); |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
23 |
if (hdr->lpData == NULL || |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
24 |
waveOutPrepareHeader(_waveout, hdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR) |
0 | 25 |
error("waveOutPrepareHeader failed"); |
26 |
} |
|
27 |
||
6573 | 28 |
static void FillHeaders() |
0 | 29 |
{ |
30 |
WAVEHDR *hdr; |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
31 |
|
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
32 |
for (hdr = _wave_hdr; hdr != endof(_wave_hdr); hdr++) { |
0 | 33 |
if (!(hdr->dwFlags & WHDR_INQUEUE)) { |
2977 | 34 |
MxMixSamples(hdr->lpData, hdr->dwBufferLength / 4); |
0 | 35 |
if (waveOutWrite(_waveout, hdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR) |
36 |
error("waveOutWrite failed"); |
|
37 |
} |
|
38 |
} |
|
39 |
} |
|
40 |
||
2449
29c0920aee6d
(svn r2975) Use the correct types, not types which accidently have the same size on 32bit machines
tron
parents:
2189
diff
changeset
|
41 |
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
|
42 |
DWORD dwParam1, DWORD dwParam2) |
0 | 43 |
{ |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
44 |
switch (uMsg) { |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
45 |
case WOM_DONE: |
6314
f738bcf05ad6
(svn r8691) -Cleanup: Some proper #endif comments for sound/music/video files, and a little elimination of magic numbers in Win32SoundStart
Darkvater
parents:
5860
diff
changeset
|
46 |
if (_waveout != NULL) FillHeaders(); |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
47 |
break; |
6314
f738bcf05ad6
(svn r8691) -Cleanup: Some proper #endif comments for sound/music/video files, and a little elimination of magic numbers in Win32SoundStart
Darkvater
parents:
5860
diff
changeset
|
48 |
default: break; |
0 | 49 |
} |
50 |
} |
|
51 |
||
7666
a5fccd76176a
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents:
6573
diff
changeset
|
52 |
const char *SoundDriver_Win32::Start(const char* const* parm) |
0 | 53 |
{ |
54 |
WAVEFORMATEX wfex; |
|
55 |
wfex.wFormatTag = WAVE_FORMAT_PCM; |
|
56 |
wfex.nChannels = 2; |
|
57 |
wfex.wBitsPerSample = 16; |
|
6314
f738bcf05ad6
(svn r8691) -Cleanup: Some proper #endif comments for sound/music/video files, and a little elimination of magic numbers in Win32SoundStart
Darkvater
parents:
5860
diff
changeset
|
58 |
wfex.nSamplesPerSec = GetDriverParamInt(parm, "hz", 11025); |
f738bcf05ad6
(svn r8691) -Cleanup: Some proper #endif comments for sound/music/video files, and a little elimination of magic numbers in Win32SoundStart
Darkvater
parents:
5860
diff
changeset
|
59 |
wfex.nBlockAlign = (wfex.nChannels * wfex.wBitsPerSample) / 8; |
f738bcf05ad6
(svn r8691) -Cleanup: Some proper #endif comments for sound/music/video files, and a little elimination of magic numbers in Win32SoundStart
Darkvater
parents:
5860
diff
changeset
|
60 |
wfex.nAvgBytesPerSec = wfex.nSamplesPerSec * wfex.nBlockAlign; |
f738bcf05ad6
(svn r8691) -Cleanup: Some proper #endif comments for sound/music/video files, and a little elimination of magic numbers in Win32SoundStart
Darkvater
parents:
5860
diff
changeset
|
61 |
|
f738bcf05ad6
(svn r8691) -Cleanup: Some proper #endif comments for sound/music/video files, and a little elimination of magic numbers in Win32SoundStart
Darkvater
parents:
5860
diff
changeset
|
62 |
_bufsize = GetDriverParamInt(parm, "bufsize", 1024); |
f738bcf05ad6
(svn r8691) -Cleanup: Some proper #endif comments for sound/music/video files, and a little elimination of magic numbers in Win32SoundStart
Darkvater
parents:
5860
diff
changeset
|
63 |
|
2449
29c0920aee6d
(svn r2975) Use the correct types, not types which accidently have the same size on 32bit machines
tron
parents:
2189
diff
changeset
|
64 |
if (waveOutOpen(&_waveout, WAVE_MAPPER, &wfex, (DWORD_PTR)&waveOutProc, 0, CALLBACK_FUNCTION) != MMSYSERR_NOERROR) |
0 | 65 |
return "waveOutOpen failed"; |
6314
f738bcf05ad6
(svn r8691) -Cleanup: Some proper #endif comments for sound/music/video files, and a little elimination of magic numbers in Win32SoundStart
Darkvater
parents:
5860
diff
changeset
|
66 |
|
0 | 67 |
PrepareHeader(&_wave_hdr[0]); |
68 |
PrepareHeader(&_wave_hdr[1]); |
|
69 |
FillHeaders(); |
|
70 |
return NULL; |
|
71 |
} |
|
72 |
||
7666
a5fccd76176a
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents:
6573
diff
changeset
|
73 |
void SoundDriver_Win32::Stop() |
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 |
} |